-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(tags): set of colors and refactoring * chore(boards): refactor * chore(tags): tailwind config * chore(tags): tokens * fix(tags): fix tags able to be empty string * chore(tags): colors constant * chore(tags): rename variable
- Loading branch information
1 parent
c8cdb1f
commit 4a0d508
Showing
15 changed files
with
203 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
next-tavla/app/(admin)/boards/components/TagModal/AddNewTag.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
next-tavla/app/(admin)/boards/components/TagModal/actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use server' | ||
import { TFormFeedback, getFormFeedbackForError } from 'app/(admin)/utils' | ||
import { FirebaseError } from 'firebase/app' | ||
import { isString, uniq } from 'lodash' | ||
import { revalidatePath } from 'next/cache' | ||
import { hasBoardEditorAccess } from 'app/(admin)/utils/firebase' | ||
import { TBoardID } from 'types/settings' | ||
import { firestore } from 'firebase-admin' | ||
import { TTag } from 'types/meta' | ||
import { isEmptyOrSpaces } from 'app/(admin)/edit/utils' | ||
|
||
async function fetchTags({ bid }: { bid: TBoardID }) { | ||
const board = await firestore().collection('boards').doc(bid).get() | ||
if (!board.exists) throw 'board/not-found' | ||
|
||
const access = await hasBoardEditorAccess(board.id) | ||
if (!access) throw 'auth/operation-not-allowed' | ||
|
||
return (board.data()?.meta?.tags as TTag[]) ?? [] | ||
} | ||
|
||
export async function removeTag( | ||
prevState: TFormFeedback | undefined, | ||
data: FormData, | ||
) { | ||
const bid = data.get('bid') as string | ||
const tag = data.get('tag') as string | ||
|
||
const access = await hasBoardEditorAccess(bid) | ||
if (!access) throw 'auth/operation-not-allowed' | ||
|
||
try { | ||
const tags = await fetchTags({ bid }) | ||
await firestore() | ||
.collection('boards') | ||
.doc(bid) | ||
.update({ 'meta.tags': tags.filter((t) => t !== tag) }) | ||
revalidatePath('/') | ||
} catch (e) { | ||
if (e instanceof FirebaseError || isString(e)) | ||
return getFormFeedbackForError(e) | ||
return getFormFeedbackForError('general') | ||
} | ||
} | ||
|
||
export async function addTag( | ||
prevState: TFormFeedback | undefined, | ||
data: FormData, | ||
) { | ||
const bid = data.get('bid') as string | ||
const tag = data.get('tag') as string | ||
|
||
if (isEmptyOrSpaces(tag)) | ||
return getFormFeedbackForError('tags/name-missing') | ||
|
||
const access = await hasBoardEditorAccess(bid) | ||
if (!access) throw 'auth/operation-not-allowed' | ||
|
||
try { | ||
const tags = await fetchTags({ bid }) | ||
|
||
if (tags.map((t) => t.toUpperCase()).includes(tag.toUpperCase())) | ||
throw 'boards/tag-exists' | ||
|
||
await firestore() | ||
.collection('boards') | ||
.doc(bid) | ||
.update({ 'meta.tags': uniq([...tags, tag]).sort() }) | ||
revalidatePath('/') | ||
} catch (e) { | ||
if (e instanceof FirebaseError || isString(e)) | ||
return getFormFeedbackForError(e) | ||
return getFormFeedbackForError('general') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use server' | ||
import { TFormFeedback, getFormFeedbackForError } from 'app/(admin)/utils' | ||
import { FirebaseError } from 'firebase/app' | ||
import { isString } from 'lodash' | ||
import { revalidatePath } from 'next/cache' | ||
import { deleteBoard, initializeAdminApp } from 'app/(admin)/utils/firebase' | ||
import { redirect } from 'next/navigation' | ||
|
||
initializeAdminApp() | ||
|
||
export async function deleteBoardAction( | ||
prevState: TFormFeedback | undefined, | ||
data: FormData, | ||
) { | ||
try { | ||
const bid = data.get('bid') as string | ||
|
||
await deleteBoard(bid) | ||
revalidatePath('/') | ||
} catch (e) { | ||
if (e instanceof FirebaseError || isString(e)) | ||
return getFormFeedbackForError(e) | ||
return getFormFeedbackForError('general') | ||
} | ||
redirect('/boards') | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.