{(() => {
@@ -77,11 +87,13 @@ export const SuppliersTable = () => {
labelData={label}
columnsOrder={order}
rowsPerPage={10}
- filterColumns={filters}
isCollapsabile={true}
+ onEdit={handleEdit}
+ filterColumns={filters}
showEmptyCell={false}
rowKey="name"
manualFilter={false}
+ headerActions={headerActions}
/>
);
case "SUCCESS_EMPTY":
diff --git a/src/components/activities/adminActivity/AdminActivity.module.scss b/src/components/activities/adminActivity/AdminActivity.module.scss
index 5429b4de6..22d4f3937 100644
--- a/src/components/activities/adminActivity/AdminActivity.module.scss
+++ b/src/components/activities/adminActivity/AdminActivity.module.scss
@@ -14,7 +14,7 @@
border-radius: 8px;
flex-grow: 1;
margin: 30px 160px;
- align-self: center;
+ // align-self: center;
@include susy-media($medium-down) {
flex-direction: column;
margin: 20px 20px;
diff --git a/src/consts.ts b/src/consts.ts
index 63e5fcb2c..71c5b493c 100644
--- a/src/consts.ts
+++ b/src/consts.ts
@@ -24,6 +24,11 @@ export const PATHS = {
diseases: "/admin/diseases",
diseases_new: "/admin/diseases/new",
diseases_edit: "/admin/diseases/#id/edit",
+ operations: "/admin/operations",
+ operations_edit: "/admin/operations/#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_new: "/admin/operations/new",
diff --git a/src/mockServer/routes/suppliers.js b/src/mockServer/routes/suppliers.js
index 0645c9787..be3f9f0ce 100644
--- a/src/mockServer/routes/suppliers.js
+++ b/src/mockServer/routes/suppliers.js
@@ -5,5 +5,26 @@ export const suppliersRoutes = (server) => {
server.get("/").intercept((req, res) => {
res.status(200).json(supplierDTO);
});
+ server.post("/").intercept((req, res) => {
+ let body = req.jsonBody();
+ switch (body.supId) {
+ case "FAIL":
+ res.status(400).json({ message: "Fail to create supplier" });
+ break;
+ default:
+ body.supId = 100;
+ res.status(200).json(body);
+ }
+ });
+ server.put("/").intercept((req, res) => {
+ const body = req.jsonBody();
+ switch (body.supId) {
+ case "FAIL":
+ res.status(400).json({ message: "Fail to update supplier" });
+ break;
+ default:
+ res.status(200).json(body);
+ }
+ });
});
}
\ No newline at end of file
diff --git a/src/resources/i18n/en.json b/src/resources/i18n/en.json
index d8cb94763..155bc550a 100644
--- a/src/resources/i18n/en.json
+++ b/src/resources/i18n/en.json
@@ -823,13 +823,23 @@
"defaultResult": "Default value"
},
"supplier": {
+ "id": "Supplier ID",
"name": "Name",
"address": "Address",
"taxcode": "Tax Number ID",
"phone": "Phone number",
"fax": "Fax",
"email": "Email Address",
- "note": "Note"
+ "note": "Note",
+ "addNewSupplier": "Add a new supplier",
+ "editSupplier": "Edit supplier",
+ "updateSupplier": "Save changes",
+ "saveSupplier": "Save",
+ "addSupplier": "New supplier",
+ "updated": "Supplier updated",
+ "updateSuccess": "Supplier has been updated successfully!",
+ "created": "Supplier created",
+ "createSuccess": "Supplier has been created successfully!"
},
"ward": {
"code": "Code",
diff --git a/src/routes/Admin/AdminRoutes.tsx b/src/routes/Admin/AdminRoutes.tsx
index 3052a0643..4a4e2ffa8 100644
--- a/src/routes/Admin/AdminRoutes.tsx
+++ b/src/routes/Admin/AdminRoutes.tsx
@@ -17,6 +17,8 @@ import {
EditOperation,
Suppliers,
} from "../../components/accessories/admin";
+import { NewSupplier } from "../../components/accessories/admin/suppliers/newSupplier";
+import { EditSupplier } from "../../components/accessories/admin/suppliers/editSupplier";
export const AdminRoutes = () => {
const { t } = useTranslation();
@@ -106,6 +108,24 @@ export const AdminRoutes = () => {
/>
),
},
+ {
+ path: "suppliers/new",
+ element: (
+
}
+ />
+ ),
+ },
+ {
+ path: "suppliers/:id/edit",
+ element: (
+
}
+ />
+ ),
+ },
{
path: "users",
element: (
diff --git a/src/state/suppliers/actions.ts b/src/state/suppliers/actions.ts
index 5f03a0b26..8f5236400 100644
--- a/src/state/suppliers/actions.ts
+++ b/src/state/suppliers/actions.ts
@@ -3,9 +3,17 @@ import { Dispatch } from "redux";
import { customConfiguration } from "../../libraries/apiUtils/configuration";
import { IAction } from "../types";
import {
+ CREATE_SUPPLIER_FAIL,
+ CREATE_SUPPLIER_LOADING,
+ CREATE_SUPPLIER_RESET,
+ CREATE_SUPPLIER_SUCCESS,
GET_SUPPLIERS_FAIL,
GET_SUPPLIERS_LOADING,
GET_SUPPLIERS_SUCCESS,
+ UPDATE_SUPPLIER_FAIL,
+ UPDATE_SUPPLIER_LOADING,
+ UPDATE_SUPPLIER_RESET,
+ UPDATE_SUPPLIER_SUCCESS,
} from "./consts";
import { SupplierDTO, SuppliersApi } from "../../generated";
@@ -39,3 +47,63 @@ export const getSuppliers =
}
);
};
+
+export const createSupplier =
+ (supplierDTO: SupplierDTO) =>
+ (dispatch: Dispatch
>): void => {
+ dispatch({
+ type: CREATE_SUPPLIER_LOADING,
+ });
+ suppliersApi.saveSupplier({ supplierDTO }).subscribe(
+ (payload) => {
+ dispatch({
+ type: CREATE_SUPPLIER_SUCCESS,
+ payload: payload,
+ });
+ },
+ (error) => {
+ dispatch({
+ type: CREATE_SUPPLIER_FAIL,
+ error: error?.response,
+ });
+ }
+ );
+ };
+
+export const updateSupplier =
+ (supplierDTO: SupplierDTO) =>
+ (dispatch: Dispatch>): void => {
+ dispatch({
+ type: UPDATE_SUPPLIER_LOADING,
+ });
+ suppliersApi.updateSupplier({ supplierDTO }).subscribe(
+ (payload) => {
+ dispatch({
+ type: UPDATE_SUPPLIER_SUCCESS,
+ payload: payload,
+ });
+ },
+ (error) => {
+ dispatch({
+ type: UPDATE_SUPPLIER_FAIL,
+ error: error?.response,
+ });
+ }
+ );
+ };
+
+export const createSupplierReset =
+ () =>
+ (dispatch: Dispatch>): void => {
+ dispatch({
+ type: CREATE_SUPPLIER_RESET,
+ });
+ };
+
+export const updateSupplierReset =
+ () =>
+ (dispatch: Dispatch>): void => {
+ dispatch({
+ type: UPDATE_SUPPLIER_RESET,
+ });
+ };
diff --git a/src/state/suppliers/consts.ts b/src/state/suppliers/consts.ts
index 3899674dc..448373163 100644
--- a/src/state/suppliers/consts.ts
+++ b/src/state/suppliers/consts.ts
@@ -1,3 +1,13 @@
export const GET_SUPPLIERS_LOADING = "suppliers/GET_SUPPLIERS_LOADING";
export const GET_SUPPLIERS_SUCCESS = "suppliers/GET_SUPPLIERS_SUCCESS";
export const GET_SUPPLIERS_FAIL = "suppliers/GET_SUPPLIERS_FAIL";
+
+export const CREATE_SUPPLIER_LOADING = "suppliers/CREATE_SUPPLIER_LOADING";
+export const CREATE_SUPPLIER_SUCCESS = "suppliers/CREATE_SUPPLIER_SUCCESS";
+export const CREATE_SUPPLIER_FAIL = "suppliers/CREATE_SUPPLIER_FAIL";
+export const CREATE_SUPPLIER_RESET = "suppliers/CREATE_SUPPLIER_RESET";
+
+export const UPDATE_SUPPLIER_LOADING = "suppliers/UPDATE_SUPPLIER_LOADING";
+export const UPDATE_SUPPLIER_SUCCESS = "suppliers/UPDATE_SUPPLIER_SUCCESS";
+export const UPDATE_SUPPLIER_FAIL = "suppliers/UPDATE_SUPPLIER_FAIL";
+export const UPDATE_SUPPLIER_RESET = "suppliers/UPDATE_SUPPLIER_RESET";
diff --git a/src/state/suppliers/initial.ts b/src/state/suppliers/initial.ts
index ed5e9e801..894f45168 100644
--- a/src/state/suppliers/initial.ts
+++ b/src/state/suppliers/initial.ts
@@ -2,6 +2,9 @@ import { ISupplierState } from "./types";
import { ApiResponse } from "../types";
export const initial: ISupplierState = {
+ create: new ApiResponse({ status: "IDLE" }),
+ update: new ApiResponse({ status: "IDLE" }),
+ delete: new ApiResponse({ status: "IDLE" }),
supplierList: new ApiResponse({
status: "IDLE",
data: [],
diff --git a/src/state/suppliers/reducer.ts b/src/state/suppliers/reducer.ts
index 85900eb35..b6245954d 100644
--- a/src/state/suppliers/reducer.ts
+++ b/src/state/suppliers/reducer.ts
@@ -1,9 +1,17 @@
import produce from "immer";
import { IAction } from "../types";
import {
+ CREATE_SUPPLIER_FAIL,
+ CREATE_SUPPLIER_LOADING,
+ CREATE_SUPPLIER_RESET,
+ CREATE_SUPPLIER_SUCCESS,
GET_SUPPLIERS_FAIL,
GET_SUPPLIERS_LOADING,
GET_SUPPLIERS_SUCCESS,
+ UPDATE_SUPPLIER_FAIL,
+ UPDATE_SUPPLIER_LOADING,
+ UPDATE_SUPPLIER_RESET,
+ UPDATE_SUPPLIER_SUCCESS,
} from "./consts";
import { initial } from "./initial";
import { ISupplierState } from "./types";
@@ -11,7 +19,7 @@ import { ISupplierState } from "./types";
export default produce((draft: ISupplierState, action: IAction) => {
switch (action.type) {
/**
- * GET_EXAMS
+ * GET_SUPPLIERS
*/
case GET_SUPPLIERS_LOADING: {
draft.supplierList.status = "LOADING";
@@ -30,5 +38,61 @@ export default produce((draft: ISupplierState, action: IAction) => {
draft.supplierList.error = action.error;
break;
}
+
+ /**
+ * CREATE_SUPPLIER
+ */
+ case CREATE_SUPPLIER_LOADING: {
+ draft.create.status = "LOADING";
+ break;
+ }
+
+ case CREATE_SUPPLIER_SUCCESS: {
+ draft.create.status = "SUCCESS";
+ draft.create.data = action.payload;
+ delete draft.create.error;
+ break;
+ }
+
+ case CREATE_SUPPLIER_FAIL: {
+ draft.create.status = "FAIL";
+ draft.create.error = action.error;
+ break;
+ }
+
+ case CREATE_SUPPLIER_RESET: {
+ draft.create.status = "IDLE";
+ delete draft.create.error;
+ delete draft.create.data;
+ break;
+ }
+
+ /**
+ * UPDATE_SUPPLIER
+ */
+ case UPDATE_SUPPLIER_LOADING: {
+ draft.update.status = "LOADING";
+ break;
+ }
+
+ case UPDATE_SUPPLIER_SUCCESS: {
+ draft.update.status = "SUCCESS";
+ draft.update.data = action.payload;
+ delete draft.update.error;
+ break;
+ }
+
+ case UPDATE_SUPPLIER_FAIL: {
+ draft.update.status = "FAIL";
+ draft.update.error = action.error;
+ break;
+ }
+
+ case UPDATE_SUPPLIER_RESET: {
+ draft.update.status = "IDLE";
+ delete draft.update.error;
+ delete draft.update.data;
+ break;
+ }
}
}, initial);
diff --git a/src/state/suppliers/types.ts b/src/state/suppliers/types.ts
index cbb043fbb..bc9e2ae7a 100644
--- a/src/state/suppliers/types.ts
+++ b/src/state/suppliers/types.ts
@@ -3,4 +3,7 @@ import { ApiResponse } from "../types";
export type ISupplierState = {
supplierList: ApiResponse>;
+ create: ApiResponse;
+ update: ApiResponse;
+ delete: ApiResponse;
};