Skip to content

Commit

Permalink
fix nomenclature and others
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Granello committed Jan 9, 2025
1 parent 937a222 commit cd822a7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
16 changes: 11 additions & 5 deletions app/components/ui/CalculatorInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -36,7 +36,7 @@ const CalculatorInput = () => {
const urlHouseType = searchParams.get("houseType");
const urlMaintenancePercentage = searchParams.get("maintenancePercentage");

const form = useForm<formType>({
const form = useForm<FormFontend>({
resolver: zodResolver(formSchema),
defaultValues: {
houseType:
Expand All @@ -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",
Expand Down Expand Up @@ -336,8 +336,14 @@ const CalculatorInput = () => {
<ClipLoader color="black" size={50} />
</div>
);
} else if (view === "dashboard") {
return <Dashboard processedData={data} inputData={form.getValues()} />;
} else if (view === "dashboard" && data) {
const formValues = form.getValues();
return (
<Dashboard
processedData={data}
inputData={formSchema.parse(formValues)}
/>
);
}
};

Expand Down
4 changes: 2 additions & 2 deletions app/components/ui/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -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<DashboardProps> = ({ inputData }) => {
Expand Down
4 changes: 2 additions & 2 deletions app/components/ui/FormEdit.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,7 +10,7 @@ import {
import { HouseType } from "../../models/Property";

interface Props {
formData: formType;
formData: FormFontend;
}

const houseTypeDisplayNames: Record<HouseType, string> = {
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/formSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ export const formSchema = z.object({
maintenancePercentage: maintenancePercentageSchema,
});

export type formType = z.infer<typeof formSchema>;
export type FormFontend = z.infer<typeof formSchema>;

0 comments on commit cd822a7

Please sign in to comment.