@openmrs/esm-stock-management-app 1.0.1-pre.469 → 1.0.1-pre.475

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. package/dist/474.js +1 -1
  2. package/dist/474.js.map +1 -1
  3. package/dist/main.js +1 -1
  4. package/dist/main.js.map +1 -1
  5. package/dist/openmrs-esm-stock-management-app.js.buildmanifest.json +6 -6
  6. package/dist/routes.json +1 -1
  7. package/package.json +1 -1
  8. package/src/core/utils/alert.ts +4 -4
  9. package/src/stock-items/add-bulk-stock-item/stock-items-bulk-import.component.tsx +9 -17
  10. package/src/stock-items/add-stock-item/packaging-units/packaging-units-delete-modal.component.tsx +7 -7
  11. package/src/stock-items/add-stock-item/stock-item-references/stock-item-references.component.tsx +3 -14
  12. package/src/stock-items/add-stock-item/stock-item-rules/add-stock-rules.component.tsx +11 -22
  13. package/src/stock-items/add-stock-item/stock-item-rules/stock-rules-delete.component.tsx +7 -7
  14. package/src/stock-items/stock-item.utils.tsx +7 -13
  15. package/src/stock-locations/add-locations-form.component.tsx +7 -7
  16. package/src/stock-locations/stock-locations-table.resource.tsx +11 -14
  17. package/src/stock-lookups/stock-lookups.resource.ts +7 -0
  18. package/src/stock-operations/add-stock-operation/add-stock-operation.component.tsx +1 -6
  19. package/src/stock-operations/add-stock-operation/add-stock-operation.utils.tsx +29 -61
  20. package/src/stock-operations/stock-operation.utils.tsx +7 -8
  21. package/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx +8 -12
  22. package/src/stock-sources/stock-sources-delete/stock-sources-delete.component.tsx +7 -12
  23. package/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx +20 -73
  24. package/src/stock-user-role-scopes/delete-stock-user-scope/delete-stock-user-scope.component.tsx +7 -12
  25. package/src/utils.ts +4 -4
@@ -86,10 +86,10 @@
86
86
  "initial": true,
87
87
  "entry": true,
88
88
  "recorded": false,
89
- "size": 4770073,
89
+ "size": 4767329,
90
90
  "sizes": {
91
91
  "consume-shared": 252,
92
- "javascript": 4748124,
92
+ "javascript": 4745380,
93
93
  "share-init": 252,
94
94
  "runtime": 21445
95
95
  },
@@ -106,7 +106,7 @@
106
106
  "auxiliaryFiles": [
107
107
  "main.js.map"
108
108
  ],
109
- "hash": "4584f840c7b06eb6",
109
+ "hash": "2dd0d0b605a58141",
110
110
  "childrenByOrder": {}
111
111
  },
112
112
  {
@@ -138,9 +138,9 @@
138
138
  "initial": false,
139
139
  "entry": false,
140
140
  "recorded": false,
141
- "size": 1098361,
141
+ "size": 1095617,
142
142
  "sizes": {
143
- "javascript": 1098151,
143
+ "javascript": 1095407,
144
144
  "consume-shared": 210
145
145
  },
146
146
  "names": [],
@@ -154,7 +154,7 @@
154
154
  "auxiliaryFiles": [
155
155
  "474.js.map"
156
156
  ],
157
- "hash": "3d31f10ff5724cc8",
157
+ "hash": "d3138f8f9dbb47a0",
158
158
  "childrenByOrder": {}
159
159
  },
160
160
  {
package/dist/routes.json CHANGED
@@ -1 +1 @@
1
- {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.24.0"},"extensions":[{"name":"stock-nav-menu","slot":"stock-sidebar-slot","component":"stockNavMenu","online":true,"offline":true},{"name":"overview-db-link","slot":"stock-page-dashboard-slot","component":"stockOverviewLink","meta":{"name":"overview","slot":"overview-dashboard-slot","title":"overview"},"order":0,"online":true,"offline":true},{"name":"stock-overview-db","slot":"overview-dashboard-slot","component":"stockOverview"},{"name":"operations-db-link","slot":"stock-page-dashboard-slot","component":"stockOperationsLink","meta":{"name":"operations","slot":"operations-dashboard-slot","title":"operations"},"order":2,"online":true,"offline":true},{"name":"stock-operations-db","slot":"operations-dashboard-slot","component":"stockOperations"},{"name":"items-db-link","slot":"stock-page-dashboard-slot","component":"stockItemsLink","meta":{"name":"items","slot":"items-dashboard-slot","title":"items"},"order":1,"online":true,"offline":true},{"name":"stock-items-db","slot":"items-dashboard-slot","component":"stockItems"},{"name":"user-scopes-db-link","slot":"stock-page-dashboard-slot","component":"stockUserScopesLink","meta":{"name":"user-scopes","slot":"user-scopes-dashboard-slot","title":"user-scopes"},"order":3,"online":true,"offline":true},{"name":"stock-user-scopes-db","slot":"user-scopes-dashboard-slot","component":"stockUserScopes"},{"name":"sources-db-link","slot":"stock-page-dashboard-slot","component":"stockSourcesLink","meta":{"name":"sources","slot":"sources-dashboard-slot","title":"Sources"},"order":2,"online":true,"offline":true},{"name":"stock-sources-db","slot":"sources-dashboard-slot","component":"stockSources"},{"name":"locations-db-link","slot":"stock-page-dashboard-slot","component":"stockLocationsLink","meta":{"name":"locations","slot":"locations-dashboard-slot","title":"Locations"},"order":4,"online":true,"offline":true},{"name":"stock-locations-db","slot":"locations-dashboard-slot","component":"stockLocations"},{"name":"reports-db-link","slot":"stock-page-dashboard-slot","component":"stockReportsLink","meta":{"name":"reports","slot":"reports-dashboard-slot","title":"Reports"},"order":5,"online":true,"offline":true},{"name":"stock-reports-db","slot":"reports-dashboard-slot","component":"stockReports"},{"name":"settings-db-link","slot":"stock-page-dashboard-slot","component":"stockSettingsLink","meta":{"name":"settings","slot":"settings-dashboard-slot","title":"Settings"},"order":6,"online":true,"offline":true},{"name":"stock-settings-db","slot":"settings-dashboard-slot","component":"stockSettings"},{"name":"stock-management-admin-card-link","slot":"system-admin-page-card-link-slot","component":"stockManagementAdminCardLink"},{"name":"stock-operation-dialog","component":"stockOperationDialog"},{"name":"import-bulk-stock-items","component":"importBulkStockItemsDialog"},{"name":"delete-stock-modal","component":"deleteStockModal"},{"name":"delete-stock-user-scope-modal","component":"deleteUserScopeModal"},{"name":"stock-management-app-menu-item","component":"stockManagementAppMenuItem","slot":"app-menu-item-slot","meta":{"name":" Stock Management"}},{"name":"delete-stock-rule-modal","component":"deleteStockRuleModal"},{"name":"delete-packaging-unit-modal","component":"deletePackagingUnitModal"},{"name":"delete-packaging-unit-button","component":"deletePackagingUnitButton"}],"pages":[{"component":"root","route":"stock-management"}],"version":"1.0.1-pre.469"}
1
+ {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.24.0"},"extensions":[{"name":"stock-nav-menu","slot":"stock-sidebar-slot","component":"stockNavMenu","online":true,"offline":true},{"name":"overview-db-link","slot":"stock-page-dashboard-slot","component":"stockOverviewLink","meta":{"name":"overview","slot":"overview-dashboard-slot","title":"overview"},"order":0,"online":true,"offline":true},{"name":"stock-overview-db","slot":"overview-dashboard-slot","component":"stockOverview"},{"name":"operations-db-link","slot":"stock-page-dashboard-slot","component":"stockOperationsLink","meta":{"name":"operations","slot":"operations-dashboard-slot","title":"operations"},"order":2,"online":true,"offline":true},{"name":"stock-operations-db","slot":"operations-dashboard-slot","component":"stockOperations"},{"name":"items-db-link","slot":"stock-page-dashboard-slot","component":"stockItemsLink","meta":{"name":"items","slot":"items-dashboard-slot","title":"items"},"order":1,"online":true,"offline":true},{"name":"stock-items-db","slot":"items-dashboard-slot","component":"stockItems"},{"name":"user-scopes-db-link","slot":"stock-page-dashboard-slot","component":"stockUserScopesLink","meta":{"name":"user-scopes","slot":"user-scopes-dashboard-slot","title":"user-scopes"},"order":3,"online":true,"offline":true},{"name":"stock-user-scopes-db","slot":"user-scopes-dashboard-slot","component":"stockUserScopes"},{"name":"sources-db-link","slot":"stock-page-dashboard-slot","component":"stockSourcesLink","meta":{"name":"sources","slot":"sources-dashboard-slot","title":"Sources"},"order":2,"online":true,"offline":true},{"name":"stock-sources-db","slot":"sources-dashboard-slot","component":"stockSources"},{"name":"locations-db-link","slot":"stock-page-dashboard-slot","component":"stockLocationsLink","meta":{"name":"locations","slot":"locations-dashboard-slot","title":"Locations"},"order":4,"online":true,"offline":true},{"name":"stock-locations-db","slot":"locations-dashboard-slot","component":"stockLocations"},{"name":"reports-db-link","slot":"stock-page-dashboard-slot","component":"stockReportsLink","meta":{"name":"reports","slot":"reports-dashboard-slot","title":"Reports"},"order":5,"online":true,"offline":true},{"name":"stock-reports-db","slot":"reports-dashboard-slot","component":"stockReports"},{"name":"settings-db-link","slot":"stock-page-dashboard-slot","component":"stockSettingsLink","meta":{"name":"settings","slot":"settings-dashboard-slot","title":"Settings"},"order":6,"online":true,"offline":true},{"name":"stock-settings-db","slot":"settings-dashboard-slot","component":"stockSettings"},{"name":"stock-management-admin-card-link","slot":"system-admin-page-card-link-slot","component":"stockManagementAdminCardLink"},{"name":"stock-operation-dialog","component":"stockOperationDialog"},{"name":"import-bulk-stock-items","component":"importBulkStockItemsDialog"},{"name":"delete-stock-modal","component":"deleteStockModal"},{"name":"delete-stock-user-scope-modal","component":"deleteUserScopeModal"},{"name":"stock-management-app-menu-item","component":"stockManagementAppMenuItem","slot":"app-menu-item-slot","meta":{"name":" Stock Management"}},{"name":"delete-stock-rule-modal","component":"deleteStockRuleModal"},{"name":"delete-packaging-unit-modal","component":"deletePackagingUnitModal"},{"name":"delete-packaging-unit-button","component":"deletePackagingUnitButton"}],"pages":[{"component":"root","route":"stock-management"}],"version":"1.0.1-pre.475"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-stock-management-app",
3
- "version": "1.0.1-pre.469",
3
+ "version": "1.0.1-pre.475",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Stock management microfrontend for OpenMRS 3.x",
6
6
  "browser": "dist/openmrs-esm-stock-management-app.js",
@@ -1,10 +1,10 @@
1
- import { showToast } from "@openmrs/esm-framework";
1
+ import { showSnackbar } from "@openmrs/esm-framework";
2
2
 
3
3
  export function errorAlert(title: string, msg: string) {
4
- showToast({
5
- critical: true,
4
+ showSnackbar({
5
+ isLowContrast: true,
6
6
  title: title,
7
7
  kind: "error",
8
- description: msg,
8
+ subtitle: msg,
9
9
  });
10
10
  }
@@ -9,7 +9,7 @@ import {
9
9
  FileUploader,
10
10
  } from "@carbon/react";
11
11
  import { UploadStockItems } from "./stock-items-bulk-import.resource";
12
- import { showNotification, showToast } from "@openmrs/esm-framework";
12
+ import { showSnackbar } from "@openmrs/esm-framework";
13
13
 
14
14
  export interface ImportDialogPopupProps {
15
15
  closeModal: () => void;
@@ -20,8 +20,6 @@ const ImportDialogPopup: React.FC<ImportDialogPopupProps> = ({
20
20
  }) => {
21
21
  const { t } = useTranslation();
22
22
  const [selectedFile, setSelectedFile] = useState<any>();
23
- const [hasHeader, setHasHeader] = useState(true);
24
- const [fileNotSelected, setFileNotSelected] = useState(true);
25
23
 
26
24
  const onConfirmUpload = () => {
27
25
  if (!selectedFile) {
@@ -30,15 +28,15 @@ const ImportDialogPopup: React.FC<ImportDialogPopupProps> = ({
30
28
  const formData = new FormData();
31
29
  if (selectedFile) {
32
30
  formData.append("file", selectedFile, "Import_Stock_Items.csv");
33
- formData.append("hasHeader", hasHeader ? "true" : "false");
31
+ formData.append("hasHeader", "true");
34
32
  }
35
33
  UploadStockItems(formData).then(
36
- (resp) => {
37
- showToast({
38
- critical: true,
34
+ () => {
35
+ showSnackbar({
36
+ isLowContrast: true,
39
37
  title: t("rejectOrder", "Uploaded Order"),
40
38
  kind: "success",
41
- description: t(
39
+ subtitle: t(
42
40
  "Successfully uploaded",
43
41
  `You have successfully uploaded stock items`
44
42
  ),
@@ -46,13 +44,13 @@ const ImportDialogPopup: React.FC<ImportDialogPopupProps> = ({
46
44
  closeModal();
47
45
  },
48
46
  (err) => {
49
- showNotification({
47
+ showSnackbar({
50
48
  title: t(
51
49
  `errorUploadingItems', 'An error occurred uploading stock items`
52
50
  ),
53
51
  kind: "error",
54
- critical: true,
55
- description: err?.message,
52
+ isLowContrast: true,
53
+ subtitle: err?.message,
56
54
  });
57
55
  }
58
56
  );
@@ -62,16 +60,11 @@ const ImportDialogPopup: React.FC<ImportDialogPopupProps> = ({
62
60
  const file = event?.target?.files?.[0];
63
61
  if (file) {
64
62
  setSelectedFile(file);
65
- setFileNotSelected(false);
66
63
  } else {
67
64
  event.preventDefault();
68
65
  }
69
66
  };
70
67
 
71
- const onFileDeleted = () => {
72
- setFileNotSelected(true);
73
- };
74
-
75
68
  return (
76
69
  <div>
77
70
  <Form>
@@ -90,7 +83,6 @@ const ImportDialogPopup: React.FC<ImportDialogPopupProps> = ({
90
83
  labelTitle=""
91
84
  size="small"
92
85
  onChange={onFileChanged}
93
- onDelete={onFileDeleted}
94
86
  />
95
87
  </ModalBody>
96
88
  <ModalFooter>
@@ -1,5 +1,5 @@
1
1
  import React, { useState, useEffect } from "react";
2
- import { showNotification, showToast } from "@openmrs/esm-framework";
2
+ import { showSnackbar } from "@openmrs/esm-framework";
3
3
  import {
4
4
  Button,
5
5
  ModalHeader,
@@ -42,25 +42,25 @@ const DeletePackagingUnit: React.FC<DeletePackagingUnitProps> = ({
42
42
  () => {
43
43
  mutate();
44
44
  closeModal();
45
- showToast({
46
- critical: true,
45
+ showSnackbar({
46
+ isLowContrast: true,
47
47
  title: t("deletePackagingUnitTitle", `Delete packing item `),
48
48
  kind: "success",
49
- description: t(
49
+ subtitle: t(
50
50
  "deletePackagingUnitMesaage",
51
51
  `Stock Item packing unit deleted Successfully`
52
52
  ),
53
53
  });
54
54
  },
55
55
  (error) => {
56
- showNotification({
56
+ showSnackbar({
57
57
  title: t(
58
58
  "deletePackingUnitErrorTitle",
59
59
  `Error Deleting a stock item packing unit`
60
60
  ),
61
61
  kind: "error",
62
- critical: true,
63
- description: error?.message,
62
+ isLowContrast: true,
63
+ subtitle: error?.message,
64
64
  });
65
65
  }
66
66
  );
@@ -26,12 +26,7 @@ import {
26
26
  createStockItemReference,
27
27
  deleteStockItemReference,
28
28
  } from "../../stock-items.resource";
29
- import {
30
- restBaseUrl,
31
- showNotification,
32
- showSnackbar,
33
- showToast,
34
- } from "@openmrs/esm-framework";
29
+ import { restBaseUrl, showSnackbar } from "@openmrs/esm-framework";
35
30
  import { extractErrorMessagesFromResponse } from "../../../constants";
36
31
  import { handleMutate } from "../../../utils";
37
32
 
@@ -41,10 +36,7 @@ interface StockReferencesProps {
41
36
  stockItemUuid: string;
42
37
  }
43
38
 
44
- const StockReferences: React.FC<StockReferencesProps> = ({
45
- isEditing,
46
- stockItemUuid,
47
- }) => {
39
+ const StockReferences: React.FC<StockReferencesProps> = ({ stockItemUuid }) => {
48
40
  const { t } = useTranslation();
49
41
 
50
42
  // get stock item references
@@ -189,10 +181,7 @@ const StockReferencesRow: React.FC<{
189
181
  }> = ({ isEditing, row, key }) => {
190
182
  const { t } = useTranslation();
191
183
 
192
- const {
193
- control,
194
- formState: { errors },
195
- } = useFormContext();
184
+ const { control } = useFormContext();
196
185
 
197
186
  const handleDelete = (e) => {
198
187
  e.preventDefault();
@@ -19,7 +19,7 @@ import {
19
19
  } from "../../../stock-lookups/stock-lookups.resource";
20
20
  import { createOrUpdateStockRule } from "./stock-rules.resource";
21
21
  import { StockRule } from "../../../core/api/types/stockItem/StockRule";
22
- import { showNotification, showToast } from "@openmrs/esm-framework";
22
+ import { showSnackbar } from "@openmrs/esm-framework";
23
23
  import { useTranslation } from "react-i18next";
24
24
  import { closeOverlay } from "../../../core/components/overlay/hook";
25
25
  import { ResourceRepresentation } from "../../../core/api/api";
@@ -61,11 +61,7 @@ const StockRulesAddOrUpdate: React.FC<AddStockRuleProps> = ({
61
61
  const { stockLocations } = useStockTagLocations();
62
62
 
63
63
  //Roles
64
- const {
65
- items: rolesData,
66
- isError: rolesError,
67
- isLoading: loadingRoles,
68
- } = useRoles({ v: ResourceRepresentation.Default });
64
+ const { items: rolesData } = useRoles({ v: ResourceRepresentation.Default });
69
65
 
70
66
  const [formModel, setFormModel] = useState<StockRule>({
71
67
  enabled: true,
@@ -75,8 +71,7 @@ const StockRulesAddOrUpdate: React.FC<AddStockRuleProps> = ({
75
71
  useEffect(() => {
76
72
  if (model != null && Object.keys(model).length != 0) {
77
73
  // To prevent editing properties like date created
78
- const { dateCreated, creatorGivenName, creatorFamilyName, ...rest } =
79
- model;
74
+ const { ...rest } = model;
80
75
  const tmpFormModel = { ...rest };
81
76
  setFormModel(tmpFormModel);
82
77
  }
@@ -143,18 +138,12 @@ const StockRulesAddOrUpdate: React.FC<AddStockRuleProps> = ({
143
138
  setFormModel({ ...formModel, mailRole: selectedMailRole.display });
144
139
  };
145
140
 
146
- const onEnabledChanged = (
147
- cvt: React.ChangeEvent<HTMLInputElement>,
148
- data: { checked: boolean; id: string }
149
- ): void => {
141
+ const onEnabledChanged = (): void => {
150
142
  const isEnabled = !formModel?.enabled;
151
143
  setFormModel({ ...formModel, enabled: isEnabled });
152
144
  };
153
145
 
154
- const onAppliesToChildrenChanged = (
155
- cvt: React.ChangeEvent<HTMLInputElement>,
156
- data: { checked: boolean; id: string }
157
- ): void => {
146
+ const onAppliesToChildrenChanged = (): void => {
158
147
  const enableDescendants = !formModel?.enableDescendants;
159
148
  setFormModel({ ...formModel, enableDescendants: enableDescendants });
160
149
  };
@@ -171,11 +160,11 @@ const StockRulesAddOrUpdate: React.FC<AddStockRuleProps> = ({
171
160
  createOrUpdateStockRule(formModel)
172
161
  .then(
173
162
  () => {
174
- showToast({
175
- critical: true,
163
+ showSnackbar({
164
+ isLowContrast: true,
176
165
  title: t("addedRule", "Add Rule"),
177
166
  kind: "success",
178
- description: t(
167
+ subtitle: t(
179
168
  "stockruleaddedsuccessfully",
180
169
  "Stock Rule Added Successfully"
181
170
  ),
@@ -183,11 +172,11 @@ const StockRulesAddOrUpdate: React.FC<AddStockRuleProps> = ({
183
172
  closeOverlay();
184
173
  },
185
174
  (error) => {
186
- showNotification({
175
+ showSnackbar({
187
176
  title: t(`errorAddingRule', 'error adding a rule`),
188
177
  kind: "error",
189
- critical: true,
190
- description: error?.message,
178
+ isLowContrast: true,
179
+ subtitle: error?.message,
191
180
  });
192
181
  }
193
182
  )
@@ -3,7 +3,7 @@ import { Button, InlineLoading } from "@carbon/react";
3
3
  import { useTranslation } from "react-i18next";
4
4
  import { TrashCan } from "@carbon/react/icons";
5
5
  import { deleteStockRule } from "../../stock-items.resource";
6
- import { showModal, showNotification, showToast } from "@openmrs/esm-framework";
6
+ import { showModal, showSnackbar } from "@openmrs/esm-framework";
7
7
 
8
8
  interface StockRulesDeleteActionMenuProps {
9
9
  uuid: string;
@@ -25,11 +25,11 @@ const StockRulesDeleteActionMenu: React.FC<StockRulesDeleteActionMenuProps> = ({
25
25
  .then(
26
26
  () => {
27
27
  setDeletingRule(false);
28
- showToast({
29
- critical: true,
28
+ showSnackbar({
29
+ isLowContrast: true,
30
30
  title: t("deletingRule", "Delete Rule"),
31
31
  kind: "success",
32
- description: t(
32
+ subtitle: t(
33
33
  "stockruledeletedsuccessfully",
34
34
  "Stock Rule Deleted Successfully"
35
35
  ),
@@ -37,11 +37,11 @@ const StockRulesDeleteActionMenu: React.FC<StockRulesDeleteActionMenuProps> = ({
37
37
  },
38
38
  (error) => {
39
39
  setDeletingRule(false);
40
- showNotification({
40
+ showSnackbar({
41
41
  title: t(`errorDeletingRule', 'error deleting a rule`),
42
42
  kind: "error",
43
- critical: true,
44
- description: error?.message,
43
+ isLowContrast: true,
44
+ subtitle: error?.message,
45
45
  });
46
46
  }
47
47
  )
@@ -2,11 +2,7 @@ import { closeOverlay, launchOverlay } from "../core/components/overlay/hook";
2
2
  import { StockItemDTO } from "../core/api/types/stockItem/StockItem";
3
3
  import React from "react";
4
4
  import AddEditStockItem from "./add-stock-item/add-stock-item.component";
5
- import {
6
- FetchResponse,
7
- showNotification,
8
- showToast,
9
- } from "@openmrs/esm-framework";
5
+ import { FetchResponse, showSnackbar } from "@openmrs/esm-framework";
10
6
  import { createStockItem, updateStockItem } from "./stock-items.resource";
11
7
 
12
8
  export const addOrEditStockItem = async (
@@ -19,13 +15,11 @@ export const addOrEditStockItem = async (
19
15
  : createStockItem)(stockItem);
20
16
 
21
17
  if (response?.data) {
22
- showToast({
23
- critical: true,
18
+ showSnackbar({
19
+ isLowContrast: true,
24
20
  title: `${isEditing ? "Edit" : "Add"} Stock Item`,
25
21
  kind: "success",
26
- description: `Stock Item ${
27
- isEditing ? "Edited" : "Added"
28
- } Successfully`,
22
+ subtitle: `Stock Item ${isEditing ? "Edited" : "Added"} Successfully`,
29
23
  });
30
24
 
31
25
  if (!isEditing) {
@@ -38,11 +32,11 @@ export const addOrEditStockItem = async (
38
32
  }
39
33
  }
40
34
  } catch (error) {
41
- showNotification({
35
+ showSnackbar({
42
36
  title: `Error ${isEditing ? "edit" : "add"}ing a stock item`,
43
37
  kind: "error",
44
- critical: true,
45
- description: error?.responseBody?.error?.message,
38
+ isLowContrast: true,
39
+ subtitle: error?.responseBody?.error?.message,
46
40
  });
47
41
  }
48
42
  };
@@ -1,6 +1,6 @@
1
1
  import React, { useCallback } from "react";
2
2
  import { useTranslation } from "react-i18next";
3
- import { showToast, showNotification, useConfig } from "@openmrs/esm-framework";
3
+ import { showSnackbar } from "@openmrs/esm-framework";
4
4
  import { saveLocation } from "./stock-locations-table.resource";
5
5
  import { locationData, LocationMutator } from "../stock-items/types";
6
6
  import LocationAdministrationForm from "./location-admin-form.component";
@@ -35,22 +35,22 @@ const NewLocationForm: React.FC<LocationFormProps> = ({
35
35
  };
36
36
  saveLocation({ locationPayload: locationbject })
37
37
  .then(() => {
38
- showToast({
38
+ showSnackbar({
39
39
  title: t("formCreated", "Add Location"),
40
40
  kind: "success",
41
- critical: true,
42
- description: t(`Location ${name} was created successfully.`),
41
+ isLowContrast: true,
42
+ subtitle: t(`Location ${name} was created successfully.`),
43
43
  });
44
44
 
45
45
  mutate();
46
46
  onModalChange(false);
47
47
  })
48
48
  .catch((error) => {
49
- showNotification({
49
+ showSnackbar({
50
50
  title: t("errorCreatingForm", "Error creating location"),
51
51
  kind: "error",
52
- critical: true,
53
- description: error?.message,
52
+ isLowContrast: true,
53
+ subtitle: error?.message,
54
54
  });
55
55
  onModalChange(false);
56
56
  });
@@ -1,18 +1,15 @@
1
- import { StockOperationFilter } from "../stock-operations/stock-operations.resource";
2
1
  import { useMemo, useState } from "react";
2
+ import useSWR from "swr";
3
3
  import {
4
4
  FetchResponse,
5
5
  openmrsFetch,
6
6
  restBaseUrl,
7
- showToast,
7
+ showSnackbar,
8
8
  usePagination,
9
9
  } from "@openmrs/esm-framework";
10
10
  import { useTranslation } from "react-i18next";
11
- import {
12
- useStockLocations,
13
- useStockTagLocations,
14
- } from "../stock-lookups/stock-lookups.resource";
15
- import useSWR from "swr";
11
+ import { StockOperationFilter } from "../stock-operations/stock-operations.resource";
12
+ import { useStockTagLocations } from "../stock-lookups/stock-lookups.resource";
16
13
  import { extractErrorMessagesFromResponse } from "../constants";
17
14
 
18
15
  export function useStockLocationPages(filter: StockOperationFilter) {
@@ -89,10 +86,10 @@ export const useLocationTags = () => {
89
86
  const url = `${restBaseUrl}/locationtag/`;
90
87
 
91
88
  // eslint-disable-next-line react-hooks/rules-of-hooks
92
- const { data, error, isLoading, isValidating, mutate } = useSWR<
93
- { data },
94
- Error
95
- >(url, openmrsFetch);
89
+ const { data, isLoading, mutate } = useSWR<{ data }, Error>(
90
+ url,
91
+ openmrsFetch
92
+ );
96
93
  const results = data?.data?.results ? data?.data?.results : [];
97
94
  return {
98
95
  locationTagList: results,
@@ -118,11 +115,11 @@ export async function saveLocation({
118
115
  return response;
119
116
  } catch (error) {
120
117
  const errorMessages = extractErrorMessagesFromResponse(error);
121
- showToast({
122
- description: errorMessages.join(", "),
118
+ showSnackbar({
119
+ subtitle: errorMessages.join(", "),
123
120
  title: "Error on saving form",
124
121
  kind: "error",
125
- critical: true,
122
+ isLowContrast: true,
126
123
  });
127
124
  }
128
125
  }
@@ -22,6 +22,7 @@ import { Drug } from "../core/api/types/concept/Drug";
22
22
  import { Patient } from "../core/api/types/identity/Patient";
23
23
  import { useMemo } from "react";
24
24
  import { uniqBy } from "lodash-es";
25
+ import { UserRoleScope } from "../core/api/types/identity/UserRoleScope";
25
26
 
26
27
  export type PatientFilterCriteria = ResourceFilterCriteria;
27
28
 
@@ -304,3 +305,9 @@ export const useUserRoles = () => {
304
305
  error,
305
306
  };
306
307
  };
308
+ export function getUserRoleScopes(): Promise<
309
+ FetchResponse<PageableResult<UserRoleScope>>
310
+ > {
311
+ const apiUrl = `${restBaseUrl}/stockmanagement/userrolescope`;
312
+ return openmrsFetch(apiUrl);
313
+ }
@@ -22,12 +22,7 @@ import StockOperationApproveDispatchButton from "../stock-operations-dialog/stoc
22
22
  import StockOperationCompleteDispatchButton from "../stock-operations-dialog/stock-operations-completed-dispatch-button.component";
23
23
  import StockOperationIssueStockButton from "../stock-operations-dialog/stock-operations-issue-stock-button.component";
24
24
  import { StockOperation } from "./stock-operation-context/useStockOperationContext";
25
- import {
26
- formatDate,
27
- parseDate,
28
- showSnackbar,
29
- showToast,
30
- } from "@openmrs/esm-framework";
25
+ import { formatDate, parseDate, showSnackbar } from "@openmrs/esm-framework";
31
26
  import {
32
27
  OperationType,
33
28
  StockOperationType,
@@ -23,8 +23,10 @@ import {
23
23
  import {
24
24
  getParties,
25
25
  getStockOperationTypes,
26
+ getUserRoleScopes,
26
27
  } from "../../stock-lookups/stock-lookups.resource";
27
28
  import { Party } from "../../core/api/types/Party";
29
+ import { getCurrentUser } from "@openmrs/esm-framework";
28
30
 
29
31
  export async function initializeNewStockOperation(
30
32
  currentStockOperationType: StockOperationType,
@@ -36,7 +38,15 @@ export async function initializeNewStockOperation(
36
38
  const isNew = !!stockOperation;
37
39
  const newItemsToCopy: StockOperationItemDTO[] = [];
38
40
  const showQuantityRequested = false;
39
-
41
+ const currentUserUuid = await new Promise((resolve, reject) => {
42
+ getCurrentUser().subscribe({
43
+ next: (user) => {
44
+ const userUuid = user?.user?.uuid;
45
+ resolve(userUuid);
46
+ },
47
+ error: (err) => reject(err),
48
+ });
49
+ });
40
50
  let operationTypes = stockOperationTypes;
41
51
  const canIssueStock =
42
52
  stockOperation?.permission?.isRequisitionAndCanIssueStock ?? false;
@@ -68,69 +78,27 @@ export async function initializeNewStockOperation(
68
78
  operationTypeUuid: currentStockOperationType?.uuid,
69
79
  operationType: currentStockOperationType?.operationType,
70
80
  });
71
-
72
- if (
73
- currentStockOperationType.operationType ==
74
- OperationType.STOCK_ISSUE_OPERATION_TYPE
75
- ) {
76
- // requisition = urlQueryParams?.get("requisition");
77
- // if (requisition) {
78
- // const response = await getStockOperation(requisition);
79
- // if (!response.ok) {
80
- // return;
81
- // }
82
- //
83
- // const requisitionStockOperation = response.data;
84
- //
85
- // if (
86
- // !requisitionStockOperation.responsiblePersonUuid &&
87
- // requisitionStockOperation.responsiblePersonOther
88
- // ) {
89
- // requisitionStockOperation.responsiblePersonUuid = "Other";
90
- // }
91
- //
92
- // if (
93
- // requisitionStockOperation &&
94
- // requisitionStockOperation.stockOperationItems
95
- // ) {
96
- // let hasQtyRequested = false;
97
- // requisitionStockOperation.stockOperationItems.forEach((si) => {
98
- // if (si.quantity && si.stockItemPackagingUOMName) {
99
- // hasQtyRequested = true;
100
- // }
101
- //
102
- // const itemId = `new-item-${getStockOperationUniqueId()}`;
103
- // si.id = itemId;
104
- // si.uuid = itemId;
105
- // newItemsToCopy.push({
106
- // ...si,
107
- // quantityRequested: si.quantity,
108
- // quantityRequestedPackagingUOMUuid: si.stockItemPackagingUOMUuid,
109
- // quantityRequestedPackagingUOMName: si.stockItemPackagingUOMName,
110
- // });
111
- // });
112
- // if (hasQtyRequested) {
113
- // showQuantityRequested = true;
114
- // }
115
- // }
116
- // newItemsToCopy.push({ uuid: `new-item-1`, id: `new-item-1` });
117
- // model.destinationUuid = requisitionStockOperation.sourceUuid;
118
- // model.destinationName = requisitionStockOperation.sourceName;
119
- // model.responsiblePersonUuid =
120
- // requisitionStockOperation.responsiblePersonUuid;
121
- // model.responsiblePersonOther =
122
- // requisitionStockOperation.responsiblePersonOther;
123
- // model.responsiblePersonFamilyName =
124
- // requisitionStockOperation.responsiblePersonFamilyName;
125
- // model.responsiblePersonGivenName =
126
- // requisitionStockOperation.responsiblePersonGivenName;
127
- // model.remarks = requisitionStockOperation.remarks;
128
- // }
129
- }
130
81
  const partyList = await getParties();
82
+ const userRoleScopes = await getUserRoleScopes();
83
+ const currentUserRoleScope = userRoleScopes.data?.results?.filter(
84
+ (role) => role.userUuid === currentUserUuid
85
+ );
86
+ const userRoleScopeLocations = [
87
+ ...new Set(
88
+ currentUserRoleScope.flatMap((role) =>
89
+ role?.locations?.map((l) => l.locationUuid)
90
+ )
91
+ ),
92
+ ];
93
+
131
94
  if (!partyList.ok) throw Error("Error loading parties");
95
+ const filteredPartyList = partyList.data?.results?.filter(
96
+ (party) =>
97
+ userRoleScopeLocations.includes(party.locationUuid) ||
98
+ party.stockSourceUuid !== null
99
+ );
132
100
 
133
- sourcePartyList = partyList?.data?.results?.filter(
101
+ sourcePartyList = filteredPartyList?.filter(
134
102
  (p) =>
135
103
  (p.locationUuid &&
136
104
  currentStockOperationType?.sourceType === LocationTypeLocation &&