chore: invite add id support

This commit is contained in:
moonrailgun 2024-09-21 01:10:43 +08:00
parent 4a1d704fbb
commit 6a1f413a38
2 changed files with 19 additions and 9 deletions

View File

@ -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<typeof inviteFormSchema>;
@ -64,7 +64,7 @@ function PageComponent() {
const form = useForm<InviteFormValues>({
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() {
<CardContent>
<FormField
control={form.control}
name="email"
name="emailOrId"
render={({ field }) => (
<FormItem className="max-w-[320px]">
<FormLabel />
<FormControl>
<Input placeholder="jane@example.com" {...field} />
<Input
placeholder="jane@example.com or userId"
{...field}
/>
</FormControl>
<FormDescription />
<FormMessage />

View File

@ -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,
},
],
},
});