From fda212f8da54b7fbae000b92981c15bfc22e3965 Mon Sep 17 00:00:00 2001 From: christian Date: Sat, 25 May 2024 08:59:50 +0200 Subject: [PATCH] Its working and i am officially the greatest (for the next 2 minutes) --- src/app/_components/CreateWine.tsx | 31 ++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/app/_components/CreateWine.tsx b/src/app/_components/CreateWine.tsx index e437421..b619c55 100644 --- a/src/app/_components/CreateWine.tsx +++ b/src/app/_components/CreateWine.tsx @@ -1,13 +1,21 @@ -import { useActionState } from "react"; -import { InsertResult, addWine } from "~/server/actions/addWine"; +"use client"; +import { useActionState, useEffect, useState } from "react"; +import { addWine } from "~/server/actions/addWine"; import { getProducers } from "~/server/actions/allProducers"; -type Wine = { - name: string; - producer: string; -}; +async function fetchProducers() { + const producers = await getProducers(); + return producers; +} -const producers = await getProducers(); +type ProducersData = { + id: string; + name: string; + createdAt: Date; + country: string; + region: string; + email: string; +}[]; export default function CreateWine() { const [formState, formAction] = useActionState(addWine, { @@ -18,7 +26,14 @@ export default function CreateWine() { producer: "", }, }); - + const [producers, setProducers] = useState([]); + useEffect(() => { + async function loadProducers() { + const producersData = await fetchProducers(); + setProducers(producersData); + } + loadProducers(); + }, []); return (