- {Math.floor(
- getSlotsPerSession(
- availability[0].start_time,
- availability[0].end_time,
- slot_size_in_minutes,
- ) ?? 0,
- )}{" "}
+ {availability[0] &&
+ Math.floor(
+ getSlotsPerSession(
+ availability[0].start_time,
+ availability[0].end_time,
+ slot_size_in_minutes,
+ ) ?? 0,
+ )}{" "}
slots of {slot_size_in_minutes} mins.
)}
@@ -303,7 +304,9 @@ const diagonalStripes = {
export const formatAvailabilityTime = (
availability: AvailabilityDateTime[],
) => {
- const startTime = availability[0].start_time;
- const endTime = availability[0].end_time;
- return `${formatTimeShort(startTime)} - ${formatTimeShort(endTime)}`;
+ if (availability[0]) {
+ const startTime = availability[0].start_time;
+ const endTime = availability[0].end_time;
+ return `${formatTimeShort(startTime)} - ${formatTimeShort(endTime)}`;
+ }
};
diff --git a/src/components/ui/chart.tsx b/src/components/ui/chart.tsx
index 5887b4d3acb..07289a66ab4 100644
--- a/src/components/ui/chart.tsx
+++ b/src/components/ui/chart.tsx
@@ -137,7 +137,7 @@ const ChartTooltipContent = React.forwardRef<
}
const [item] = payload;
- const key = `${labelKey || item.dataKey || item.name || "value"}`;
+ const key = `${labelKey || item?.dataKey || item?.name || "value"}`;
const itemConfig = getPayloadConfigFromPayload(config, item, key);
const value =
!labelKey && typeof label === "string"
diff --git a/src/components/ui/input-otp.tsx b/src/components/ui/input-otp.tsx
index ea07b294c56..9d150705448 100644
--- a/src/components/ui/input-otp.tsx
+++ b/src/components/ui/input-otp.tsx
@@ -33,7 +33,7 @@ const InputOTPSlot = React.forwardRef<
React.ComponentPropsWithoutRef<"div"> & { index: number }
>(({ index, className, ...props }, ref) => {
const inputOTPContext = React.useContext(OTPInputContext);
- const { char, hasFakeCaret, isActive } = inputOTPContext.slots[index];
+ const { char, hasFakeCaret, isActive } = inputOTPContext.slots[index] ?? {};
return (
{
- if (history.length > 1)
+ if (history.length > 1) {
// Otherwise, navigate to history present in the app navigation history stack.
- return navigate(history[1]);
+ if (history[1]) return navigate(history[1]);
+ }
if (fallbackUrl)
// use provided fallback url if provided.
diff --git a/src/hooks/useFileManager.tsx b/src/hooks/useFileManager.tsx
index e6c92ff5166..82fafce3b88 100644
--- a/src/hooks/useFileManager.tsx
+++ b/src/hooks/useFileManager.tsx
@@ -81,8 +81,9 @@ export default function useFileManager(
const queryClient = useQueryClient();
const getExtension = (url: string) => {
- const div1 = url.split("?")[0].split(".");
- const ext: string = div1[div1.length - 1].toLowerCase();
+ const div1 = url.split("?")[0]?.split(".") || [];
+ const ext: string =
+ div1.length > 0 ? (div1[div1.length - 1]?.toLowerCase() ?? "") : "";
return ext;
};
diff --git a/src/hooks/useFileUpload.tsx b/src/hooks/useFileUpload.tsx
index d5884dddd02..dc65a310c61 100644
--- a/src/hooks/useFileUpload.tsx
+++ b/src/hooks/useFileUpload.tsx
@@ -105,7 +105,7 @@ export default function useFileUpload(
setFiles((prev) => [...prev, ...selectedFiles]);
selectedFiles.forEach((file) => {
- const ext: string = file.name.split(".")[1];
+ const ext: string = file.name.split(".")[1] ?? "";
if (ExtImage.includes(ext)) {
const options = {
initialQuality: 0.6,
diff --git a/src/hooks/useFilters.tsx b/src/hooks/useFilters.tsx
index c5984a70c9c..66a48e9bbc1 100644
--- a/src/hooks/useFilters.tsx
+++ b/src/hooks/useFilters.tsx
@@ -94,7 +94,9 @@ export default function useFilters({
name={name}
value={
value === undefined
- ? humanizeStrings(paramKey.map((k) => qParams[k]).filter(Boolean))
+ ? (humanizeStrings(
+ paramKey.map((k) => qParams[k]).filter(Boolean),
+ ) ?? "")
: value
}
onRemove={() => removeFilters(paramKey)}
@@ -128,7 +130,10 @@ export default function useFilters({
},
range(name: string, paramKey: string, minKey = "min", maxKey = "max") {
const paramKeys = [paramKey + "_" + minKey, paramKey + "_" + maxKey];
- const values = [qParams[paramKeys[0]], qParams[paramKeys[1]]];
+ const values = [
+ paramKeys[0] && qParams[paramKeys[0]],
+ paramKeys[1] && qParams[paramKeys[1]],
+ ];
if (values[0] === values[1])
return [{ name, value: values[0], paramKey: paramKeys }];
return [name + " " + minKey, name + " " + maxKey].map((name, i) => {
diff --git a/src/pages/Appointments/utils.ts b/src/pages/Appointments/utils.ts
index 4b131e50382..b01e0bfb798 100644
--- a/src/pages/Appointments/utils.ts
+++ b/src/pages/Appointments/utils.ts
@@ -51,9 +51,12 @@ export const groupSlotsByAvailability = (slots: TokenSlot[]) => {
);
// sort availability by first slot start time
- result.sort((a, b) =>
- compareAsc(a.slots[0].start_datetime, b.slots[0].start_datetime),
- );
+ result.sort((a, b) => {
+ if (a.slots[0]?.start_datetime && b.slots[0]?.start_datetime) {
+ return compareAsc(a.slots[0].start_datetime, b.slots[0].start_datetime);
+ }
+ return 0;
+ });
return result;
};
diff --git a/src/pages/Encounters/EncounterShow.tsx b/src/pages/Encounters/EncounterShow.tsx
index 0440aa49aae..b68383ed927 100644
--- a/src/pages/Encounters/EncounterShow.tsx
+++ b/src/pages/Encounters/EncounterShow.tsx
@@ -166,8 +166,7 @@ export const EncounterShow = (props: Props) => {
if (!encounterData) {
return
;
}
-
- const SelectedTab = tabs[props.tab];
+ const SelectedTab = tabs[props.tab] || EncounterUpdatesTab;
const tabButtonClasses = (selected: boolean) =>
`capitalize min-w-max-content cursor-pointer font-bold whitespace-nowrap ${
diff --git a/src/pages/Encounters/PrintPrescription.tsx b/src/pages/Encounters/PrintPrescription.tsx
index b5f8f8ec4e6..3e7225a6dfb 100644
--- a/src/pages/Encounters/PrintPrescription.tsx
+++ b/src/pages/Encounters/PrintPrescription.tsx
@@ -194,10 +194,10 @@ export const PrintPrescription = (props: {
{Array.from(usedFrequencies).map((key) => (
- {FREQUENCY_DISPLAY[key].code}
+ {FREQUENCY_DISPLAY[key]?.code}
- = {FREQUENCY_DISPLAY[key].meaning}
+ = {FREQUENCY_DISPLAY[key]?.meaning}
))}
diff --git a/src/pages/Encounters/tabs/EncounterNotesTab.tsx b/src/pages/Encounters/tabs/EncounterNotesTab.tsx
index d8a93b592c5..8cb2b176d3c 100644
--- a/src/pages/Encounters/tabs/EncounterNotesTab.tsx
+++ b/src/pages/Encounters/tabs/EncounterNotesTab.tsx
@@ -330,7 +330,11 @@ export const EncounterNotesTab = ({ encounter }: EncounterTabProps) => {
// Auto-select first thread
useEffect(() => {
- if (threadsData?.results.length && !selectedThread) {
+ if (
+ threadsData?.results.length &&
+ threadsData.results[0] &&
+ !selectedThread
+ ) {
setSelectedThread(threadsData.results[0].id);
}
}, [threadsData, selectedThread]);
diff --git a/src/pages/Encounters/tabs/EncounterPlotsTab.tsx b/src/pages/Encounters/tabs/EncounterPlotsTab.tsx
index cc9c6d57689..b039dfc342c 100644
--- a/src/pages/Encounters/tabs/EncounterPlotsTab.tsx
+++ b/src/pages/Encounters/tabs/EncounterPlotsTab.tsx
@@ -30,7 +30,7 @@ export const EncounterPlotsTab = (props: EncounterTabProps) => {
return
;
}
- const currentTabId = qParams.plot || data[0].id;
+ const currentTabId = qParams.plot || data[0]?.id;
const currentTab = data.find((tab) => tab.id === currentTabId);
if (!currentTab) {
diff --git a/src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx b/src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx
index b9c32974a82..5267da41a1c 100644
--- a/src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx
+++ b/src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx
@@ -100,8 +100,10 @@ export default function FacilityOrganizationSelector(
setSelectedLevels(newLevels);
if (newLevels.length > 0) {
const lastOrg = newLevels[newLevels.length - 1];
- setSelectedOrganization(lastOrg);
- onChange(lastOrg.id);
+ if (lastOrg) {
+ setSelectedOrganization(lastOrg);
+ onChange(lastOrg.id);
+ }
} else {
setSelectedOrganization(null);
}
diff --git a/src/pages/Scheduling/ScheduleTemplates.tsx b/src/pages/Scheduling/ScheduleTemplates.tsx
index 5d32b332910..7877efbf3a0 100644
--- a/src/pages/Scheduling/ScheduleTemplates.tsx
+++ b/src/pages/Scheduling/ScheduleTemplates.tsx
@@ -125,13 +125,14 @@ const ScheduleTemplateItem = ({
<>
|
- {Math.floor(
- getSlotsPerSession(
- slot.availability[0].start_time,
- slot.availability[0].end_time,
- slot.slot_size_in_minutes,
- ) ?? 0,
- )}{" "}
+ {slot.availability[0] &&
+ Math.floor(
+ getSlotsPerSession(
+ slot.availability[0].start_time,
+ slot.availability[0].end_time,
+ slot.slot_size_in_minutes,
+ ) ?? 0,
+ )}{" "}
slots of {slot.slot_size_in_minutes} mins.
>
diff --git a/src/pages/Scheduling/components/EditScheduleTemplateSheet.tsx b/src/pages/Scheduling/components/EditScheduleTemplateSheet.tsx
index cd8b01d7020..0e55eef5bbc 100644
--- a/src/pages/Scheduling/components/EditScheduleTemplateSheet.tsx
+++ b/src/pages/Scheduling/components/EditScheduleTemplateSheet.tsx
@@ -330,13 +330,15 @@ const AvailabilityEditor = ({
if (availability.slot_type !== "appointment")
return { totalSlots: null, tokenDuration: null };
- const slots = Math.floor(
- getSlotsPerSession(
- availability.availability[0].start_time,
- availability.availability[0].end_time,
- availability.slot_size_in_minutes,
- ) ?? 0,
- );
+ const slots =
+ availability.availability[0] &&
+ Math.floor(
+ getSlotsPerSession(
+ availability.availability[0].start_time,
+ availability.availability[0].end_time,
+ availability.slot_size_in_minutes,
+ ) ?? 0,
+ );
const duration = getTokenDuration(
availability.slot_size_in_minutes,
@@ -432,19 +434,24 @@ const AvailabilityEditor = ({
{t("schedule")}
- {Object.entries(availabilitiesByDay).map(([day, times]) => (
-
-
- {DayOfWeek[parseInt(day)].charAt(0) +
- DayOfWeek[parseInt(day)].slice(1).toLowerCase()}
-
-
- {times
- .map((time) => formatAvailabilityTime([time]))
- .join(", ")}
-
-
- ))}
+ {Object.entries(availabilitiesByDay).map(([day, times]) => {
+ const dayofWeek = DayOfWeek[parseInt(day)];
+ if (!dayofWeek) return;
+ const formattedDay =
+ dayofWeek?.charAt(0) + dayofWeek?.slice(1).toLowerCase();
+ return (
+
+
+ {formattedDay}
+
+
+ {times
+ .map((time) => formatAvailabilityTime([time]))
+ .join(", ")}
+
+
+ );
+ })}