Skip to content

Commit

Permalink
chore: changes based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimduncan committed Jun 8, 2024
1 parent 31d0b3e commit 65a5d08
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 372 deletions.
13 changes: 13 additions & 0 deletions apps/web/src/app/(main)/_actions/revalidateDashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use server';

import { revalidatePath } from 'next/cache';

// eslint-disable-next-line @typescript-eslint/require-await
export const revalidateDashboard = async () => {
revalidatePath('/dashboard');
};

// eslint-disable-next-line @typescript-eslint/require-await
export const revalidateFromClient = async (route: string) => {
revalidatePath(route);
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,13 @@ export function CreateFormDialog() {
const router = useRouter();
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
name: '',
description: '',
returnUrl: '',
keys: [''],
},
});
const [showDialog, setShowDialog] = useState<boolean>(false);
const [_isCreatePending, startCreateTransaction] = useTransition();
const [isCreatePending, startCreateTransaction] = useTransition();

const { mutateAsync: createNewForm } = api.form.create.useMutation();

const createPost = (data: z.infer<typeof FormSchema>) => {
const createForm = (data: z.infer<typeof FormSchema>) => {
startCreateTransaction(async () => {
await createNewForm(
{
Expand All @@ -86,7 +80,7 @@ export function CreateFormDialog() {
};

function onSubmit(data: z.infer<typeof FormSchema>) {
createPost(data);
createForm(data);

setShowDialog(false);
}
Expand Down Expand Up @@ -159,6 +153,7 @@ export function CreateFormDialog() {
<Button
onClick={form.handleSubmit(onSubmit)}
className="mt-2 w-full"
loading={isCreatePending}
>
Create Form
</Button>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/app/(main)/form/[id]/form-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Switch } from '@formbase/ui/primitives/switch';

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

import { refreshDashboardAfterDeletion } from '../_actions/refresh-dashboard-after-deletion';
import { revalidateDashboard } from '../../_actions/revalidateDashboard';
import { DeleteFormDialog } from './delete-form-dialog';

const formNameSchema = z.object({
Expand Down Expand Up @@ -65,7 +65,7 @@ export function FormSettings({ form }: FormSettingsProps) {
}

const redirectToDashboard = () => {
void refreshDashboardAfterDeletion();
void revalidateDashboard();
router.push('/dashboard');
};

Expand Down

This file was deleted.

14 changes: 4 additions & 10 deletions apps/web/src/app/(main)/onboarding/form/create-form-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,14 @@ export function CreateFormDialog() {
const router = useRouter();
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
name: '',
description: '',
returnUrl: '',
keys: [''],
},
});
const [showDialog, setShowDialog] = useState<boolean>(false);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, startCreateTransaction] = useTransition();
const [isCreatingForm, startCreateTransaction] = useTransition();

const { mutateAsync: createNewForm } =
api.form.createOnboardingForm.useMutation();

const createPost = (data: z.infer<typeof FormSchema>) => {
const createForm = (data: z.infer<typeof FormSchema>) => {
startCreateTransaction(async () => {
await createNewForm(
{
Expand All @@ -84,7 +77,7 @@ export function CreateFormDialog() {
};

function onSubmit(data: z.infer<typeof FormSchema>) {
createPost(data);
createForm(data);

setShowDialog(false);
}
Expand Down Expand Up @@ -157,6 +150,7 @@ export function CreateFormDialog() {
<Button
onClick={form.handleSubmit(onSubmit)}
className="mt-2 w-full"
loading={isCreatingForm}
>
Create Form Endpoint
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { toast } from 'sonner';

import { Button } from '@formbase/ui/primitives/button';

import { revalidateFromClient } from '../../_actions/revalidateDashboard';

type SendFormSubmissionButton = {
formId: string | null;
};
Expand All @@ -29,17 +31,16 @@ export default function SendFormSubmissionButton({

toast.success('Form submission sent!');

// router.push(`/form/${formId}`);
// 'TODO: redirec to form page after we figure out how to refetch the submissions')
router.push('dasbhoard');
void revalidateFromClient(`/form/${formId}`);
router.push(`/form/${formId}`);
});
};
return (
<Button
onClick={handleFormSubmission}
className="flex items-center gap-1"
loading={isSubmittingForm}
disabled={!formId}
disabled={!formId || isSubmittingForm}
>
{!isSubmittingForm && <Send className="w-4 h-4" />}
<span>Send a submission</span>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/primitives/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Loader = ({
};

const buttonVariants = cva(
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50',
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:select-none disabled:opacity-50',
{
variants: {
variant: {
Expand Down
Loading

0 comments on commit 65a5d08

Please sign in to comment.