From 2fd461222a03048d982470eb117339c050ebbf90 Mon Sep 17 00:00:00 2001 From: vipeeshpavithran Date: Tue, 5 Sep 2023 15:10:29 +0530 Subject: [PATCH] json download and localstorage --- src/Components/PatientDetails/PatientDetails.tsx | 8 +++++--- src/Components/PatientForm/PatientForm.tsx | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Components/PatientDetails/PatientDetails.tsx b/src/Components/PatientDetails/PatientDetails.tsx index 5b1d95c..437f195 100644 --- a/src/Components/PatientDetails/PatientDetails.tsx +++ b/src/Components/PatientDetails/PatientDetails.tsx @@ -177,7 +177,9 @@ export default function PatientDetails(){ const handleCheckboxChange = (event:any) => { setIsChecked(event.target.checked); }; - + + //@ts-ignore + const patientData = localStorage.getItem('patientData') ? JSON.parse(localStorage.getItem('patientData')) : []; return( <> @@ -200,7 +202,7 @@ export default function PatientDetails(){ - + @@ -211,7 +213,7 @@ export default function PatientDetails(){ - + diff --git a/src/Components/PatientForm/PatientForm.tsx b/src/Components/PatientForm/PatientForm.tsx index 9648897..90c6192 100644 --- a/src/Components/PatientForm/PatientForm.tsx +++ b/src/Components/PatientForm/PatientForm.tsx @@ -338,9 +338,22 @@ export default function PatientForm(){ // Update the state with the new array setAllPatientData(updatedAllPatientData); + + localStorage.setItem('patientData', JSON.stringify(newPatientData)); console.log("UpdatedallPatientData:", updatedAllPatientData); - }; + TextFile(); + }; + + const TextFile = () => { + const element = document.createElement("a"); + //@ts-ignore + const textFile = new Blob([localStorage.getItem('patientData')], {type: 'text/json'}); + element.href = URL.createObjectURL(textFile); + element.download = "patientData.json"; + document.body.appendChild(element); + element.click(); + } const handleExpandChange =