Skip to content

Commit

Permalink
fix:eslint warings - unused imports, exhaustive deps, ...
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverD3 committed Oct 3, 2024
1 parent 3567635 commit 207137e
Show file tree
Hide file tree
Showing 94 changed files with 343 additions and 419 deletions.
3 changes: 1 addition & 2 deletions src/components/Private.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from "react";
import { Navigate, Outlet, useLocation } from "react-router-dom";
import { Navigate, Outlet } from "react-router-dom";
import { PATHS } from "../consts";
import { isAuthenticated } from "../libraries/authUtils/isAuthenticated";
import { useAuthentication } from "../libraries/authUtils/useAuthentication";

export const Private = () => {
useAuthentication();
const { pathname } = useLocation();

return isAuthenticated() ? <Outlet /> : <Navigate to={PATHS.login} replace />;
};
13 changes: 5 additions & 8 deletions src/components/accessories/admin/diseases/Diseases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ export const Diseases = () => {
});
};

const handleViewChange = useCallback(
(event: any, value: any) => {
if (!isEmpty(value)) {
setView(value);
}
},
[view]
);
const handleViewChange = useCallback((event: any, value: any) => {
if (!isEmpty(value)) {
setView(value);
}
}, []);

const predicate = useCallback(
(disease: DiseaseDTO) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const EditSupplier = () => {
if (state?.supId !== Number(id)) {
navigate(PATHS.admin_suppliers);
}
}, [id, state]);
}, [id, navigate, state]);

return (
<SupplierForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import TextField from "../../../textField/TextField";
import "./styles.scss";
import { ISupplierFormProps } from "./types";

const FORMAT = /^([0-9]{3})?[0-9]{2,10}$/;

const SupplierForm: FC<ISupplierFormProps> = ({
fields,
onSubmit,
Expand Down
10 changes: 7 additions & 3 deletions src/components/accessories/admin/types/TypesAdmin.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useAppSelector } from "libraries/hooks/redux";
import { sortBy } from "lodash";
import React, { useEffect, useState } from "react";
import React, { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { Outlet, useLocation, useNavigate } from "react-router";
import { PATHS } from "../../../../consts";
Expand All @@ -16,7 +16,11 @@ const TypesAdmin = () => {
const { t } = useTranslation();
const location = useLocation();
const navigate = useNavigate();
const defaultTypeOption: TypeOption = { label: "", value: "" };
const defaultTypeOption: TypeOption = useMemo(
() => ({ label: "", value: "" }),
[]
);

const [selectedOption, setSelectedOption] =
useState<TypeOption>(defaultTypeOption);
const mode = useAppSelector((state) => state.types.config.mode);
Expand Down Expand Up @@ -57,7 +61,7 @@ const TypesAdmin = () => {
setSelectedOption(defaultTypeOption);
}
}
}, [location]);
}, [defaultTypeOption, location, typeOptions]);

const handleTypeChange = (value: string) => {
if (value?.length > 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/accessories/admission/PatientAdmission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const PatientAdmission: FC = () => {
if (patientCode && creationMode) {
dispatch(getLastOpd(parseInt(id!!)));
}
}, [dispatch, patientCode, creationMode]);
}, [dispatch, patientCode, creationMode, id]);

const fields = useFields(admissionToEdit, lastOpd?.disease);

Expand Down Expand Up @@ -157,7 +157,7 @@ const PatientAdmission: FC = () => {
dispatch(getPatient(id!!));
dispatch(getCurrentAdmission(parseInt(id!!)));
}
}, [createStatus, updateStatus]);
}, [createStatus, dispatch, id, updateStatus]);

const resetFormCallback = () => {
setCreationMode(true);
Expand All @@ -173,7 +173,7 @@ const PatientAdmission: FC = () => {
return () => {
dispatch(getCurrentAdmissionReset());
};
}, [dispatch]);
}, [dispatch, id]);

const onEdit = (row: AdmissionDTO) => {
setAdmissionToEdit(row);
Expand Down
2 changes: 1 addition & 1 deletion src/components/accessories/appHeader/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const AppHeader: FunctionComponent<IOwnProps> = ({ breadcrumbMap }) => {
);
useEffect(() => {
dispatch(getHospital());
}, [dispatch, getHospital]);
}, [dispatch]);

const hospital = useAppSelector(
(state) => state.hospital.getHospital.data
Expand Down
1 change: 0 additions & 1 deletion src/components/accessories/appHeader/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TUserCredentials } from "../../../state/main/types";
import { TAPIResponseStatus } from "../../../state/types";

export type TBreadcrumbMap = Record<string, string>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import _ from "lodash";
import React, {
ChangeEvent,
FC,
Fragment,
useCallback,
useEffect,
useState,
Expand Down Expand Up @@ -76,6 +75,7 @@ const AutocompleteField: FC<IProps> = ({
}
};

// eslint-disable-next-line react-hooks/exhaustive-deps
const debounceUpdate = useCallback(
debounce((value: any) => {
setValue(value);
Expand Down Expand Up @@ -111,16 +111,6 @@ const AutocompleteField: FC<IProps> = ({
return option.label;
};

const isSelected = (option: DefaultOptionType, v: DefaultOptionType) => {
return option.value === v.value;
};

const rendOption = (props: any, option: DefaultOptionType | string) => {
return (
<Fragment>{typeof option === "string" ? option : option.label}</Fragment>
);
};

const filter = createFilterOptions<DefaultOptionType>({
limit: options_limit,
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/accessories/billTable/BillTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const BillTable: FC<IBillTableProps> = ({ fields }) => {
dispatch(searchBills(filter));
break;
}
}, [filter]);
}, [dispatch, filter]);

const { setFieldValue, handleBlur } = formik;

Expand Down
4 changes: 2 additions & 2 deletions src/components/accessories/billrecords/BillRecords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const BillRecords = () => {
dispatch(deleteBillReset());
dispatch(payBillReset());
dispatch(closeBillReset());
}, []);
}, [dispatch]);

useEffect(() => {
if (patient && patient.code) {
Expand Down Expand Up @@ -275,7 +275,7 @@ const BillRecords = () => {
}}
handleSecondaryButtonClick={() => ({})}
/>
<iframe id="ifmcontentstoprint"></iframe>
<iframe id="ifmcontentstoprint" title="ifmcontentstoprint"></iframe>
</div>
);
};
Expand Down
18 changes: 6 additions & 12 deletions src/components/accessories/billsRecap/BillsRecap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ import {
} from "chart.js";
import { useAppDispatch, useAppSelector } from "libraries/hooks/redux";
import moment from "moment";
import React, {
FC,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import React, { FC, useCallback, useEffect, useMemo, useState } from "react";
import { Bar, Doughnut, Line, Pie } from "react-chartjs-2";
import { useTranslation } from "react-i18next";
import { getBillsByYear, searchBills } from "../../../state/bills";
Expand Down Expand Up @@ -98,6 +91,7 @@ export const BillsRecap: FC = () => {

useEffect(() => {
dispatch(searchBills(filter as TFilterValues));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dispatch]);

useEffect(() => {
Expand Down Expand Up @@ -188,7 +182,7 @@ export const BillsRecap: FC = () => {
],
};
},
[summaryCurrentYear]
[summaryCurrentYear, t]
);

const paymentsVariationsData = useMemo(() => {
Expand All @@ -206,7 +200,7 @@ export const BillsRecap: FC = () => {
{
label: t("bill.payments"),
data:
labels.length != 0
labels.length !== 0
? labels.map(
(item) => summaryCurrentYear.paymentsByMonthsOfYear[item] ?? 0
)
Expand All @@ -217,7 +211,7 @@ export const BillsRecap: FC = () => {
{
label: t("bill.debts"),
data:
labels.length != 0
labels.length !== 0
? labels.map(
(item) => summaryCurrentYear.debtsByMonthsOfYear[item] ?? 0
)
Expand All @@ -227,6 +221,7 @@ export const BillsRecap: FC = () => {
},
],
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [summaryCurrentYear]);

const getOptionsFromYears = (years: number[]) => {
Expand All @@ -237,7 +232,6 @@ export const BillsRecap: FC = () => {
};
});
};
const infoBoxRef = useRef<HTMLDivElement>(null);

return (
<div className="bills__recap">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ import {
AdmissionTypeDTO,
DiseaseDTO,
DiseaseTypeDTO,
WardDTO
WardDTO,
} from "../../../../generated";
import {
differenceInDays,
formatAllFieldValues,
getFromFields
getFromFields,
} from "../../../../libraries/formDataHandling/functions";
import { updateAdmissionReset } from "../../../../state/admissions";
import {
getPatient
} from "../../../../state/patients";
import { getPatient } from "../../../../state/patients";
import { IState } from "../../../../types";
import AutocompleteField from "../../autocompleteField/AutocompleteField";
import Button from "../../button/Button";
Expand Down Expand Up @@ -130,9 +128,9 @@ export const CurrentAdmissionForm: FunctionComponent<IOwnProps> = ({
}
onDiscard();
}
}, [dispatch, activityTransitionState]);
}, [dispatch, activityTransitionState, patient, onDiscard]);

const { setFieldValue, resetForm, handleBlur } = formik;
const { setFieldValue, handleBlur } = formik;

const isValid = (fieldName: string): boolean => {
return has(formik.touched, fieldName) && has(formik.errors, fieldName);
Expand All @@ -154,7 +152,7 @@ export const CurrentAdmissionForm: FunctionComponent<IOwnProps> = ({
).toString();
setFieldValue("bedDays", days);
},
[setFieldValue]
[formik, setFieldValue]
);

const onBlurCallback = useCallback(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdmissionDTO, PatientDTO } from "../../../../generated";
import { AdmissionDTO } from "../../../../generated";
import { parseDate } from "../../../../libraries/formDataHandling/functions";
import { TFields } from "../../../../libraries/formDataHandling/types";
import { TCurrentAdmissionFieldName } from "./types";
Expand Down
11 changes: 1 addition & 10 deletions src/components/accessories/dashboard/admissions/useData.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useAppSelector } from "libraries/hooks/redux";
import {
AdmissionDTO,
WardDTO,
AdmissionTypeDTO,
AgeTypeDTO,
} from "../../../../generated";
import { useTranslation } from "react-i18next";
import { colorGen } from "../../../../libraries/uiUtils/colorGenerator";
import { TAPIResponseStatus } from "../../../../state/types";
import { IState } from "../../../../types";

export const useData = () => {
const { t } = useTranslation();
Expand Down
8 changes: 6 additions & 2 deletions src/components/accessories/dashboard/card/DashboardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ export const DashboardCard: React.FC<TDashboardCardProps> = ({
if (sizeChangeHandler && cardBodyRef.current) {
resizeObserver.observe(cardBodyRef.current);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [cardBodyRef]);

// Remove the observer on component unmount
useEffect(() => {
const currentRef = cardBodyRef.current;

return () => {
if (sizeChangeHandler && cardBodyRef.current) {
resizeObserver.unobserve(cardBodyRef.current);
if (sizeChangeHandler && currentRef) {
resizeObserver.unobserve(currentRef);
resizeObserver.disconnect();
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const getTitle = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const DashboardFilter: FC<IOwnProps> = ({ onPeriodChange }) => {

useEffect(() => {
onPeriodChange([range[0], range[1]]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [range]);

const handleViewChange = useCallback(
Expand All @@ -36,6 +37,7 @@ export const DashboardFilter: FC<IOwnProps> = ({ onPeriodChange }) => {
setSelection("current");
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[view]
);

Expand All @@ -45,7 +47,7 @@ export const DashboardFilter: FC<IOwnProps> = ({ onPeriodChange }) => {
setSelection(value as TPeriodType);
}
},
[selection]
[setSelection]
);

const onIconClickHandler = useCallback(
Expand All @@ -66,6 +68,7 @@ export const DashboardFilter: FC<IOwnProps> = ({ onPeriodChange }) => {
setSelection("custom");
setOpen(false);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[dateRange]
);

Expand All @@ -78,7 +81,7 @@ export const DashboardFilter: FC<IOwnProps> = ({ onPeriodChange }) => {
setSelection("custom");
setOpen(false);
},
[dateRange]
[setDateRange, setSelection, setView]
);

return (
Expand Down
Loading

0 comments on commit 207137e

Please sign in to comment.