diff --git a/src/components/CreateOrModifyTagDialog.tsx b/src/components/CreateOrModifyTagDialog.tsx index a52a5da..f3dc9ca 100644 --- a/src/components/CreateOrModifyTagDialog.tsx +++ b/src/components/CreateOrModifyTagDialog.tsx @@ -27,10 +27,8 @@ import { useCreateOrModifyTag } from '@/hooks/useCreateOrModifyTag'; import { useModalStore } from '@/store/modalStore'; import { useTranslation } from 'react-i18next'; -type CurrentTagId = string | null; - interface CreateOrModifyCanvasDialogProps { - currentTagId: CurrentTagId; + currentTagId?: string; } export default function CreateOrModifyTagDialog({ @@ -64,9 +62,7 @@ export default function CreateOrModifyTagDialog({ description: formValues.description || undefined, }; - currentTagId === 'new' - ? createTagHandler(formData) - : updateTagHandler(formData); + currentTagId ? updateTagHandler(formData) : createTagHandler(formData); } return ( diff --git a/src/components/TagsManager.tsx b/src/components/TagsManager.tsx index a966d86..217739b 100644 --- a/src/components/TagsManager.tsx +++ b/src/components/TagsManager.tsx @@ -10,22 +10,17 @@ import { useTranslation } from 'react-i18next'; export default function TagsManager() { const { t } = useTranslation(); - const { openModal, modalState, resetState, modalProps } = useModalStore(); + const { openModal, resetState, modalProps } = useModalStore(); return ( <> - {(modalState === 'ADD_TAG' || modalState === 'EDIT_TAG') && ( - - )} - + - {t('tagsManager.all')} + {t('components.tagsManager.all')} } > - {t('tagsManager.createButton')} + {t('components.tagsManager.createButton')} diff --git a/src/hooks/useCreateOrModifyTag.ts b/src/hooks/useCreateOrModifyTag.ts index 50e325c..110fbd3 100644 --- a/src/hooks/useCreateOrModifyTag.ts +++ b/src/hooks/useCreateOrModifyTag.ts @@ -5,7 +5,7 @@ import { toast } from '@/components/ui/use-toast'; import { useModalStore } from '@/store/modalStore'; export function useCreateOrModifyTag( - currentTagId: string | null, + currentTagId: string | undefined, resetForm: () => void ) { const queryClient = useQueryClient(); @@ -14,7 +14,7 @@ export function useCreateOrModifyTag( const { data: tagDetails } = useQuery({ queryKey: ['canvas-tag-details', currentTagId], queryFn: () => ExcaliApi.getTagById(`${currentTagId}`), - enabled: Boolean(currentTagId) && currentTagId !== 'new', + enabled: !!currentTagId, }); function onSuccess() { diff --git a/src/schema/create-or-modify-tag.ts b/src/schema/create-or-modify-tag.ts index e12f6d9..985575a 100644 --- a/src/schema/create-or-modify-tag.ts +++ b/src/schema/create-or-modify-tag.ts @@ -17,7 +17,7 @@ export const createOrModifyTagFormSchema = z.object({ number: 12, }), }), - color: z.string(), + color: z.string().optional(), description: z.string().optional(), }); diff --git a/src/store/modalStore.ts b/src/store/modalStore.ts index e5a8395..0fe837c 100644 --- a/src/store/modalStore.ts +++ b/src/store/modalStore.ts @@ -1,7 +1,7 @@ import { create } from 'zustand'; import { immer } from 'zustand/middleware/immer'; -type ModalProps = { selectedId: string | null } | undefined; +type ModalProps = { selectedId: string } | undefined; interface ModalState { isModalOpen: boolean; @@ -29,13 +29,14 @@ const initialState = { modalProps: undefined, }; -export type ModalPayload = { - modalState: - | typeof MODAL_STATE.ADD_TAG - | typeof MODAL_STATE.EDIT_TAG - | typeof MODAL_STATE.REMOVE_TAG; - params: ModalProps; -}; +export type ModalPayload = + | { + modalState: typeof MODAL_STATE.EDIT_TAG | typeof MODAL_STATE.REMOVE_TAG; + params: ModalProps; + } + | { + modalState: typeof MODAL_STATE.ADD_TAG; + }; const useModalStore = create( immer((set) => ({