chore: invite add id support
This commit is contained in:
parent
4a1d704fbb
commit
6a1f413a38
@ -46,7 +46,7 @@ export const Route = createFileRoute('/settings/workspace')({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const inviteFormSchema = z.object({
|
const inviteFormSchema = z.object({
|
||||||
email: z.string().email(),
|
emailOrId: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
type InviteFormValues = z.infer<typeof inviteFormSchema>;
|
type InviteFormValues = z.infer<typeof inviteFormSchema>;
|
||||||
@ -64,7 +64,7 @@ function PageComponent() {
|
|||||||
const form = useForm<InviteFormValues>({
|
const form = useForm<InviteFormValues>({
|
||||||
resolver: zodResolver(inviteFormSchema),
|
resolver: zodResolver(inviteFormSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
email: '',
|
emailOrId: '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const inviteMutation = trpc.workspace.invite.useMutation({
|
const inviteMutation = trpc.workspace.invite.useMutation({
|
||||||
@ -80,7 +80,7 @@ function PageComponent() {
|
|||||||
async (values: InviteFormValues) => {
|
async (values: InviteFormValues) => {
|
||||||
await inviteMutation.mutateAsync({
|
await inviteMutation.mutateAsync({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
targetUserEmail: values.email,
|
emailOrId: values.emailOrId,
|
||||||
});
|
});
|
||||||
form.reset();
|
form.reset();
|
||||||
|
|
||||||
@ -148,12 +148,15 @@ function PageComponent() {
|
|||||||
<CardContent>
|
<CardContent>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="email"
|
name="emailOrId"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="max-w-[320px]">
|
<FormItem className="max-w-[320px]">
|
||||||
<FormLabel />
|
<FormLabel />
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder="jane@example.com" {...field} />
|
<Input
|
||||||
|
placeholder="jane@example.com or userId"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription />
|
<FormDescription />
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
@ -220,15 +220,22 @@ export const workspaceRouter = router({
|
|||||||
)
|
)
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
targetUserEmail: z.string(),
|
emailOrId: z.string(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.output(z.void())
|
.output(z.void())
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
const { targetUserEmail, workspaceId } = input;
|
const { emailOrId, workspaceId } = input;
|
||||||
const targetUser = await prisma.user.findUnique({
|
const targetUser = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
email: targetUserEmail,
|
OR: [
|
||||||
|
{
|
||||||
|
email: emailOrId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: emailOrId,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user