From cd822a7f6f8b3b25c8b836266275c42144ee744f Mon Sep 17 00:00:00 2001 From: Gabriele Granello Date: Thu, 9 Jan 2025 14:19:10 +0100 Subject: [PATCH] fix nomenclature and others --- app/components/ui/CalculatorInput.tsx | 16 +++++++++++----- app/components/ui/Dashboard.tsx | 4 ++-- app/components/ui/FormEdit.tsx | 4 ++-- app/schemas/formSchema.ts | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/components/ui/CalculatorInput.tsx b/app/components/ui/CalculatorInput.tsx index f1a5cf29..171829b5 100644 --- a/app/components/ui/CalculatorInput.tsx +++ b/app/components/ui/CalculatorInput.tsx @@ -4,7 +4,7 @@ import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { Household } from "@/app/models/Household"; import Dashboard from "./Dashboard"; -import { formSchema, formType } from "@/app/schemas/formSchema"; +import { formSchema, FormFontend } from "@/app/schemas/formSchema"; import { useSearchParams } from "next/navigation"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; @@ -36,7 +36,7 @@ const CalculatorInput = () => { const urlHouseType = searchParams.get("houseType"); const urlMaintenancePercentage = searchParams.get("maintenancePercentage"); - const form = useForm({ + const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { houseType: @@ -60,7 +60,7 @@ const CalculatorInput = () => { }, }); - const onSubmit = async (data: formType) => { + const onSubmit = async (data: FormFontend) => { setView("loading"); const response = await fetch("/api", { method: "POST", @@ -336,8 +336,14 @@ const CalculatorInput = () => { ); - } else if (view === "dashboard") { - return ; + } else if (view === "dashboard" && data) { + const formValues = form.getValues(); + return ( + + ); } }; diff --git a/app/components/ui/Dashboard.tsx b/app/components/ui/Dashboard.tsx index 1e5a85fe..40542849 100644 --- a/app/components/ui/Dashboard.tsx +++ b/app/components/ui/Dashboard.tsx @@ -1,11 +1,11 @@ import React, { useRef, useState } from "react"; import GraphCard from "./GraphCard"; import { Household } from "@/app/models/Household"; -import type { formSchema } from "@/app/schemas/formSchema"; +import { FormFontend } from "@/app/schemas/formSchema"; interface DashboardProps { processedData: Household; - inputData: typeof formSchema; + inputData: FormFontend; } const Dashboard: React.FC = ({ inputData }) => { diff --git a/app/components/ui/FormEdit.tsx b/app/components/ui/FormEdit.tsx index c7e8a194..97e7ed7e 100644 --- a/app/components/ui/FormEdit.tsx +++ b/app/components/ui/FormEdit.tsx @@ -1,6 +1,6 @@ "use client"; import React from "react"; -import { formType } from "@/app/schemas/formSchema"; +import { FormFontend } from "@/app/schemas/formSchema"; import { Accordion, AccordionContent, @@ -10,7 +10,7 @@ import { import { HouseType } from "../../models/Property"; interface Props { - formData: formType; + formData: FormFontend; } const houseTypeDisplayNames: Record = { diff --git a/app/schemas/formSchema.ts b/app/schemas/formSchema.ts index c13d3ce5..cf862d6d 100644 --- a/app/schemas/formSchema.ts +++ b/app/schemas/formSchema.ts @@ -27,4 +27,4 @@ export const formSchema = z.object({ maintenancePercentage: maintenancePercentageSchema, }); -export type formType = z.infer; +export type FormFontend = z.infer;