N-FIN-12: add sample data generation for development (#14)

Resolves #12
This commit is contained in:
Markus Thielker 2024-03-11 03:58:02 +01:00 committed by GitHub
commit c1359dbcf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 323 additions and 4 deletions

View file

@ -7,6 +7,9 @@ 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';
export default async function AccountPage() {
@ -16,6 +19,28 @@ export default async function AccountPage() {
redirect(URL_SIGN_IN);
}
let paymentCount = 0;
let entityCount = 0;
let categoryCount = 0;
if (process.env.NODE_ENV === 'development') {
paymentCount = await prismaClient.payment.count({
where: {
userId: user.id,
},
});
entityCount = await prismaClient.entity.count({
where: {
userId: user.id,
},
});
categoryCount = await prismaClient.category.count({
where: {
userId: user.id,
},
});
}
return (
<div className="flex flex-col items-center">
<Card className="w-full max-w-md mt-12">
@ -36,8 +61,33 @@ export default async function AccountPage() {
disabled
value={user?.username}/>
</div>
<div className="flex flex-row items-center space-x-4">
<div>
<Label>Payments</Label>
<Input
disabled
value={paymentCount}/>
</div>
<div>
<Label>Entities</Label>
<Input
disabled
value={entityCount}/>
</div>
<div>
<Label>Categories</Label>
<Input
disabled
value={categoryCount}/>
</div>
</div>
</CardContent>
<CardFooter>
<CardFooter className="space-x-4">
{
process.env.NODE_ENV === 'development' && (
<GenerateSampleDataForm onSubmit={generateSampleData}/>
)
}
<SignOutForm onSubmit={signOut}/>
</CardFooter>
</Card>

View file

@ -6,7 +6,7 @@ export default function AuthLayout({
children: React.ReactNode;
}>) {
return (
<div className="flex min-h-screen items-center justify-center">
<div className="flex justify-center">
{children}
</div>
);

View file

@ -7,7 +7,7 @@ import { URL_SIGN_UP } from '@/lib/constants';
export default async function SignInPage() {
return (
<Card className="w-full max-w-md">
<Card className="w-full max-w-md mt-12">
<CardHeader>
<CardTitle>Sign in</CardTitle>
<CardDescription>Sign into your existing account</CardDescription>

View file

@ -7,7 +7,7 @@ import { URL_SIGN_IN } from '@/lib/constants';
export default async function SignUpPage() {
return (
<Card className="w-full max-w-md">
<Card className="w-full max-w-md mt-12">
<CardHeader>
<CardTitle>Sign up</CardTitle>
<CardDescription>Create a new account.</CardDescription>