From 6a1f413a384021d3c91e136be36a8c6375c74f99 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 21 Sep 2024 01:10:43 +0800 Subject: [PATCH] chore: invite add id support --- src/client/routes/settings/workspace.tsx | 13 ++++++++----- src/server/trpc/routers/workspace.ts | 15 +++++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/client/routes/settings/workspace.tsx b/src/client/routes/settings/workspace.tsx index d352055..d37af05 100644 --- a/src/client/routes/settings/workspace.tsx +++ b/src/client/routes/settings/workspace.tsx @@ -46,7 +46,7 @@ export const Route = createFileRoute('/settings/workspace')({ }); const inviteFormSchema = z.object({ - email: z.string().email(), + emailOrId: z.string(), }); type InviteFormValues = z.infer; @@ -64,7 +64,7 @@ function PageComponent() { const form = useForm({ resolver: zodResolver(inviteFormSchema), defaultValues: { - email: '', + emailOrId: '', }, }); const inviteMutation = trpc.workspace.invite.useMutation({ @@ -80,7 +80,7 @@ function PageComponent() { async (values: InviteFormValues) => { await inviteMutation.mutateAsync({ workspaceId, - targetUserEmail: values.email, + emailOrId: values.emailOrId, }); form.reset(); @@ -148,12 +148,15 @@ function PageComponent() { ( - + diff --git a/src/server/trpc/routers/workspace.ts b/src/server/trpc/routers/workspace.ts index a105121..6e7f972 100644 --- a/src/server/trpc/routers/workspace.ts +++ b/src/server/trpc/routers/workspace.ts @@ -220,15 +220,22 @@ export const workspaceRouter = router({ ) .input( z.object({ - targetUserEmail: z.string(), + emailOrId: z.string(), }) ) .output(z.void()) .mutation(async ({ input }) => { - const { targetUserEmail, workspaceId } = input; - const targetUser = await prisma.user.findUnique({ + const { emailOrId, workspaceId } = input; + const targetUser = await prisma.user.findFirst({ where: { - email: targetUserEmail, + OR: [ + { + email: emailOrId, + }, + { + id: emailOrId, + }, + ], }, });