Skip to content

Commit

Permalink
resolve typescript issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AmoabaKelvin committed Jul 20, 2024
1 parent 303765c commit df2e35b
Showing 1 changed file with 48 additions and 27 deletions.
75 changes: 48 additions & 27 deletions apps/web/src/app/(main)/form/[id]/form-settings.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
'use client';

import { RouterOutputs } from "@formbase/api";
import { UserInstance } from "@formbase/auth";
import { Button } from "@formbase/ui/primitives/button";
import { useRouter } from 'next/navigation';

import { zodResolver } from '@hookform/resolvers/zod';
import { BellRing, ExternalLink, FolderPen, FolderX } from 'lucide-react';
import { useForm } from 'react-hook-form';
import { toast } from 'sonner';
import { z } from 'zod';

import { type RouterOutputs } from '@formbase/api';
import { type UserInstance } from '@formbase/auth';
import { Button } from '@formbase/ui/primitives/button';
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
} from "@formbase/ui/primitives/form";
import { Input } from "@formbase/ui/primitives/input";
import { Label } from "@formbase/ui/primitives/label";
import { Switch } from "@formbase/ui/primitives/switch";
import { zodResolver } from "@hookform/resolvers/zod";
import { BellRing, ExternalLink, FolderPen, FolderX } from "lucide-react";
import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { z } from "zod";

import { api } from "~/lib/trpc/react";

import { revalidateDashboard } from "../../_actions/revalidateDashboard";
import { DeleteFormDialog } from "./delete-form-dialog";
} from '@formbase/ui/primitives/form';
import { Input } from '@formbase/ui/primitives/input';
import { Label } from '@formbase/ui/primitives/label';
import { Switch } from '@formbase/ui/primitives/switch';

import { api } from '~/lib/trpc/react';

import { revalidateDashboard } from '../../_actions/revalidateDashboard';
import { DeleteFormDialog } from './delete-form-dialog';

const formNameSchema = z.object({
name: z.string().min(1).optional(),
Expand Down Expand Up @@ -56,7 +58,9 @@ type _EnableSubmissionsRetentionSchema = z.infer<typeof enableRetentionSchema>;
type EnableFormNotificationsSchema = z.infer<typeof enableNotificationsSchema>;
type FormReturnUrlSchema = z.infer<typeof formReturnUrlSchema>;

type DefaultSubmissionEmailSchema = z.infer<typeof defaultSubmissionEmailSchema>;
type DefaultSubmissionEmailSchema = z.infer<
typeof defaultSubmissionEmailSchema
>;

type FormSettingsProps = {
form: RouterOutputs['form']['get'];
Expand Down Expand Up @@ -261,7 +265,13 @@ const ReturnUrlForm = ({
);
};

const FormDefaultSubmissionEmailRecipient = ({ formId, email }: { formId: string; email: string }) => {
const FormDefaultSubmissionEmailRecipient = ({
formId,
email,
}: {
formId: string;
email: string;
}) => {
const router = useRouter();

const formDefaultSubmissionEmail = useForm<DefaultSubmissionEmailSchema>({
Expand All @@ -271,10 +281,14 @@ const FormDefaultSubmissionEmailRecipient = ({ formId, email }: { formId: string
},
});

const { mutateAsync: updateFormDefaultSubmissionEmail, isPending: isUpdatingFormDefaultSubmissionEmail } =
api.form.update.useMutation();
const {
mutateAsync: updateFormDefaultSubmissionEmail,
isPending: isUpdatingFormDefaultSubmissionEmail,
} = api.form.update.useMutation();

async function handleFormDefaultSubmissionEmailSubmit(data: DefaultSubmissionEmailSchema) {
async function handleFormDefaultSubmissionEmailSubmit(
data: DefaultSubmissionEmailSchema,
) {
try {
await updateFormDefaultSubmissionEmail({
id: formId,
Expand All @@ -296,7 +310,11 @@ const FormDefaultSubmissionEmailRecipient = ({ formId, email }: { formId: string

return (
<Form {...formDefaultSubmissionEmail}>
<form onSubmit={formDefaultSubmissionEmail.handleSubmit(handleFormDefaultSubmissionEmailSubmit)}>
<form
onSubmit={formDefaultSubmissionEmail.handleSubmit(
handleFormDefaultSubmissionEmailSubmit,
)}
>
<FormField
control={formDefaultSubmissionEmail.control}
name="defaultSubmissionEmail"
Expand All @@ -306,7 +324,10 @@ const FormDefaultSubmissionEmailRecipient = ({ formId, email }: { formId: string
<FormLabel className="text-base">
Default Submission Email
</FormLabel>
<FormDescription>This is the email address that submission emails will be sent to</FormDescription>
<FormDescription>
This is the email address that submission emails will be sent
to
</FormDescription>
</div>
<FormControl>
<div className="flex gap-2">
Expand Down Expand Up @@ -392,7 +413,7 @@ const EnableFormSubmissions = ({
</div>
<FormControl>
<Switch
checked={field.value}
checked={field.value ?? false}
onCheckedChange={async (isChecked) => {
field.onChange(isChecked);
await handleEnableSubmissionsRetentionSubmit({
Expand Down Expand Up @@ -472,7 +493,7 @@ const EnableFormNotifications = ({
</div>
<FormControl>
<Switch
checked={field.value}
checked={field.value ?? false}
onCheckedChange={async (isChecked) => {
field.onChange(isChecked);
await handleEnableSubmissionsNotifications({
Expand Down

0 comments on commit df2e35b

Please sign in to comment.