From 85cf137c4d0d9b114da46e77164a2d5659b1f1b4 Mon Sep 17 00:00:00 2001 From: Nithin Date: Sat, 24 Aug 2024 19:14:40 +0530 Subject: [PATCH 1/6] Fix TypeError: s.map is not a function in InvestigationBuilder component --- .../InvestigationBuilder.tsx | 275 +++++++++--------- 1 file changed, 143 insertions(+), 132 deletions(-) diff --git a/src/Components/Common/prescription-builder/InvestigationBuilder.tsx b/src/Components/Common/prescription-builder/InvestigationBuilder.tsx index ce7c579ee22..65f427cb26b 100644 --- a/src/Components/Common/prescription-builder/InvestigationBuilder.tsx +++ b/src/Components/Common/prescription-builder/InvestigationBuilder.tsx @@ -96,164 +96,175 @@ export default function InvestigationBuilder( }; useEffect(() => { - const load = async () => setInvestigationsList(await loadInvestigations()); + const load = async () => { + try { + const loadedInvestigations = await loadInvestigations(); + setInvestigationsList(loadedInvestigations); + } catch (error) { + console.error("Error loading investigations:", error); + setInvestigationsList([]); + } + }; load(); }, []); return (
- {investigations?.map((investigation, i) => { - const setFrequency = (frequency: string) => { - setItem( - { - ...investigation, - frequency, - }, - i, - ); - }; + {(Array.isArray(investigations) ? investigations : []).map( + (investigation, i) => { + const setFrequency = (frequency: string) => { + setItem( + { + ...investigation, + frequency, + }, + i, + ); + }; - const setType = (type: string[]) => { - setItem( - { - ...investigation, - type, - }, - i, - ); - }; + const setType = (type: string[]) => { + setItem( + { + ...investigation, + type, + }, + i, + ); + }; - return ( -
-
-

- Investigation No. {i + 1} -

- -
-
-
-
- Investigations Recommended - {" *"} -
-
- setActiveIdx(i)} - onBlur={() => setActiveIdx(null)} - /> -
+ return ( +
+
+

+ Investigation No. {i + 1} +

+
-
-
-
- Is the investigation repetitive? -
- +
+
+ Investigations Recommended + {" *"} +
+
+ setActiveIdx(i)} onBlur={() => setActiveIdx(null)} - className="inline-block h-[18px] w-[18px] rounded-md" - checked={investigation?.repetitive || false} - onChange={(e) => { - setItem( - { - ...investigation, - repetitive: e.currentTarget.checked, - }, - i, - ); - }} />
- {investigation.repetitive ? ( -
-
- Frequency{" *"} -
-
- setActiveIdx(i)} - onBlur={() => setActiveIdx(null)} - /> -
-
- ) : ( -
- Time{" *"} +
+
+
+
+ Is the investigation repetitive? +
setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} + className="inline-block h-[18px] w-[18px] rounded-md" + checked={investigation?.repetitive || false} onChange={(e) => { setItem( { ...investigation, - time: e.currentTarget.value, + repetitive: e.currentTarget.checked, }, i, ); }} - onFocus={() => setActiveIdx(i)} - onBlur={() => setActiveIdx(null)} />
- )} -
-
-
Notes
- { - setItem( - { - ...investigation, - notes: e.currentTarget.value, - }, - i, - ); - }} - onFocus={() => setActiveIdx(i)} - onBlur={() => setActiveIdx(null)} - /> + {investigation.repetitive ? ( +
+
+ Frequency + {" *"} +
+
+ setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} + /> +
+
+ ) : ( +
+ Time{" *"} + { + setItem( + { + ...investigation, + time: e.currentTarget.value, + }, + i, + ); + }} + onFocus={() => setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} + /> +
+ )} +
+
+
Notes
+ { + setItem( + { + ...investigation, + notes: e.currentTarget.value, + }, + i, + ); + }} + onFocus={() => setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} + /> +
-
- ); - })} + ); + }, + )} + return ( +
+
+

+ Investigation No. {i + 1} +

+ +
+
+
+
+ Investigations Recommended + {" *"} +
+
+ setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} + /> +
-
-
-
- Investigations Recommended - {" *"} -
-
- +
+
+ Is the investigation repetitive? +
+ setActiveIdx(i)} onBlur={() => setActiveIdx(null)} + className="inline-block h-[18px] w-[18px] rounded-md" + checked={investigation?.repetitive || false} + onChange={(e) => { + setItem( + { + ...investigation, + repetitive: e.currentTarget.checked, + }, + i, + ); + }} />
-
-
-
-
- Is the investigation repetitive? -
+ {investigation.repetitive ? ( +
+
+ Frequency{" *"} +
+
+ setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} + /> +
+
+ ) : ( +
+ Time{" *"} setActiveIdx(i)} - onBlur={() => setActiveIdx(null)} - className="inline-block h-[18px] w-[18px] rounded-md" - checked={investigation?.repetitive || false} + type="datetime-local" + className="block w-[calc(100%-5px)] rounded border border-secondary-400 bg-secondary-100 px-4 py-2 text-sm hover:bg-secondary-200 focus:border-primary-500 focus:bg-white focus:outline-none focus:ring-primary-500" + value={investigation.time || ""} onChange={(e) => { setItem( { ...investigation, - repetitive: e.currentTarget.checked, + time: e.currentTarget.value, }, i, ); }} + onFocus={() => setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} />
- {investigation.repetitive ? ( -
-
- Frequency - {" *"} -
-
- setActiveIdx(i)} - onBlur={() => setActiveIdx(null)} - /> -
-
- ) : ( -
- Time{" *"} - { - setItem( - { - ...investigation, - time: e.currentTarget.value, - }, - i, - ); - }} - onFocus={() => setActiveIdx(i)} - onBlur={() => setActiveIdx(null)} - /> -
- )} -
-
-
Notes
- { - setItem( - { - ...investigation, - notes: e.currentTarget.value, - }, - i, - ); - }} - onFocus={() => setActiveIdx(i)} - onBlur={() => setActiveIdx(null)} - /> -
+ )} +
+
+
Notes
+ { + setItem( + { + ...investigation, + notes: e.currentTarget.value, + }, + i, + ); + }} + onFocus={() => setActiveIdx(i)} + onBlur={() => setActiveIdx(null)} + />
- ); - }, - )} +
+ ); + })}