Skip to content
15 changes: 8 additions & 7 deletions apps/mail/components/labels/label-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -49,13 +54,9 @@ export function LabelDialog({
const form = useForm<LabelType>({
defaultValues: {
name: '',
color: {
backgroundColor: '',
textColor: '',
},
color: DEFAULT_LABEL_COLORS,
},
});

const formColor = form.watch('color');

// Reset form when editingLabel changes or dialog opens
Expand All @@ -69,7 +70,7 @@ export function LabelDialog({
} else {
form.reset({
name: '',
color: { backgroundColor: '#E2E2E2', textColor: '#000000' },
color: DEFAULT_LABEL_COLORS,
});
}
}
Expand All @@ -85,7 +86,7 @@ export function LabelDialog({
setDialogOpen(false);
form.reset({
name: '',
color: { backgroundColor: '#E2E2E2', textColor: '#000000' },
color: DEFAULT_LABEL_COLORS,
});
};

Expand Down
15 changes: 10 additions & 5 deletions apps/mail/components/ui/nav-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
18 changes: 9 additions & 9 deletions apps/server/src/trpc/routes/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 }) => {
Expand Down