mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
Allowing users to trigger remote assessments
This commit is contained in:
parent
c812923937
commit
adef91345b
5 changed files with 52 additions and 37 deletions
BIN
public/domna_logo_white_text.png
Normal file
BIN
public/domna_logo_white_text.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
|
|
@ -4,15 +4,22 @@ import { z } from "zod";
|
|||
const PresignedUrlBodySchema = z.object({
|
||||
portfolio_id: z.string(),
|
||||
housing_type: z.enum(["Social", "Private"]),
|
||||
goal: z.enum(["Increase EPC", "Reduce energy consumption"]),
|
||||
goal: z.enum(["Increasing EPC", "Reduce energy consumption"]),
|
||||
goal_value: z.string(),
|
||||
trigger_file_path: z.string(),
|
||||
valuation_file_path: z.string(),
|
||||
multi_plan: z.boolean().optional(),
|
||||
budget: z.number().optional().nullable(),
|
||||
scenario_name: z.string().optional(),
|
||||
event_type: z.enum(["remote_assessment"]).optional(),
|
||||
});
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
// For the moment, this api specifically handles uploads of csvs
|
||||
console.log("Triggering plan build");
|
||||
|
||||
const body = await request.json();
|
||||
console.log("Unvalidated body: ", body);
|
||||
let validatedBody;
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ function Nav({ userImage }: { userImage: string }) {
|
|||
<div className="flex items-center">
|
||||
<div className="flex-shrink-0">
|
||||
<Image
|
||||
src="/hestiaSymbol.png"
|
||||
src="/domna_logo_white_text.png"
|
||||
alt="Workflow"
|
||||
width={96}
|
||||
width={140}
|
||||
height={40}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ export function Footer() {
|
|||
return (
|
||||
<footer className="bg-brandblue text-white p-4 text-center border-t border-gray-300 mt-8">
|
||||
<p>
|
||||
© {new Date().getFullYear()} Hestia Hearth And Home. All rights
|
||||
reserved. Hestia proprietary IP.
|
||||
© {new Date().getFullYear()} Domna. All rights reserved. Domna
|
||||
proprietary IP.
|
||||
</p>
|
||||
<p>
|
||||
All intellectual property rights are retained by the respective owners.
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import {
|
|||
FormLabel,
|
||||
FormControl,
|
||||
FormMessage,
|
||||
FormDescription,
|
||||
} from "@/app/shadcn_components/ui/form";
|
||||
import { useToast } from "@/app/hooks/use-toast";
|
||||
|
||||
|
|
@ -47,8 +48,8 @@ const selecthousingTypeOptions = [
|
|||
|
||||
const selectGoalOptions = [
|
||||
{
|
||||
label: "Increase EPC",
|
||||
value: "Increase EPC",
|
||||
label: "Increasing EPC",
|
||||
value: "Increasing EPC",
|
||||
disabled: false,
|
||||
},
|
||||
{
|
||||
|
|
@ -204,7 +205,7 @@ async function generatePresignedUrl({
|
|||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
|
||||
data.fileKey = fileKey;
|
||||
|
||||
return data;
|
||||
|
|
@ -263,19 +264,17 @@ function useCreateRemoteAssessment({
|
|||
mutate: mutateUploadFile,
|
||||
isLoading: uploadFileIsLoading,
|
||||
isError: uploadFileIsError,
|
||||
} = useMutation(uploadCsvToS3,
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
// Callback for successful mutation
|
||||
console.log("Files uploaded successfully");
|
||||
// Trigger the engine here if needed
|
||||
},
|
||||
onError: (error) => {
|
||||
// Callback for failed mutation
|
||||
console.error("Error uploading files:", error);
|
||||
},
|
||||
}
|
||||
);
|
||||
} = useMutation(uploadCsvToS3, {
|
||||
onSuccess: (data) => {
|
||||
// Callback for successful mutation
|
||||
console.log("Files uploaded successfully");
|
||||
// Trigger the engine here if needed
|
||||
},
|
||||
onError: (error) => {
|
||||
// Callback for failed mutation
|
||||
console.error("Error uploading files:", error);
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
mutate: mutatePresignedUrl,
|
||||
|
|
@ -289,7 +288,6 @@ function useCreateRemoteAssessment({
|
|||
let csvFile: Blob = new Blob();
|
||||
|
||||
if (data.fileKey === assetListFileKey) {
|
||||
|
||||
const assetList = [
|
||||
{
|
||||
uprn: uprn,
|
||||
|
|
@ -301,9 +299,7 @@ function useCreateRemoteAssessment({
|
|||
csvFile = new Blob([convertToCSV(assetList)], {
|
||||
type: "text/csv",
|
||||
});
|
||||
|
||||
} else if (data.fileKey === valuationDataFileKey) {
|
||||
|
||||
const valuationData = [
|
||||
{
|
||||
uprn: uprn,
|
||||
|
|
@ -324,8 +320,7 @@ function useCreateRemoteAssessment({
|
|||
onError: (error) => {
|
||||
console.error(error);
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
async function triggerEngine(data: FormValues) {
|
||||
try {
|
||||
|
|
@ -342,7 +337,7 @@ function useCreateRemoteAssessment({
|
|||
scenario_name: data.scenario,
|
||||
multi_plan: true,
|
||||
budget: null,
|
||||
event_type: "Remote Assessment",
|
||||
event_type: "remote_assessment",
|
||||
};
|
||||
|
||||
const response = await fetch("/api/plan/trigger", {
|
||||
|
|
@ -365,10 +360,11 @@ function useCreateRemoteAssessment({
|
|||
async function handleSubmit(formData: FormValues) {
|
||||
try {
|
||||
await Promise.all([
|
||||
mutatePresignedUrl({
|
||||
userId,
|
||||
portfolioId,
|
||||
fileKey: assetListFileKey }),
|
||||
mutatePresignedUrl({
|
||||
userId,
|
||||
portfolioId,
|
||||
fileKey: assetListFileKey,
|
||||
}),
|
||||
mutatePresignedUrl({
|
||||
userId,
|
||||
portfolioId,
|
||||
|
|
@ -616,7 +612,19 @@ export default function RemoteAssessmentModal({
|
|||
name="valuation"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Valuation</FormLabel>
|
||||
<FormLabel>Valuation </FormLabel>
|
||||
<FormDescription>
|
||||
The valuation can be found at{" "}
|
||||
<a
|
||||
href={`https://www.zoopla.co.uk/property/uprn/${form.watch(
|
||||
"uprn"
|
||||
)}/`}
|
||||
target="_blank"
|
||||
>
|
||||
`https://www.zoopla.co.uk/property/uprn/
|
||||
{form.watch("uprn")}/`
|
||||
</a>
|
||||
</FormDescription>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
|
|
@ -636,13 +644,13 @@ export default function RemoteAssessmentModal({
|
|||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => { setIsOpen(false); }}>
|
||||
onClick={() => {
|
||||
setIsOpen(false);
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={presignedUrlIsLoading}
|
||||
>
|
||||
<Button type="submit" disabled={presignedUrlIsLoading}>
|
||||
{presignedUrlIsLoading ? "Submitting..." : "Submit"}
|
||||
</Button>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue