removed janky list all card and added formcard
All checks were successful
Vercel Preview Deployment / Deploy-Preview (push) Successful in 1m38s
All checks were successful
Vercel Preview Deployment / Deploy-Preview (push) Successful in 1m38s
This commit is contained in:
parent
39e6d86420
commit
f72c525701
@ -1,15 +1,10 @@
|
|||||||
import { Suspense } from "react";
|
import FormCard from "./FormCard";
|
||||||
import CreateWine from "./CreateWine";
|
|
||||||
import WineCards from "./WineCards";
|
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
return (
|
return (
|
||||||
<div className="container ">
|
<div className="container flex w-full flex-col justify-center">
|
||||||
<h1>Yes hello</h1>
|
<h1>Yes hello</h1>
|
||||||
<Suspense fallback={<p>Loading....</p>}>
|
<FormCard />
|
||||||
<CreateWine />
|
|
||||||
<WineCards />
|
|
||||||
</Suspense>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,9 @@ export default function CreateWine() {
|
|||||||
loadProducers();
|
loadProducers();
|
||||||
}, []);
|
}, []);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="container flex flex-col gap-4">
|
||||||
<form action={formAction}>
|
<form action={formAction}>
|
||||||
<input type="text" name="name" />
|
<input className="border-2" type="text" name="name" />
|
||||||
<select name="producer">
|
<select name="producer">
|
||||||
{producers.map((producer, i) => (
|
{producers.map((producer, i) => (
|
||||||
<option key={i} value={producer.id}>
|
<option key={i} value={producer.id}>
|
||||||
@ -47,6 +47,7 @@ export default function CreateWine() {
|
|||||||
</select>
|
</select>
|
||||||
<button type="submit">Add wine</button>
|
<button type="submit">Add wine</button>
|
||||||
</form>
|
</form>
|
||||||
|
{JSON.stringify(formState)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
10
src/app/_components/FormCard.tsx
Normal file
10
src/app/_components/FormCard.tsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import CreateWine from "./CreateWine";
|
||||||
|
|
||||||
|
export default function FormCard() {
|
||||||
|
return (
|
||||||
|
<div className="mx-auto p-4 shadow-md">
|
||||||
|
<h1>Add a new wine</h1>
|
||||||
|
<CreateWine />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@ -1,19 +0,0 @@
|
|||||||
import { getWines } from "~/server/actions/allWines";
|
|
||||||
import WineName from "./WineName";
|
|
||||||
import WineProducer from "./WineProducer";
|
|
||||||
export const dynamic = "force-dynamic";
|
|
||||||
|
|
||||||
const allWines = await getWines();
|
|
||||||
export default async function WineCards() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{allWines.map((wine, i) => {
|
|
||||||
return (
|
|
||||||
<div key={i} className="flex">
|
|
||||||
<WineName name={wine.name} /> - <WineProducer id={wine.producer} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
@ -2,6 +2,7 @@
|
|||||||
import { ZodError, z } from 'zod';
|
import { ZodError, z } from 'zod';
|
||||||
import { db } from '../db/index'
|
import { db } from '../db/index'
|
||||||
import { wines } from '../db/schema'
|
import { wines } from '../db/schema'
|
||||||
|
import { QueryResult } from 'pg';
|
||||||
|
|
||||||
type NewWine = typeof wines.$inferInsert;
|
type NewWine = typeof wines.$inferInsert;
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ export type Fields = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type FormState = {
|
export type FormState = {
|
||||||
message: string;
|
message: string | QueryResult<never>;
|
||||||
errors: Record<keyof Fields, string> | undefined;
|
errors: Record<keyof Fields, string> | undefined;
|
||||||
fieldValues: NewWine;
|
fieldValues: NewWine;
|
||||||
}
|
}
|
||||||
@ -39,9 +40,9 @@ export const addWine = async (
|
|||||||
try {
|
try {
|
||||||
schema.parse(newWine)
|
schema.parse(newWine)
|
||||||
|
|
||||||
const response = await db.insert(wines).values(newWine);
|
await db.insert(wines).values(newWine);
|
||||||
return {
|
return {
|
||||||
message: `success fully added ${response}`,
|
message: 'success',
|
||||||
errors: undefined,
|
errors: undefined,
|
||||||
fieldValues: {
|
fieldValues: {
|
||||||
name: "",
|
name: "",
|
||||||
|
Loading…
Reference in New Issue
Block a user