Skip to content

Commit

Permalink
OH2-309 | Minor bugs fix (#599)
Browse files Browse the repository at this point in the history
* fix(OH2-309): Fix admin activity navigation

* fix: Fix admin edit routes param

* fix: Fix admin edit routes

* update: Send lock when updating entities

* fix: Add full type object in disease and operation payload

---------

Co-authored-by: SteveGT96 <[email protected]>
  • Loading branch information
SteveGT96 and SteveGT96 authored Jun 6, 2024
1 parent 774128e commit 8a8e0b6
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/components/accessories/admin/diseases/Diseases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Diseases = () => {
}, [dispatch]);

const handleEdit = (row: DiseaseDTO) => {
navigate(PATHS.admin_diseases_edit.replace("#id", row.code!), {
navigate(PATHS.admin_diseases_edit.replace(":id", row.code!), {
state: row,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ const DiseaseForm: FC<IDiseaseProps> = ({
enableReinitialize: true,
onSubmit: (values) => {
const formattedValues = formatAllFieldValues(fields, values);
formattedValues.diseaseType = diseasesTypeState.data?.find(
(item) => item.code === values.diseaseType
);
onSubmit(formattedValues as any);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const DiseaseTable: FunctionComponent<IOwnProps> = ({
) : (
""
),
lock: item.lock,
};
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const EditDisease = () => {
);

const handleSubmit = (value: DiseaseDTO) => {
dispatch(updateDisease(value));
dispatch(updateDisease({ ...value, lock: state?.lock }));
};

if (state?.code?.toString() !== id?.toString()) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/accessories/admin/operations/Operations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const Operations = () => {
}, [dispatch]);

const handleEdit = (row: OperationDTO) => {
navigate(PATHS.admin_operations_edit.replace("#id", row.code!), {
navigate(PATHS.admin_operations_edit.replace(":id", row.code!), {
state: row,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export const EditOperation = () => {
);

const handleSubmit = (value: OperationDTO) => {
dispatch(updateOperation({ code: id ?? "", operationDTO: value }));
dispatch(
updateOperation({
code: id ?? "",
operationDTO: { ...value, lock: state?.lock },
})
);
};

if (state?.code !== id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ const OperationForm: FC<IOperationProps> = ({
enableReinitialize: true,
onSubmit: (values) => {
const formattedValues = formatAllFieldValues(fields, values);
formattedValues.type = operationsTypeState.data?.find(
(item) => item.code === values.type
);
onSubmit(formattedValues as any);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const OperationTable: FunctionComponent<IOwnProps> = ({
item.major === 0
? t("operation.classes.minor")
: t("operation.classes.major"),
lock: item.lock,
};
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/accessories/admin/wards/Wards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const Wards = () => {
}, [dispatch]);

const handleEdit = (row: WardDTO) => {
navigate(PATHS.admin_wards_edit.replace("#id", row.code!), { state: row });
navigate(PATHS.admin_wards_edit.replace(":id", row.code!), { state: row });
};

const handleDelete = (row: WardDTO) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const EditWard = () => {
);

const handleSubmit = (value: WardDTO) => {
dispatch(updateWard(value));
dispatch(updateWard({ ...value, lock: state?.lock }));
};

if (state?.code?.toString() !== id?.toString()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const WardTable: FunctionComponent<IOwnProps> = ({
telephone: item.telephone ?? "",
fax: item.fax ?? "",
visitDuration: item.visitDuration ?? "",
lock: item.lock,
};
});
};
Expand Down
11 changes: 7 additions & 4 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ export const PATHS = {
visits: "/visits",
laboratory: "/laboratory",
laboratory_new: "/laboratory/new",
laboratory_edit: "/laboratory/#id/edit",
laboratory_edit: "/laboratory/:id/edit",
dashboard: "/dashboard",
admin: "/admin",
admin_users: "/admin/users",
admin_types: "/admin/types",
admin_vaccines: "/admin/vaccines",
admin_wards: "/admin/wards",
admin_wards_new: "/admin/wards/new",
admin_wards_edit: "/admin/wards/#id/edit",
admin_wards_edit: "/admin/wards/:id/edit",
admin_diseases: "/admin/diseases",
admin_diseases_new: "/admin/diseases/new",
admin_diseases_edit: "/admin/diseases/#id/edit",
admin_diseases_edit: "/admin/diseases/:id/edit",
admin_suppliers: "/admin/suppliers",
admin_suppliers_new: "/admin/suppliers/new",
admin_suppliers_edit: "/admin/suppliers/:id/edit",
admin_operations: "/admin/operations",
admin_operations_edit: "/admin/operations/#id/edit",
admin_operations_edit: "/admin/operations/:id/edit",
admin_operations_new: "/admin/operations/new",
};
36 changes: 20 additions & 16 deletions src/routes/Admin/AdminRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ import { EditSupplier } from "../../components/accessories/admin/suppliers/editS

export const AdminRoutes = () => {
const { t } = useTranslation();
const getPath = (from: string) => from.replace(`${PATHS.admin}/`, "");
const routes: { element: ReactNode; path: string }[] = useMemo(
() => [
{
path: PATHS.admin_wards,
path: getPath(PATHS.admin_wards),
element: (
<AdminActivityContent title={t("nav.wards")} children={<Wards />} />
),
},
{
path: PATHS.admin_wards_new,
path: getPath(PATHS.admin_wards_new),
element: (
<AdminActivityContent
title={t("ward.addWard")}
Expand All @@ -43,7 +44,7 @@ export const AdminRoutes = () => {
),
},
{
path: PATHS.admin_wards_edit,
path: getPath(PATHS.admin_wards_edit),
element: (
<AdminActivityContent
title={t("ward.editWard")}
Expand All @@ -52,7 +53,7 @@ export const AdminRoutes = () => {
),
},
{
path: PATHS.admin_diseases,
path: getPath(PATHS.admin_diseases),
element: (
<AdminActivityContent
title={t("nav.diseases")}
Expand All @@ -61,7 +62,7 @@ export const AdminRoutes = () => {
),
},
{
path: PATHS.admin_diseases_new,
path: getPath(PATHS.admin_diseases_new),
element: (
<AdminActivityContent
title={t("disease.addDisease")}
Expand All @@ -70,7 +71,7 @@ export const AdminRoutes = () => {
),
},
{
path: PATHS.admin_diseases_edit,
path: getPath(PATHS.admin_diseases_edit),
element: (
<AdminActivityContent
title={t("disease.editDisease")}
Expand All @@ -85,7 +86,7 @@ export const AdminRoutes = () => {
),
},
{
path: PATHS.admin_operations,
path: getPath(PATHS.admin_operations),
element: (
<AdminActivityContent
title={t("nav.operations")}
Expand All @@ -94,7 +95,7 @@ export const AdminRoutes = () => {
),
},
{
path: PATHS.admin_operations_new,
path: getPath(PATHS.admin_operations_new),
element: (
<AdminActivityContent
title={t("operation.addOperation")}
Expand All @@ -103,7 +104,7 @@ export const AdminRoutes = () => {
),
},
{
path: PATHS.admin_operations_edit,
path: getPath(PATHS.admin_operations_edit),
element: (
<AdminActivityContent
title={t("operation.editOperation")}
Expand All @@ -112,7 +113,7 @@ export const AdminRoutes = () => {
),
},
{
path: "vaccines",
path: getPath(PATHS.admin_vaccines),
element: (
<AdminActivityContent
title={t("nav.vaccines")}
Expand All @@ -121,7 +122,7 @@ export const AdminRoutes = () => {
),
},
{
path: "suppliers",
path: getPath(PATHS.admin_suppliers),
element: (
<AdminActivityContent
title={t("nav.suppliers")}
Expand All @@ -130,7 +131,7 @@ export const AdminRoutes = () => {
),
},
{
path: "suppliers/new",
path: getPath(PATHS.admin_suppliers_new),
element: (
<AdminActivityContent
title={t("supplier.addNewSupplier")}
Expand All @@ -139,7 +140,7 @@ export const AdminRoutes = () => {
),
},
{
path: "suppliers/:id/edit",
path: getPath(PATHS.admin_suppliers_edit),
element: (
<AdminActivityContent
title={t("supplier.editSupplier")}
Expand All @@ -148,13 +149,13 @@ export const AdminRoutes = () => {
),
},
{
path: "users",
path: getPath(PATHS.admin_users),
element: (
<AdminActivityContent title={t("nav.users")} children={<Users />} />
),
},
{
path: "types",
path: getPath(PATHS.admin_types),
element: (
<AdminActivityContent title={t("nav.types")} children={<Wards />} />
),
Expand All @@ -165,7 +166,10 @@ export const AdminRoutes = () => {
return (
<Routes>
<Route element={<AdminActivity />}>
<Route index element={<Navigate to="wards" replace />} />
<Route
index
element={<Navigate to={getPath(PATHS.admin_wards)} replace />}
/>
{routes.map((route) => (
<Route key={route.path} path={route.path} element={route.element} />
))}
Expand Down

0 comments on commit 8a8e0b6

Please sign in to comment.