Skip to content

Commit

Permalink
feat: update trpc router to send extra form details
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimduncan committed Feb 19, 2024
1 parent d8b63a1 commit a3aea02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/app/(main)/dashboard/_components/new-form-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const FormSchema = z.object({
message: "Form title is required.",
}),
returnUrl: z.string().optional(),
description: z.string().optional(),
});

export function CreateFormDialog() {
Expand All @@ -48,6 +49,7 @@ export function CreateFormDialog() {
resolver: zodResolver(FormSchema),
defaultValues: {
name: "",
description: "",
returnUrl: "",
},
});
Expand All @@ -61,6 +63,8 @@ export function CreateFormDialog() {
await createNewForm(
{
title: data.name,
description: data.description,
returningUrl: data.returnUrl,
},
{
onSuccess: ({ id }) => {
Expand Down Expand Up @@ -106,7 +110,21 @@ export function CreateFormDialog() {
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<Input placeholder="A new form" {...field} />
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>

<FormField
control={form.control}
name="description"
render={({ field }) => (
<FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
Expand Down
2 changes: 2 additions & 0 deletions src/app/s/[formId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default async function FormCompletedPage({
}) {
const form = await api.form.hasReturiningUrl.query({ formId: params.formId });

console.log(form);

if (!form) {
return (
<div className="container flex h-screen flex-col items-center justify-center gap-3">
Expand Down
4 changes: 3 additions & 1 deletion src/server/api/routers/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ export const formRouter = createTRPCRouter({
create: protectedProcedure
.input(
z.object({
title: z.string().min(3).max(255),
title: z.string().min(1).max(255),
description: z.string().optional(),
returningUrl: z.string().optional(),
}),
)
.mutation(async ({ ctx, input }) => {
Expand All @@ -53,6 +54,7 @@ export const formRouter = createTRPCRouter({
title: input.title,
description: input.description,
updatedAt: new Date(),
returnUrl: input.returningUrl,
});

return { id };
Expand Down

0 comments on commit a3aea02

Please sign in to comment.