Skip to content

Commit

Permalink
Merge pull request #13 from Excali-Studio/exd-120
Browse files Browse the repository at this point in the history
EXD-120 - Tag color field as optional
  • Loading branch information
MicDeb-Silk authored Sep 9, 2024
2 parents 3d80a97 + 7699418 commit 543844f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
8 changes: 2 additions & 6 deletions src/components/CreateOrModifyTagDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -64,9 +62,7 @@ export default function CreateOrModifyTagDialog({
description: formValues.description || undefined,
};

currentTagId === 'new'
? createTagHandler(formData)
: updateTagHandler(formData);
currentTagId ? updateTagHandler(formData) : createTagHandler(formData);
}

return (
Expand Down
14 changes: 4 additions & 10 deletions src/components/TagsManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,29 @@ import { useTranslation } from 'react-i18next';

export default function TagsManager() {
const { t } = useTranslation();
const { openModal, modalState, resetState, modalProps } = useModalStore();
const { openModal, resetState, modalProps } = useModalStore();

return (
<>
<Toaster />
{(modalState === 'ADD_TAG' || modalState === 'EDIT_TAG') && (
<CreateOrModifyTagDialog
currentTagId={modalProps?.selectedId ?? null}
/>
)}

<CreateOrModifyTagDialog currentTagId={modalProps?.selectedId} />
<ContentWrapper pagePaths={['Dashboard', 'Tags Manager']}>
<Tabs defaultValue="all">
<div className="flex items-center">
<TabsList>
<TabsTrigger value="all">{t('tagsManager.all')}</TabsTrigger>
<TabsTrigger value="all">{t('components.tagsManager.all')}</TabsTrigger>
</TabsList>
<div className="ml-auto flex items-center gap-2">
<PrimaryActionButton
onClickHandler={() => {
resetState();
openModal({
modalState: 'ADD_TAG',
params: { selectedId: null },
});
}}
icon={<PlusCircle className="h-3.5 w-3.5" />}
>
{t('tagsManager.createButton')}
{t('components.tagsManager.createButton')}
</PrimaryActionButton>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useCreateOrModifyTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/schema/create-or-modify-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const createOrModifyTagFormSchema = z.object({
number: 12,
}),
}),
color: z.string(),
color: z.string().optional(),
description: z.string().optional(),
});

Expand Down
17 changes: 9 additions & 8 deletions src/store/modalStore.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<ModalState, [['zustand/immer', never]]>(
immer((set) => ({
Expand Down

0 comments on commit 543844f

Please sign in to comment.