@openmrs/esm-stock-management-app 1.0.1-pre.418 → 1.0.1-pre.420
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/314.js +1 -0
- package/dist/314.js.map +1 -0
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-stock-management-app.js +1 -1
- package/dist/openmrs-esm-stock-management-app.js.buildmanifest.json +31 -31
- package/dist/openmrs-esm-stock-management-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/core/api/types/stockItem/StockItemReference.ts +18 -0
- package/src/core/components/carbon/controlled-text-input/controlled-text-input.component.tsx +2 -2
- package/src/core/components/tabs/vertical-tabs.scss +6 -3
- package/src/stock-items/add-stock-item/add-stock-item.component.tsx +8 -0
- package/src/stock-items/add-stock-item/stock-item-details/stock-item-details.component.tsx +3 -2
- package/src/stock-items/add-stock-item/stock-item-references/stock-item-references.component.tsx +264 -0
- package/src/stock-items/add-stock-item/stock-item-references/stock-item-references.resource.ts +39 -0
- package/src/stock-items/add-stock-item/stock-item-references/stock-item-references.scss +23 -0
- package/src/stock-items/add-stock-item/stock-item-references/stock-references-selector.component.tsx +66 -0
- package/src/stock-items/add-stock-item/stock-item-references/validation-schema.ts +8 -0
- package/src/stock-items/add-stock-item/stock-item-rules/stock-item-rules.component.tsx +0 -1
- package/src/stock-items/stock-items.resource.ts +72 -1
- package/src/stock-operations/stock-operation.utils.tsx +1 -1
- package/src/stock-operations/stock-operations-dialog/stock-operations-dialog.component.tsx +1 -1
- package/src/stock-operations/stock-operations-table.component.tsx +8 -1
- package/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx +8 -3
- package/src/stock-sources/stock-sources-delete/stock-sources-delete.component.tsx +8 -3
- package/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx +7 -4
- package/src/stock-user-role-scopes/delete-stock-user-scope/delete-stock-user-scope.component.tsx +8 -3
- package/src/utils.ts +7 -0
- package/dist/39.js +0 -1
- package/dist/39.js.map +0 -1
- package/src/stock-items/add-stock-item/stock-rules/stock-rules.component.tsx +0 -16
- package/src/stock-items/add-stock-item/stock-rules/stock-rules.resource.tsx +0 -0
- package/src/stock-items/add-stock-item/stock-rules/stock-rules.scss +0 -0
- package/src/stock-operations/swr-revalidation.ts +0 -7
- package/src/stock-sources/swr-revalidation.ts +0 -7
- package/src/stock-user-role-scopes/swr-revalidation.ts +0 -7
@@ -0,0 +1,23 @@
|
|
1
|
+
@use '@carbon/styles/scss/colors';
|
2
|
+
@use "@carbon/styles/scss/spacing";
|
3
|
+
@use "@carbon/styles/scss/type";
|
4
|
+
|
5
|
+
.referencesTable {
|
6
|
+
min-height: 15rem;
|
7
|
+
display: block;
|
8
|
+
}
|
9
|
+
|
10
|
+
.referencesTableCell {
|
11
|
+
display: flex;
|
12
|
+
align-items: center;
|
13
|
+
}
|
14
|
+
|
15
|
+
.referencesTableBody {
|
16
|
+
min-height: spacing.$spacing-13;
|
17
|
+
|
18
|
+
}
|
19
|
+
|
20
|
+
.referencesTableContainer {
|
21
|
+
min-height: 15rem;
|
22
|
+
display: block;
|
23
|
+
}
|
package/src/stock-items/add-stock-item/stock-item-references/stock-references-selector.component.tsx
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { TextInputSkeleton, ComboBox } from "@carbon/react";
|
3
|
+
import { Control, Controller, FieldValues } from "react-hook-form";
|
4
|
+
import { StockSource } from "../../../core/api/types/stockOperation/StockSource";
|
5
|
+
import { ResourceRepresentation } from "../../../core/api/api";
|
6
|
+
import { useStockSources } from "../../../stock-sources/stock-sources.resource";
|
7
|
+
import { Concept } from "../../../core/api/types/concept/Concept";
|
8
|
+
import { StockItemReferenceDTO } from "../../../core/api/types/stockItem/StockItemReference";
|
9
|
+
|
10
|
+
interface StockSourceSelectorProps<T> {
|
11
|
+
row?: StockItemReferenceDTO;
|
12
|
+
onSourceChange?: (unit: StockSource) => void;
|
13
|
+
title?: string;
|
14
|
+
placeholder?: string;
|
15
|
+
invalid?: boolean;
|
16
|
+
|
17
|
+
// Control
|
18
|
+
controllerName: string;
|
19
|
+
name: string;
|
20
|
+
control: Control<FieldValues, T>;
|
21
|
+
}
|
22
|
+
|
23
|
+
const StockSourceSelector = <T,>(props: StockSourceSelectorProps<T>) => {
|
24
|
+
const {
|
25
|
+
items: { results: sourcesList },
|
26
|
+
isLoading,
|
27
|
+
} = useStockSources({
|
28
|
+
v: ResourceRepresentation.Default,
|
29
|
+
});
|
30
|
+
if (isLoading) return <TextInputSkeleton />;
|
31
|
+
|
32
|
+
return (
|
33
|
+
<Controller
|
34
|
+
name={props.controllerName}
|
35
|
+
control={props.control}
|
36
|
+
render={({ field: { onChange, value, ref } }) => (
|
37
|
+
<ComboBox
|
38
|
+
titleText={props.title}
|
39
|
+
name={props.name}
|
40
|
+
control={props.control}
|
41
|
+
controllerName={props.controllerName}
|
42
|
+
id={props.name}
|
43
|
+
size={"md"}
|
44
|
+
items={sourcesList || []}
|
45
|
+
onChange={(data: { selectedItem: StockSource }) => {
|
46
|
+
props.onSourceChange?.(data.selectedItem);
|
47
|
+
onChange(data.selectedItem?.uuid);
|
48
|
+
}}
|
49
|
+
initialSelectedItem={
|
50
|
+
sourcesList?.find((p) => p.uuid === props.row?.uuid) || {}
|
51
|
+
}
|
52
|
+
itemToString={(item?: Concept) =>
|
53
|
+
item && item?.name ? `${item?.name}` : ""
|
54
|
+
}
|
55
|
+
shouldFilterItem={() => true}
|
56
|
+
value={sourcesList?.find((p) => p.uuid === value)?.name ?? ""}
|
57
|
+
placeholder={props.placeholder}
|
58
|
+
ref={ref}
|
59
|
+
invalid={props.invalid}
|
60
|
+
/>
|
61
|
+
)}
|
62
|
+
/>
|
63
|
+
);
|
64
|
+
};
|
65
|
+
|
66
|
+
export default StockSourceSelector;
|
@@ -12,6 +12,10 @@ import { StockOperationItemCost } from "../core/api/types/stockOperation/StockOp
|
|
12
12
|
import { StockBatchDTO } from "../core/api/types/stockItem/StockBatchDTO";
|
13
13
|
import { StockItemPackagingUOMDTO } from "../core/api/types/stockItem/StockItemPackagingUOM";
|
14
14
|
import { StockRule } from "../core/api/types/stockItem/StockRule";
|
15
|
+
import {
|
16
|
+
StockItemReference,
|
17
|
+
StockItemReferenceDTO,
|
18
|
+
} from "../core/api/types/stockItem/StockItemReference";
|
15
19
|
|
16
20
|
export interface StockItemFilter extends ResourceFilterCriteria {
|
17
21
|
isDrug?: string | null | undefined;
|
@@ -47,6 +51,10 @@ export interface StockItemPackagingUOMFilter extends ResourceFilterCriteria {
|
|
47
51
|
stockItemUuid?: string | null | undefined;
|
48
52
|
}
|
49
53
|
|
54
|
+
export interface StockItemReferenceFilter extends ResourceFilterCriteria {
|
55
|
+
stockItemUuid?: string | null | undefined;
|
56
|
+
}
|
57
|
+
|
50
58
|
export interface StockBatchFilter extends ResourceFilterCriteria {
|
51
59
|
stockItemUuid?: string | null | undefined;
|
52
60
|
excludeExpired?: boolean | null;
|
@@ -303,7 +311,6 @@ export function importStockItem(item: FormData) {
|
|
303
311
|
// stock rules
|
304
312
|
// getStockRules
|
305
313
|
export function useStockRules(filter: StockRuleFilter) {
|
306
|
-
console.warn("Rules filter: " + JSON.stringify(filter));
|
307
314
|
const apiUrl = `${restBaseUrl}/stockmanagement/stockrule${toQueryParams(
|
308
315
|
filter
|
309
316
|
)}`;
|
@@ -367,3 +374,67 @@ export function deleteStockRule(id: string) {
|
|
367
374
|
signal: abortController.signal,
|
368
375
|
});
|
369
376
|
}
|
377
|
+
|
378
|
+
// stock references
|
379
|
+
// getStockItemReferences
|
380
|
+
export function useStockItemReferences(filter: StockItemReferenceFilter) {
|
381
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockitemreference${toQueryParams(
|
382
|
+
filter
|
383
|
+
)}`;
|
384
|
+
const { data, error, isLoading } = useSWR<
|
385
|
+
{
|
386
|
+
data: PageableResult<StockItemReferenceDTO>;
|
387
|
+
},
|
388
|
+
Error
|
389
|
+
>(apiUrl, openmrsFetch);
|
390
|
+
|
391
|
+
return {
|
392
|
+
items: data?.data || <PageableResult<StockItemReferenceDTO>>{},
|
393
|
+
isLoading,
|
394
|
+
isError: error,
|
395
|
+
};
|
396
|
+
}
|
397
|
+
|
398
|
+
// create stockItemReference
|
399
|
+
export function createStockItemReference(item: StockItemReferenceDTO) {
|
400
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockitemreference`;
|
401
|
+
const abortController = new AbortController();
|
402
|
+
return openmrsFetch(apiUrl, {
|
403
|
+
method: "POST",
|
404
|
+
headers: {
|
405
|
+
"Content-Type": "application/json",
|
406
|
+
},
|
407
|
+
signal: abortController.signal,
|
408
|
+
body: item,
|
409
|
+
});
|
410
|
+
}
|
411
|
+
|
412
|
+
// updateStockRule
|
413
|
+
export function updateStockItemReference(
|
414
|
+
item: StockItemReference,
|
415
|
+
uuid: string
|
416
|
+
) {
|
417
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockitemreference/${uuid}`;
|
418
|
+
const abortController = new AbortController();
|
419
|
+
return openmrsFetch(apiUrl, {
|
420
|
+
method: "POST",
|
421
|
+
headers: {
|
422
|
+
"Content-Type": "application/json",
|
423
|
+
},
|
424
|
+
signal: abortController.signal,
|
425
|
+
body: item,
|
426
|
+
});
|
427
|
+
}
|
428
|
+
// deleteStockItemReferemce
|
429
|
+
export function deleteStockItemReference(id: string) {
|
430
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockitemreference/${id}`;
|
431
|
+
const abortController = new AbortController();
|
432
|
+
|
433
|
+
return openmrsFetch(apiUrl, {
|
434
|
+
method: "DELETE",
|
435
|
+
headers: {
|
436
|
+
"Content-Type": "application/json",
|
437
|
+
},
|
438
|
+
signal: abortController.signal,
|
439
|
+
});
|
440
|
+
}
|
@@ -19,7 +19,7 @@ import {
|
|
19
19
|
} from "../core/api/types/stockOperation/StockOperationType";
|
20
20
|
import { useLocation } from "react-router-dom";
|
21
21
|
import { extractErrorMessagesFromResponse } from "../constants";
|
22
|
-
import { handleMutate } from "
|
22
|
+
import { handleMutate } from "../utils";
|
23
23
|
export const addOrEditStockOperation = async (
|
24
24
|
stockOperation: StockOperationDTO,
|
25
25
|
isEditing: boolean,
|
@@ -19,7 +19,7 @@ import { executeStockOperationAction } from "../stock-operations.resource";
|
|
19
19
|
import { restBaseUrl, showSnackbar } from "@openmrs/esm-framework";
|
20
20
|
import { closeOverlay } from "../../core/components/overlay/hook";
|
21
21
|
import { extractErrorMessagesFromResponse } from "../../constants";
|
22
|
-
import { handleMutate } from "
|
22
|
+
import { handleMutate } from "../../utils";
|
23
23
|
|
24
24
|
interface StockOperationDialogProps {
|
25
25
|
title: string;
|
@@ -38,7 +38,12 @@ import {
|
|
38
38
|
StockOperationStatusRejected,
|
39
39
|
StockOperationStatusReturned,
|
40
40
|
} from "../core/api/types/stockOperation/StockOperationStatus";
|
41
|
-
import {
|
41
|
+
import {
|
42
|
+
isDesktop,
|
43
|
+
restBaseUrl,
|
44
|
+
showModal,
|
45
|
+
useConfig,
|
46
|
+
} from "@openmrs/esm-framework";
|
42
47
|
import StockOperationTypesSelector from "./stock-operation-types-selector/stock-operation-types-selector.component";
|
43
48
|
import { launchAddOrEditDialog } from "./stock-operation.utils";
|
44
49
|
import { initialStockOperationValue } from "../core/utils/utils";
|
@@ -51,6 +56,7 @@ import {
|
|
51
56
|
DATE_PICKER_FORMAT,
|
52
57
|
StockFilters,
|
53
58
|
} from "../constants";
|
59
|
+
import { handleMutate } from "../utils";
|
54
60
|
|
55
61
|
interface StockOperationsTableProps {
|
56
62
|
status?: string;
|
@@ -114,6 +120,7 @@ const StockOperations: React.FC<StockOperationsTableProps> = () => {
|
|
114
120
|
title: "complete",
|
115
121
|
closeModal: () => dispose(),
|
116
122
|
});
|
123
|
+
handleMutate(`${restBaseUrl}/stockmanagement/stockoperation`);
|
117
124
|
};
|
118
125
|
|
119
126
|
useEffect(() => {
|
@@ -9,15 +9,20 @@ import {
|
|
9
9
|
SelectItem,
|
10
10
|
} from "@carbon/react";
|
11
11
|
import React, { ChangeEvent, useCallback, useState } from "react";
|
12
|
-
import { handleMutate } from "../swr-revalidation";
|
13
12
|
import styles from "./add-stock-sources.scss";
|
14
13
|
import { useConcept } from "../../stock-lookups/stock-lookups.resource";
|
15
14
|
import { StockSource } from "../../core/api/types/stockOperation/StockSource";
|
16
15
|
import { createOrUpdateStockSource } from "../stock-sources.resource";
|
17
|
-
import {
|
16
|
+
import {
|
17
|
+
restBaseUrl,
|
18
|
+
showNotification,
|
19
|
+
showToast,
|
20
|
+
useConfig,
|
21
|
+
} from "@openmrs/esm-framework";
|
18
22
|
import { useTranslation } from "react-i18next";
|
19
23
|
import { closeOverlay } from "../../core/components/overlay/hook";
|
20
24
|
import { type ConfigObject } from "../../config-schema";
|
25
|
+
import { handleMutate } from "../../utils";
|
21
26
|
|
22
27
|
interface AddStockSourceProps {
|
23
28
|
model?: StockSource;
|
@@ -68,7 +73,7 @@ const StockSourcesAddOrUpdate: React.FC<AddStockSourceProps> = ({ model }) => {
|
|
68
73
|
),
|
69
74
|
});
|
70
75
|
|
71
|
-
handleMutate(
|
76
|
+
handleMutate(`${restBaseUrl}/stockmanagement/stocksource`);
|
72
77
|
|
73
78
|
closeOverlay();
|
74
79
|
},
|
@@ -1,10 +1,15 @@
|
|
1
1
|
import React, { useState } from "react";
|
2
|
-
import { handleMutate } from "../swr-revalidation";
|
3
2
|
import { Button, InlineLoading } from "@carbon/react";
|
4
3
|
import { useTranslation } from "react-i18next";
|
5
4
|
import { TrashCan } from "@carbon/react/icons";
|
6
5
|
import { deleteStockSource } from "../stock-sources.resource";
|
7
|
-
import {
|
6
|
+
import {
|
7
|
+
restBaseUrl,
|
8
|
+
showModal,
|
9
|
+
showNotification,
|
10
|
+
showToast,
|
11
|
+
} from "@openmrs/esm-framework";
|
12
|
+
import { handleMutate } from "../../utils";
|
8
13
|
|
9
14
|
interface StockSourcesDeleteActionMenuProps {
|
10
15
|
uuid: string;
|
@@ -29,7 +34,7 @@ const StockSourcesDeleteActionMenu: React.FC<
|
|
29
34
|
() => {
|
30
35
|
setDeletingSource(false);
|
31
36
|
|
32
|
-
handleMutate(
|
37
|
+
handleMutate(`${restBaseUrl}/stockmanagement/stocksource`);
|
33
38
|
showToast({
|
34
39
|
critical: true,
|
35
40
|
title: t("deletingSource", "Delete Source"),
|
package/src/stock-user-role-scopes/add-stock-user-scope/add-stock-user-role-scope.component.tsx
CHANGED
@@ -28,7 +28,11 @@ 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 {
|
31
|
+
import {
|
32
|
+
restBaseUrl,
|
33
|
+
showNotification,
|
34
|
+
showToast,
|
35
|
+
} from "@openmrs/esm-framework";
|
32
36
|
import { UserRoleScopeOperationType } from "../../core/api/types/identity/UserRoleScopeOperationType";
|
33
37
|
import { UserRoleScopeLocation } from "../../core/api/types/identity/UserRoleScopeLocation";
|
34
38
|
import {
|
@@ -42,11 +46,10 @@ import {
|
|
42
46
|
formatForDatePicker,
|
43
47
|
today,
|
44
48
|
} from "../../constants";
|
45
|
-
import { debounce } from "lodash-es";
|
46
49
|
import { User } from "../../core/api/types/identity/User";
|
47
50
|
import { Role } from "../../core/api/types/identity/Role";
|
48
51
|
import { StockOperationType } from "../../core/api/types/stockOperation/StockOperationType";
|
49
|
-
import { handleMutate } from "
|
52
|
+
import { handleMutate } from "../../utils";
|
50
53
|
|
51
54
|
const MinDate: Date = today();
|
52
55
|
|
@@ -274,7 +277,7 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
|
|
274
277
|
|
275
278
|
createOrUpdateUserRoleScope(formModel).then(
|
276
279
|
(res) => {
|
277
|
-
handleMutate(
|
280
|
+
handleMutate(`${restBaseUrl}/stockmanagement/userrolescope`);
|
278
281
|
showToast({
|
279
282
|
critical: true,
|
280
283
|
title: t("addUserRole", "Add User role"),
|
package/src/stock-user-role-scopes/delete-stock-user-scope/delete-stock-user-scope.component.tsx
CHANGED
@@ -3,8 +3,13 @@ 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
|
-
|
6
|
+
import {
|
7
|
+
restBaseUrl,
|
8
|
+
showModal,
|
9
|
+
showNotification,
|
10
|
+
showToast,
|
11
|
+
} from "@openmrs/esm-framework";
|
12
|
+
import { handleMutate } from "../../utils";
|
8
13
|
|
9
14
|
interface StockUserScopDeleteActionMenuProps {
|
10
15
|
uuid: string;
|
@@ -27,7 +32,7 @@ const StockUserScopeDeleteActionMenu: React.FC<
|
|
27
32
|
deleteUserRoleScopes(ids)
|
28
33
|
.then(
|
29
34
|
() => {
|
30
|
-
handleMutate(
|
35
|
+
handleMutate(`${restBaseUrl}/stockmanagement/userrolescope`);
|
31
36
|
setDeletingUserScope(false);
|
32
37
|
showToast({
|
33
38
|
critical: true,
|
package/src/utils.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { showNotification } from "@openmrs/esm-framework";
|
2
|
+
import { mutate } from "swr";
|
2
3
|
|
3
4
|
export function errorAlert(msg: string, error?: Error) {
|
4
5
|
showNotification({
|
@@ -8,3 +9,9 @@ export function errorAlert(msg: string, error?: Error) {
|
|
8
9
|
description: error?.message,
|
9
10
|
});
|
10
11
|
}
|
12
|
+
|
13
|
+
export const handleMutate = (url: string) => {
|
14
|
+
mutate((key) => typeof key === "string" && key.startsWith(url), undefined, {
|
15
|
+
revalidate: true,
|
16
|
+
});
|
17
|
+
};
|