From 24e8dee32eab12d0f6d89da4ea34bb021039ffa1 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 15 Apr 2025 22:40:27 +0100 Subject: [PATCH] remote assessment feature working --- .../components/RemoteAssessmentModal.tsx | 174 +++++++++++++++++- 1 file changed, 173 insertions(+), 1 deletion(-) diff --git a/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx b/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx index b500a12..0a46857 100644 --- a/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx +++ b/src/app/portfolio/[slug]/components/RemoteAssessmentModal.tsx @@ -5,7 +5,7 @@ import { Fragment, useMemo } from "react"; import { Input } from "@/app/shadcn_components/ui/input"; import { Button } from "@/app/shadcn_components/ui/button"; import { Float } from "@headlessui-float/react"; -import { ChevronDownIcon } from "@heroicons/react/20/solid"; +import { ChevronDownIcon, ChevronRightIcon } from "@heroicons/react/20/solid"; import { useMutation } from "@tanstack/react-query"; import { useSession } from "next-auth/react"; import { useForm, FormProvider } from "react-hook-form"; @@ -31,6 +31,12 @@ type DropdownProps = { options: Option[]; selectedOption: string; onSelectOption: (option: Option) => void; + width?: string; +}; + +// Extend the existing props +type OptionalDropdownProps = Omit & { + selectedOption: string | null | undefined; }; const selecthousingTypeOptions = [ @@ -46,6 +52,57 @@ const selecthousingTypeOptions = [ }, ]; +const propertyTypeOptions = [ + { + label: "House", + value: "House", + disabled: false, + }, + { + label: "Flat", + value: "Flat", + disabled: false, + }, + { + label: "Bungalow", + value: "bungalow", + disabled: false, + }, + { + label: "Maisonette", + value: "Maisonette", + disabled: false, + }, + { + label: "Other", + value: "Other", + disabled: false, + }, +]; + +const builtFormOptions = [ + { + label: "Detached", + value: "Detached", + disabled: false, + }, + { + label: "Semi-Detached", + value: "Semi-Detached", + disabled: false, + }, + { + label: "Mid-Terrace", + value: "Mid-Terrace", + disabled: false, + }, + { + label: "End-Terrace", + value: "End-Terrace", + disabled: false, + }, +]; + const selectGoalOptions = [ { label: "Increasing EPC", @@ -102,6 +159,9 @@ const formSchema = z.object({ postcode: z.string().min(1, "Postcode is required"), uprn: z.number().min(1, "UPRN is required"), valuation: z.number().min(1, "Valuation is required"), + // Both property type and build form are optional + propertyType: z.string().optional().nullable(), + builtForm: z.string().optional().nullable(), }); type FormValues = z.infer; @@ -154,6 +214,58 @@ export function SelectDropdown({ ); } +export function SelectUpDropdown({ + options, + selectedOption, + onSelectOption, + width = "w-1/2", +}: OptionalDropdownProps) { + const menuButtonStyle = (width = "w-full") => + `inline-flex justify-center ${width} px-4 py-2 text-sm font-medium text-white bg-brandblue rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75`; + + return ( + + + + {selectedOption || "Select an option"} + + + + {options.map((option) => ( + + {({ active }) => ( + + )} + + ))} + + + + + ); +} + async function uploadCsvToS3({ presignedUrl, file, @@ -239,12 +351,16 @@ function useCreateRemoteAssessment({ addressLineOne, postcode, valuation, + propertyType, + builtForm, }: { portfolioId: string; uprn: number | null; addressLineOne: string; postcode: string; valuation: string | number | null; + propertyType?: string | null; + builtForm?: string | null; }) { // 1) We want to upload the asset data. To do this, we format the asset data, generate a presigned URL, and upload the data to S3. // 2) We then want to upload valuation data. To do this, we format the valuation data, generate a presigned URL, and upload the data to S3. @@ -293,6 +409,8 @@ function useCreateRemoteAssessment({ uprn: uprn, address: addressLineOne, postcode: postcode, + property_type: propertyType, + built_form: builtForm, }, ]; @@ -436,6 +554,8 @@ export default function RemoteAssessmentModal({ addressLineOne: form.watch("addressLineOne"), postcode: form.watch("postcode"), valuation: form.watch("valuation"), + propertyType: form.watch("propertyType"), + builtForm: form.watch("builtForm"), }); return ( @@ -640,6 +760,58 @@ export default function RemoteAssessmentModal({ )} /> +
+

+ Optional: Property Type and Built + Form are only required if no EPC is available. +

+
+
+ ( + + Property Type + + + field.onChange(option.value) + } + /> + + + + )} + /> +
+ +
+ ( + + Built Form + + + field.onChange(option.value) + } + /> + + + + )} + /> +
+
+
+