N-FIN-47: replace buttons with new component
This commit is contained in:
parent
410d96a8b8
commit
0e62b7c2fd
3 changed files with 18 additions and 62 deletions
|
@ -5,11 +5,10 @@ import { redirect } from 'next/navigation';
|
|||
import signOut from '@/lib/actions/signOut';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import SignOutForm from '@/components/form/signOutForm';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
import GenerateSampleDataForm from '@/components/form/generateSampleDataForm';
|
||||
import generateSampleData from '@/lib/actions/generateSampleData';
|
||||
import { prismaClient } from '@/prisma';
|
||||
import { ServerActionTrigger } from '@/components/form/serverActionTrigger';
|
||||
|
||||
export default async function AccountPage() {
|
||||
|
||||
|
@ -81,18 +80,23 @@ export default async function AccountPage() {
|
|||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
{
|
||||
process.env.NODE_ENV === 'development' ? (
|
||||
<CardFooter className="grid gap-4 grid-cols-1 md:grid-cols-2">
|
||||
<GenerateSampleDataForm onSubmit={generateSampleData}/>
|
||||
<SignOutForm onSubmit={signOut}/>
|
||||
</CardFooter>
|
||||
) : (
|
||||
<CardFooter>
|
||||
<SignOutForm onSubmit={signOut}/>
|
||||
</CardFooter>
|
||||
)
|
||||
}
|
||||
<CardFooter className="w-full grid gap-4 grid-cols-1 md:grid-cols-2">
|
||||
<ServerActionTrigger
|
||||
className="col-span-2"
|
||||
action={signOut}>
|
||||
Sign Out
|
||||
</ServerActionTrigger>
|
||||
{
|
||||
process.env.NODE_ENV === 'development' && (
|
||||
<ServerActionTrigger
|
||||
variant="outline"
|
||||
className="col-span-2"
|
||||
action={generateSampleData}>
|
||||
Generate sample data
|
||||
</ServerActionTrigger>
|
||||
)
|
||||
}
|
||||
</CardFooter>
|
||||
</Card>
|
||||
<div className="flex w-full items-center justify-between max-w-md mt-2 text-neutral-600">
|
||||
<p>Version {process.env.appVersion}</p>
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import React from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { toast } from 'sonner';
|
||||
import { sonnerContent } from '@/components/ui/sonner';
|
||||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
|
||||
export default function GenerateSampleDataForm({onSubmit}: { onSubmit: () => Promise<ActionResponse> }) {
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const response = await onSubmit();
|
||||
toast(sonnerContent(response));
|
||||
router.refresh();
|
||||
};
|
||||
|
||||
return (
|
||||
<Button className="w-full" variant="outline" onClick={handleSubmit}>Generate sample data</Button>
|
||||
);
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
'use client';
|
||||
|
||||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import React from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { toast } from 'sonner';
|
||||
import { sonnerContent } from '@/components/ui/sonner';
|
||||
|
||||
export default function SignOutForm({onSubmit}: { onSubmit: () => Promise<ActionResponse> }) {
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const handleSignOut = async () => {
|
||||
const response = await onSubmit();
|
||||
toast(sonnerContent(response));
|
||||
if (response.redirect) {
|
||||
router.push(response.redirect);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Button className="w-full" onClick={handleSignOut}>Sign out</Button>
|
||||
);
|
||||
}
|
Loading…
Add table
Reference in a new issue