mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
succesfully implemented the valuation data upload functionality on handleSubmit now to turn this into a form
This commit is contained in:
parent
20b4d93b77
commit
3520d0858d
1 changed files with 53 additions and 6 deletions
|
|
@ -136,6 +136,7 @@ async function uploadCsvToS3({
|
|||
throw new Error("Upload failed.");
|
||||
}
|
||||
|
||||
console.log("S3 got the stuff");
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
|
|
@ -192,11 +193,13 @@ function useCreateRemoteAssessment({
|
|||
uprn,
|
||||
addressLineOne,
|
||||
postcode,
|
||||
valuation,
|
||||
}: {
|
||||
portfolioId: string;
|
||||
uprn: number | null;
|
||||
addressLineOne: string;
|
||||
postcode: string;
|
||||
valuation: string | number | 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.
|
||||
|
|
@ -218,8 +221,8 @@ function useCreateRemoteAssessment({
|
|||
isError: uploadAssetListIsError,
|
||||
} = useMutation(uploadCsvToS3, {
|
||||
onSuccess: (data) => {
|
||||
console.log("WAS IT A SUCCESS?", data.success);
|
||||
console.log("TRIGGERING THE ENGINE");
|
||||
console.log("WAS THE ASSET LIST A SUCCESS?", data.success);
|
||||
console.log("ASSETS TRIGGERING THE ENGINE");
|
||||
// This is where we trigger the engine!!!
|
||||
const body = {
|
||||
trigger_file_path: assetListFileKey,
|
||||
|
|
@ -231,6 +234,25 @@ function useCreateRemoteAssessment({
|
|||
},
|
||||
});
|
||||
|
||||
const {
|
||||
mutate: mutateUploadValuationData,
|
||||
isLoading: uploadValuationDataIsLoading,
|
||||
isError: uploadValuationDataIsError,
|
||||
} = useMutation(uploadCsvToS3, {
|
||||
onSuccess: (data) => {
|
||||
console.log("WAS VALUATION DATA A SUCCESS?", data.success);
|
||||
console.log("VALUATION TRIGGERING THE ENGINE");
|
||||
// This is where we trigger the engine!!!
|
||||
const body = {
|
||||
trigger_file_path: valuationDataFileKey,
|
||||
};
|
||||
// engine API call goes here
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
mutate: mutatePresignedUrl,
|
||||
isLoading: presignedUrlIsLoading,
|
||||
|
|
@ -246,21 +268,45 @@ function useCreateRemoteAssessment({
|
|||
postcode: postcode,
|
||||
},
|
||||
];
|
||||
const valuationData = [
|
||||
{
|
||||
uprn: uprn,
|
||||
valuation: 100000,
|
||||
},
|
||||
];
|
||||
const assetListCsvString = convertToCSV(assetList);
|
||||
const assetListCsv = new Blob([assetListCsvString], {
|
||||
type: "text/csv",
|
||||
});
|
||||
|
||||
mutateUploadAssetList({ presignedUrl: data.url, file: assetListCsv });
|
||||
|
||||
const valuationDataCsvString = convertToCSV(valuationData);
|
||||
const valuationDataCsv = new Blob([valuationDataCsvString], {
|
||||
type: "text/csv",
|
||||
});
|
||||
mutateUploadValuationData({ presignedUrl: data.url, file: valuationDataCsv });
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
},
|
||||
});
|
||||
|
||||
function handleSubmit() {
|
||||
mutatePresignedUrl({ userId, portfolioId, fileKey: assetListFileKey });
|
||||
console.log("SUCCESS"); // This is where we would want to trigger some kind of use feedback
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
// Mutate presigned URL for asset list file
|
||||
await mutatePresignedUrl({ userId, portfolioId, fileKey: assetListFileKey });
|
||||
console.log("ASSET LIST SUCCESS");
|
||||
|
||||
// Mutate presigned URL for valuation data file
|
||||
await mutatePresignedUrl({ userId, portfolioId, fileKey: valuationDataFileKey });
|
||||
console.log("VALUATION DATA SUCCESS");
|
||||
|
||||
// Trigger user feedback (e.g., show a success message)
|
||||
console.log("Both uploads SUCCESS");
|
||||
} catch (error) {
|
||||
// Handle error (e.g., show an error message)
|
||||
console.error("Error uploading files:", error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
@ -317,6 +363,7 @@ export default function RemoteAssessmentModal({
|
|||
uprn,
|
||||
addressLineOne,
|
||||
postcode,
|
||||
valuation,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue