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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) 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-operations/add-stock-operation/add-stock-operation.component.tsx +1 -6
  18. package/src/stock-operations/stock-operation.utils.tsx +7 -8
  19. package/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx +8 -12
  20. package/src/stock-sources/stock-sources-delete/stock-sources-delete.component.tsx +7 -12
  21. package/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx +20 -73
  22. package/src/stock-user-role-scopes/delete-stock-user-scope/delete-stock-user-scope.component.tsx +7 -12
  23. package/src/utils.ts +4 -4
@@ -28,12 +28,7 @@ import { closeOverlay } from "../../core/components/overlay/hook";
28
28
  import { useTranslation } from "react-i18next";
29
29
  import { UserRoleScope } from "../../core/api/types/identity/UserRoleScope";
30
30
  import { createOrUpdateUserRoleScope } from "../stock-user-role-scopes.resource";
31
- import {
32
- restBaseUrl,
33
- showNotification,
34
- showToast,
35
- useSession,
36
- } from "@openmrs/esm-framework";
31
+ import { restBaseUrl, showSnackbar, useSession } from "@openmrs/esm-framework";
37
32
  import { UserRoleScopeOperationType } from "../../core/api/types/identity/UserRoleScopeOperationType";
38
33
  import { UserRoleScopeLocation } from "../../core/api/types/identity/UserRoleScopeLocation";
39
34
  import {
@@ -69,7 +64,6 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
69
64
 
70
65
  const [roles, setRoles] = useState<Role[]>([]);
71
66
 
72
- const [showItems, setShowItems] = useState(false);
73
67
  const loggedInUserUuid = currentUser?.user?.uuid;
74
68
 
75
69
  // operation types
@@ -79,37 +73,28 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
79
73
  } = useStockOperationTypes();
80
74
 
81
75
  // get users
82
- const {
83
- items: users,
84
-
85
- isLoading: loadingUsers,
86
- } = useUsers({ v: ResourceRepresentation.Default });
76
+ const { items: users, isLoading: loadingUsers } = useUsers({
77
+ v: ResourceRepresentation.Default,
78
+ });
87
79
 
88
80
  const [selectedUserUuid, setSelectedUserUuid] = useState<string | null>(null);
89
- const { data: user, isError } = useUser(selectedUserUuid);
81
+ const { data: user } = useUser(selectedUserUuid);
90
82
 
91
83
  // get roles
92
- const { items: rolesData, isLoading: loadingRoles } = useRoles({
84
+ const { isLoading: loadingRoles } = useRoles({
93
85
  v: ResourceRepresentation.Default,
94
86
  });
95
87
 
96
88
  /* Only load locations tagged to perform stock related activities.
97
89
  Unless a location is tag as main store, main pharmacy or dispensing, it will not be listed here.
98
-
99
90
  */
100
91
  const { stockLocations } = useStockTagLocations();
101
- const onEnabledChanged = (
102
- cvt: React.ChangeEvent<HTMLInputElement>,
103
- data: { checked: boolean; id: string }
104
- ): void => {
92
+ const onEnabledChanged = (): void => {
105
93
  const isEnabled = !formModel?.enabled;
106
94
  setFormModel({ ...formModel, enabled: isEnabled });
107
95
  };
108
96
 
109
- const onPermanentChanged = (
110
- cvt: React.ChangeEvent<HTMLInputElement>,
111
- data: { checked: boolean; id: string }
112
- ): void => {
97
+ const onPermanentChanged = (): void => {
113
98
  const isPermanent = !formModel?.permanent;
114
99
  setFormModel({
115
100
  ...formModel,
@@ -119,16 +104,12 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
119
104
  });
120
105
  };
121
106
 
122
- const [searchQuery, setSearchQuery] = useState<string>("");
123
- const [filteredItems, setFilteredItems] = useState<any[]>([]);
107
+ const [filteredItems, setFilteredItems] = useState<unknown[]>([]);
124
108
 
125
109
  const usersResults = users?.results ?? [];
126
110
 
127
111
  const filterItems = (query: string) => {
128
- if (query.trim() === "") {
129
- setShowItems(false);
130
- } else {
131
- setShowItems(true);
112
+ if (query && query.trim() !== "") {
132
113
  const filtered = usersResults
133
114
  .filter((item: any) => item.uuid !== loggedInUserUuid)
134
115
  .filter((item: any) => {
@@ -145,13 +126,10 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
145
126
  }, [model]);
146
127
 
147
128
  const handleSearchQueryChange = (query: string) => {
148
- setSearchQuery(query);
149
129
  filterItems(query);
150
130
  };
151
131
  const onStockOperationTypeChanged = (
152
- event: React.ChangeEvent<HTMLInputElement>,
153
- uuid: string,
154
- isChecked: boolean
132
+ event: React.ChangeEvent<HTMLInputElement>
155
133
  ): void => {
156
134
  const operationType = formModel?.operationTypes?.find(
157
135
  (x) => x.operationTypeUuid === event?.target?.value
@@ -179,8 +157,7 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
179
157
  };
180
158
 
181
159
  const onLocationCheckBoxChanged = (
182
- event: ChangeEvent<HTMLInputElement>,
183
- id: string
160
+ event: ChangeEvent<HTMLInputElement>
184
161
  ): void => {
185
162
  const selectedLocation = formModel?.locations?.find(
186
163
  (x) => x.locationUuid === event?.target?.value
@@ -253,28 +230,6 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
253
230
  });
254
231
  };
255
232
 
256
- const onEnableDescendantsChanged = (event: ChangeEvent<HTMLInputElement>) => {
257
- const selectedLocation = formModel?.locations?.find(
258
- (x) => x.locationUuid === event?.target?.value
259
- );
260
- if (selectedLocation) {
261
- const enableDescendants = !(selectedLocation.enableDescendants === true);
262
- const newModifiedLocation = {
263
- ...selectedLocation,
264
- enableDescendants: enableDescendants,
265
- };
266
- setFormModel({
267
- ...formModel,
268
- locations: [
269
- ...(formModel?.locations?.filter(
270
- (x) => x.locationUuid !== selectedLocation?.locationUuid
271
- ) ?? []),
272
- newModifiedLocation,
273
- ],
274
- });
275
- }
276
- };
277
-
278
233
  const isOperationChecked = (operationType: StockOperationType) => {
279
234
  return (
280
235
  formModel?.operationTypes?.filter(
@@ -289,11 +244,11 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
289
244
  createOrUpdateUserRoleScope(formModel).then(
290
245
  (res) => {
291
246
  handleMutate(`${restBaseUrl}/stockmanagement/userrolescope`);
292
- showToast({
293
- critical: true,
247
+ showSnackbar({
248
+ isLowContrast: true,
294
249
  title: t("addUserRole", "Add User role"),
295
250
  kind: "success",
296
- description: t(
251
+ subtitle: t(
297
252
  "successfullysaved",
298
253
  `You have successfully saved user role scope `
299
254
  ),
@@ -301,13 +256,13 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
301
256
  closeOverlay();
302
257
  },
303
258
  (err) => {
304
- showNotification({
259
+ showSnackbar({
305
260
  title: t(
306
261
  `errorSaving user role scope', 'Error Saving user role scope`
307
262
  ),
308
263
  kind: "error",
309
- critical: true,
310
- description: err?.message,
264
+ isLowContrast: true,
265
+ subtitle: err?.message,
311
266
  });
312
267
 
313
268
  closeOverlay();
@@ -465,13 +420,7 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
465
420
  value={type.uuid}
466
421
  checked={isOperationChecked(type)}
467
422
  className={styles.checkbox}
468
- onChange={(event) =>
469
- onStockOperationTypeChanged(
470
- event,
471
- type.uuid,
472
- isOperationChecked(type)
473
- )
474
- }
423
+ onChange={(event) => onStockOperationTypeChanged(event)}
475
424
  labelText={type.name}
476
425
  id={type.uuid}
477
426
  />
@@ -520,9 +469,7 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
520
469
  key={`chk-loc-child-key-${type.id}`}
521
470
  id={`chk-loc-child-${type.id}`}
522
471
  value={type.id}
523
- onChange={(event) =>
524
- onLocationCheckBoxChanged(event, type.id)
525
- }
472
+ onChange={(event) => onLocationCheckBoxChanged(event)}
526
473
  className={styles.checkbox}
527
474
  labelText={type.name}
528
475
  checked={checkedLocation != null}
@@ -3,12 +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 { deleteUserRoleScopes } from "../stock-user-role-scopes.resource";
6
- import {
7
- restBaseUrl,
8
- showModal,
9
- showNotification,
10
- showToast,
11
- } from "@openmrs/esm-framework";
6
+ import { restBaseUrl, showModal, showSnackbar } from "@openmrs/esm-framework";
12
7
  import { handleMutate } from "../../utils";
13
8
 
14
9
  interface StockUserScopDeleteActionMenuProps {
@@ -34,11 +29,11 @@ const StockUserScopeDeleteActionMenu: React.FC<
34
29
  () => {
35
30
  handleMutate(`${restBaseUrl}/stockmanagement/userrolescope`);
36
31
  setDeletingUserScope(false);
37
- showToast({
38
- critical: true,
32
+ showSnackbar({
33
+ isLowContrast: true,
39
34
  title: t("deletingstockUserScope", "Delete Stock User Scope"),
40
35
  kind: "success",
41
- description: t(
36
+ subtitle: t(
42
37
  "stockuserscopedeletedsuccessfully",
43
38
  "Stock User Scope Deleted Successfully"
44
39
  ),
@@ -46,13 +41,13 @@ const StockUserScopeDeleteActionMenu: React.FC<
46
41
  },
47
42
  (error) => {
48
43
  setDeletingUserScope(false);
49
- showNotification({
44
+ showSnackbar({
50
45
  title: t(
51
46
  `errorDeletingUserScope', 'error deleting a user scope`
52
47
  ),
53
48
  kind: "error",
54
- critical: true,
55
- description: error?.message,
49
+ isLowContrast: true,
50
+ subtitle: error?.message,
56
51
  });
57
52
  }
58
53
  )
package/src/utils.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { showNotification } from "@openmrs/esm-framework";
1
+ import { showSnackbar } from "@openmrs/esm-framework";
2
2
  import { mutate } from "swr";
3
3
 
4
4
  export function errorAlert(msg: string, error?: Error) {
5
- showNotification({
5
+ showSnackbar({
6
6
  title: msg,
7
7
  kind: "error",
8
- critical: true,
9
- description: error?.message,
8
+ isLowContrast: true,
9
+ subtitle: error?.message,
10
10
  });
11
11
  }
12
12