diff --git a/src/index.ts b/src/index.ts index a5e7f0a6..7ca0d186 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,15 @@ export const deleteStockModal = getAsyncLifecycle( } ); +export const deleteUserScopeModal = getAsyncLifecycle( + () => + import("./stock-user-role-scopes/delete-stock-user-scope-modal.component"), + { + featureName: "delete-stock-user-scope-modal", + moduleName, + } +); + export const importBulkStockItemsDialog = getAsyncLifecycle( () => import( diff --git a/src/routes.json b/src/routes.json index 0638505e..02767cef 100644 --- a/src/routes.json +++ b/src/routes.json @@ -26,6 +26,10 @@ { "name": "delete-stock-modal", "component": "deleteStockModal" + }, + { + "name": "delete-stock-user-scope-modal", + "component": "deleteUserScopeModal" } ], "pages": [ diff --git a/src/stock-items/stock-items-table.component.tsx b/src/stock-items/stock-items-table.component.tsx index 348e3515..89b34cb7 100644 --- a/src/stock-items/stock-items-table.component.tsx +++ b/src/stock-items/stock-items-table.component.tsx @@ -94,7 +94,13 @@ const StockItemsTableComponent: React.FC = () => { return ( <> - Drugs and other stock items managed by the system. + + {t( + "panelDescription", + "Drugs and other stock items managed by the system." + )} + + = ({ labelText={operation?.hasDestination ? "From:" : "From:"} /> )} - {/* {(!canEdit || lockSource) && operation?.hasSource && ( - - )} */} - {canEdit && !lockDestination && operation?.hasDestination && ( = ({ labelText={operation?.hasSource ? "To:" : "To:"} /> )} - {/* {(!canEdit || lockDestination) && operation?.hasDestination && ( - - )} */} {canEdit && ( = () => { return (
- Stock operations to track movement of stock. + + {t("panelDescription", "Stock operations to track movement of stock.")} + +
diff --git a/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx b/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx index f991a747..e7069997 100644 --- a/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx +++ b/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx @@ -9,6 +9,7 @@ import { SelectItem, } from "@carbon/react"; import React, { ChangeEvent, useCallback, useState } from "react"; +import { handleMutate } from "../swr-revalidation"; import styles from "./add-stock-sources.scss"; import { useConceptById } from "../../stock-lookups/stock-lookups.resource"; import { STOCK_SOURCE_TYPE_CODED_CONCEPT_ID } from "../../constants"; @@ -65,6 +66,9 @@ const StockSourcesAddOrUpdate: React.FC = ({ model }) => { "Stock Source Added Successfully" ), }); + + handleMutate("ws/rest/v1/stockmanagement/stocksource"); + closeOverlay(); }, (error) => { diff --git a/src/stock-sources/stock-sources-delete/stock-sources-delete.component.tsx b/src/stock-sources/stock-sources-delete/stock-sources-delete.component.tsx index 62476bdc..f2449954 100644 --- a/src/stock-sources/stock-sources-delete/stock-sources-delete.component.tsx +++ b/src/stock-sources/stock-sources-delete/stock-sources-delete.component.tsx @@ -1,4 +1,5 @@ import React, { useState } from "react"; +import { handleMutate } from "../swr-revalidation"; import { Button, InlineLoading } from "@carbon/react"; import { useTranslation } from "react-i18next"; import { TrashCan } from "@carbon/react/icons"; @@ -27,6 +28,8 @@ const StockSourcesDeleteActionMenu: React.FC< .then( () => { setDeletingSource(false); + + handleMutate("ws/rest/v1/stockmanagement/stocksource"); showToast({ critical: true, title: t("deletingSource", "Delete Source"), diff --git a/src/stock-sources/stock-sources-items-table.component.tsx b/src/stock-sources/stock-sources-items-table.component.tsx index c9915723..ca2e470f 100644 --- a/src/stock-sources/stock-sources-items-table.component.tsx +++ b/src/stock-sources/stock-sources-items-table.component.tsx @@ -73,7 +73,12 @@ function StockSourcesItems() { return (
- List of partners who provide stock to the facility. + + {t( + "panelDescription", + "List of partners who provide stock to the facility." + )} +
diff --git a/src/stock-sources/swr-revalidation.ts b/src/stock-sources/swr-revalidation.ts new file mode 100644 index 00000000..c2ffcb45 --- /dev/null +++ b/src/stock-sources/swr-revalidation.ts @@ -0,0 +1,7 @@ +import { mutate } from "swr"; + +export const handleMutate = (url: string) => { + mutate((key) => typeof key === "string" && key.startsWith(url), undefined, { + revalidate: true, + }); +}; diff --git a/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx b/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx index 4ef8486b..f0d4f476 100644 --- a/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx +++ b/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx @@ -41,6 +41,7 @@ import { debounce } from "lodash-es"; import { User } from "../../core/api/types/identity/User"; import { Role } from "../../core/api/types/identity/Role"; import { StockOperationType } from "../../core/api/types/stockOperation/StockOperationType"; +import { handleMutate } from "../swr-revalidation"; const MinDate: Date = today(); @@ -247,6 +248,7 @@ const AddStockUserRoleScope: React.FC = ({ createOrUpdateUserRoleScope(formModel).then( (res) => { + handleMutate("ws/rest/v1/stockmanagement/userrolescope"); showToast({ critical: true, title: t("addUserRole", "Add User role"), diff --git a/src/stock-user-role-scopes/delete-stock-user-scope-modal.component.tsx b/src/stock-user-role-scopes/delete-stock-user-scope-modal.component.tsx new file mode 100644 index 00000000..c85d4fa7 --- /dev/null +++ b/src/stock-user-role-scopes/delete-stock-user-scope-modal.component.tsx @@ -0,0 +1,47 @@ +import React from "react"; +import { useTranslation } from "react-i18next"; +import { Button, ModalHeader, ModalBody, ModalFooter } from "@carbon/react"; +import styles from "../root.scss"; + +interface DeleteConfirmationProps { + uuid?: string; + close: () => void; + onConfirmation: () => void; +} + +const DeleteConfirmation: React.FC = ({ + close, + onConfirmation, + uuid, +}) => { + const { t } = useTranslation(); + const handleCancel = () => close(); + const handleDelete = () => onConfirmation?.(); + + return ( + <> + + {t("deleteStockUserScope", "Delete Stock User Scope")}? + + +

+ {t( + "deleteConfirmationText", + `Are you sure you want to delete this User Scope? This action can't be undone.`, + { encounter: uuid } + )} +

+
+ + + + + + ); +}; + +export default DeleteConfirmation; diff --git a/src/stock-user-role-scopes/delete-stock-user-scope/delete-stock-user-scope.component.tsx b/src/stock-user-role-scopes/delete-stock-user-scope/delete-stock-user-scope.component.tsx new file mode 100644 index 00000000..b1d44c07 --- /dev/null +++ b/src/stock-user-role-scopes/delete-stock-user-scope/delete-stock-user-scope.component.tsx @@ -0,0 +1,73 @@ +import React, { useState } from "react"; +import { Button, InlineLoading } from "@carbon/react"; +import { useTranslation } from "react-i18next"; +import { TrashCan } from "@carbon/react/icons"; +import { deleteUserRoleScopes } from "../stock-user-role-scopes.resource"; +import { showModal, showNotification, showToast } from "@openmrs/esm-framework"; +import { handleMutate } from "../swr-revalidation"; + +interface StockUserScopDeleteActionMenuProps { + uuid: string; +} + +const StockUserScopeDeleteActionMenu: React.FC< + StockUserScopDeleteActionMenuProps +> = ({ uuid }) => { + const { t } = useTranslation(); + + const [deletingUserScope, setDeletingUserScope] = useState(false); + + const handleDeleteStockUserScope = React.useCallback(() => { + const close = showModal("delete-stock-user-scope-modal", { + close: () => close(), + uuid: uuid, + onConfirmation: () => { + const ids = []; + ids.push(uuid); + deleteUserRoleScopes(ids) + .then( + () => { + handleMutate("ws/rest/v1/stockmanagement/userrolescope"); + setDeletingUserScope(false); + showToast({ + critical: true, + title: t("deletingstockUserScope", "Delete Stock User Scope"), + kind: "success", + description: t( + "stockuserscopedeletedsuccessfully", + "Stock User Scope Deleted Successfully" + ), + }); + }, + (error) => { + setDeletingUserScope(false); + showNotification({ + title: t( + `errorDeletingUserScope', 'error deleting a user scope` + ), + kind: "error", + critical: true, + description: error?.message, + }); + } + ) + .catch(); + close(); + }, + }); + }, [t, uuid]); + + const deleteButton = ( +