diff --git a/apps/mail/components/labels/label-dialog.tsx b/apps/mail/components/labels/label-dialog.tsx index 1084ea4ed3..85cade4e81 100644 --- a/apps/mail/components/labels/label-dialog.tsx +++ b/apps/mail/components/labels/label-dialog.tsx @@ -16,6 +16,11 @@ import { import { CurvedArrow } from '@/components/icons/icons'; import { LABEL_COLORS } from '@/lib/label-colors'; import type { Label as LabelType } from '@/types'; + +const DEFAULT_LABEL_COLORS = { + backgroundColor: '#202020', + textColor: '#FFFFFF', +} as const; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { Input } from '@/components/ui/input'; @@ -49,13 +54,9 @@ export function LabelDialog({ const form = useForm({ defaultValues: { name: '', - color: { - backgroundColor: '', - textColor: '', - }, + color: DEFAULT_LABEL_COLORS, }, }); - const formColor = form.watch('color'); // Reset form when editingLabel changes or dialog opens @@ -69,7 +70,7 @@ export function LabelDialog({ } else { form.reset({ name: '', - color: { backgroundColor: '#E2E2E2', textColor: '#000000' }, + color: DEFAULT_LABEL_COLORS, }); } } @@ -85,7 +86,7 @@ export function LabelDialog({ setDialogOpen(false); form.reset({ name: '', - color: { backgroundColor: '#E2E2E2', textColor: '#000000' }, + color: DEFAULT_LABEL_COLORS, }); }; diff --git a/apps/mail/components/ui/nav-main.tsx b/apps/mail/components/ui/nav-main.tsx index 91ee06fc9f..9c20d3fc21 100644 --- a/apps/mail/components/ui/nav-main.tsx +++ b/apps/mail/components/ui/nav-main.tsx @@ -173,11 +173,16 @@ export function NavMain({ items }: NavMainProps) { ); const onSubmit = async (data: LabelType) => { - toast.promise(createLabel(data), { - loading: 'Creating label...', - success: 'Label created successfully', - error: 'Failed to create label', - }); + toast.promise( + createLabel(data).then(() => { + refetch(); + }), + { + loading: 'Creating label...', + success: 'Label created successfully', + error: 'Failed to create label', + } + ); }; return ( diff --git a/apps/server/src/trpc/routes/label.ts b/apps/server/src/trpc/routes/label.ts index 4bbe038176..2c49007293 100644 --- a/apps/server/src/trpc/routes/label.ts +++ b/apps/server/src/trpc/routes/label.ts @@ -3,6 +3,11 @@ import { getZeroAgent } from '../../lib/server-utils'; import { Ratelimit } from '@upstash/ratelimit'; import { z } from 'zod'; +const DEFAULT_LABEL_COLORS = { + backgroundColor: '#202020', + textColor: '#FFFFFF', +} as const; + export const labelsRouter = router({ list: activeDriverProcedure .use( @@ -41,15 +46,10 @@ export const labelsRouter = router({ .input( z.object({ name: z.string(), - color: z - .object({ - backgroundColor: z.string(), - textColor: z.string(), - }) - .default({ - backgroundColor: '', - textColor: '', - }), + color: z.object({ + backgroundColor: z.string().regex(/^#[0-9A-F]{6}$/i, 'Must be a valid hex color').default(DEFAULT_LABEL_COLORS.backgroundColor), + textColor: z.string().regex(/^#[0-9A-F]{6}$/i, 'Must be a valid hex color').default(DEFAULT_LABEL_COLORS.textColor), + }).default(DEFAULT_LABEL_COLORS), }), ) .mutation(async ({ ctx, input }) => {