Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url Search Parameters #173

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/components/ui/CalculatorInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { Household } from "@/app/models/Household";
import Dashboard from "./Dashboard";
import { formSchema, formType } from "@/app/schemas/formSchema";
import { useSearchParams } from "next/navigation";

import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { ClipLoader } from "react-spinners";
Expand All @@ -22,17 +23,21 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";

const CalculatorInput = () => {
const [view, setView] = useState("form");
const [data, setData] = useState<Household | null>(null);

const searchParams = useSearchParams();
const urlPostcode = searchParams.get("postcode");

const methods = useForm<formType>({
resolver: zodResolver(formSchema),
defaultValues: {
houseType: "D", // Default value for house type
maintenancePercentage: 0.015,
housePostcode: urlPostcode || "",
},
});

const [view, setView] = useState("form");
const [data, setData] = useState<Household | null>(null);

const onSubmit = async (data: formType) => {
setView("loading");
const response = await fetch("/api", {
Expand Down Expand Up @@ -188,7 +193,8 @@ const CalculatorInput = () => {
</RadioGroup>
</FormControl>
<FormDescription>
Select a level for maintenance spend, as a percentage of house cost.
Select a level for maintenance spend, as a percentage of
house cost.
</FormDescription>
<FormMessage />
</FormItem>
Expand Down
6 changes: 5 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import CalculatorInput from "./components/ui/CalculatorInput";
import { ClipLoader } from "react-spinners";
import { Suspense } from "react";
export default function Home() {
return (
<main>
<CalculatorInput />
<Suspense fallback={<ClipLoader />}>
<CalculatorInput />
</Suspense>
</main>
);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
"mathjs": "^13.1.1",
"next": "^14.2.15",
"postcode": "^5.1.0",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.53.1",
"react-spinners": "^0.14.1",
"react": "^18",
"tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7",
"ts-node": "^10.9.2",
Expand Down
Loading