@openmrs/esm-stock-management-app 1.0.1-pre.352 → 1.0.1-pre.357
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/304.js +2 -0
- package/dist/304.js.map +1 -0
- package/dist/969.js +1 -0
- package/dist/969.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 +41 -41
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/stock-items/types.ts +79 -0
- package/src/stock-locations/add-locations-form.component.tsx +74 -0
- package/src/stock-locations/location-admin-form.component.tsx +164 -0
- package/src/stock-locations/stock-locations-table.component.tsx +33 -10
- package/src/stock-locations/stock-locations-table.resource.tsx +67 -12
- package/src/stock-locations/stock-locations-table.scss +3 -0
- package/src/stock-operations/add-stock-operation/add-stock-operation.component.tsx +10 -5
- package/dist/500.js +0 -2
- package/dist/500.js.map +0 -1
- package/dist/842.js +0 -1
- package/dist/842.js.map +0 -1
- /package/dist/{500.js.LICENSE.txt → 304.js.LICENSE.txt} +0 -0
@@ -1,12 +1,22 @@
|
|
1
1
|
import { StockOperationFilter } from "../stock-operations/stock-operations.resource";
|
2
2
|
import { useMemo, useState } from "react";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
FetchResponse,
|
5
|
+
openmrsFetch,
|
6
|
+
restBaseUrl,
|
7
|
+
showToast,
|
8
|
+
usePagination,
|
9
|
+
} from "@openmrs/esm-framework";
|
4
10
|
import { useTranslation } from "react-i18next";
|
5
|
-
import {
|
11
|
+
import {
|
12
|
+
useStockLocations,
|
13
|
+
useStockTagLocations,
|
14
|
+
} from "../stock-lookups/stock-lookups.resource";
|
15
|
+
import useSWR from "swr";
|
16
|
+
import { extractErrorMessagesFromResponse } from "../constants";
|
6
17
|
|
7
18
|
export function useStockLocationPages(filter: StockOperationFilter) {
|
8
|
-
const {
|
9
|
-
useStockLocations(filter);
|
19
|
+
const { stockLocations, error, isLoading } = useStockTagLocations();
|
10
20
|
|
11
21
|
const pageSizes = [10, 20, 30, 40, 50];
|
12
22
|
const [currentPageSize, setPageSize] = useState(10);
|
@@ -15,7 +25,7 @@ export function useStockLocationPages(filter: StockOperationFilter) {
|
|
15
25
|
goTo,
|
16
26
|
results: paginatedQueueEntries,
|
17
27
|
currentPage,
|
18
|
-
} = usePagination(
|
28
|
+
} = usePagination(stockLocations, currentPageSize);
|
19
29
|
|
20
30
|
const { t } = useTranslation();
|
21
31
|
|
@@ -46,28 +56,73 @@ export function useStockLocationPages(filter: StockOperationFilter) {
|
|
46
56
|
);
|
47
57
|
|
48
58
|
const tableRows = useMemo(() => {
|
49
|
-
return
|
59
|
+
return stockLocations.map((location) => ({
|
50
60
|
id: location?.uuid,
|
51
61
|
key: `key-${location?.uuid}`,
|
52
62
|
uuid: `${location?.uuid}`,
|
53
63
|
name: `${location?.name}`,
|
54
|
-
tags:
|
64
|
+
tags:
|
65
|
+
location?.meta.tag
|
66
|
+
?.filter((tag) => tag.code !== "SUBSETTED")
|
67
|
+
.map((p) => p.code)
|
68
|
+
?.join(", ") ?? "",
|
55
69
|
childLocations:
|
56
70
|
location?.childLocations?.map((p) => p.display)?.join(", ") ?? "",
|
57
71
|
}));
|
58
|
-
}, [
|
59
|
-
|
72
|
+
}, [stockLocations]);
|
60
73
|
return {
|
61
|
-
items:
|
74
|
+
items: stockLocations,
|
62
75
|
currentPage,
|
63
76
|
currentPageSize,
|
64
77
|
paginatedQueueEntries,
|
65
78
|
goTo,
|
66
79
|
pageSizes,
|
67
|
-
|
68
|
-
|
80
|
+
isLoading,
|
81
|
+
error,
|
69
82
|
setPageSize,
|
70
83
|
tableHeaders,
|
71
84
|
tableRows,
|
72
85
|
};
|
73
86
|
}
|
87
|
+
|
88
|
+
export const useLocationTags = () => {
|
89
|
+
const url = `${restBaseUrl}/locationtag/`;
|
90
|
+
|
91
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
92
|
+
const { data, error, isLoading, isValidating, mutate } = useSWR<
|
93
|
+
{ data },
|
94
|
+
Error
|
95
|
+
>(url, openmrsFetch);
|
96
|
+
const results = data?.data?.results ? data?.data?.results : [];
|
97
|
+
return {
|
98
|
+
locationTagList: results,
|
99
|
+
loading: isLoading,
|
100
|
+
mutate,
|
101
|
+
};
|
102
|
+
};
|
103
|
+
interface LocationName {
|
104
|
+
name: string;
|
105
|
+
}
|
106
|
+
export async function saveLocation({
|
107
|
+
locationPayload,
|
108
|
+
}): Promise<FetchResponse<LocationName>> {
|
109
|
+
try {
|
110
|
+
const response: FetchResponse = await openmrsFetch(
|
111
|
+
`${restBaseUrl}/location/`,
|
112
|
+
{
|
113
|
+
method: "POST",
|
114
|
+
headers: { "Content-Type": "application/json" },
|
115
|
+
body: locationPayload,
|
116
|
+
}
|
117
|
+
);
|
118
|
+
return response;
|
119
|
+
} catch (error) {
|
120
|
+
const errorMessages = extractErrorMessagesFromResponse(error);
|
121
|
+
showToast({
|
122
|
+
description: errorMessages.join(", "),
|
123
|
+
title: "Error on saving form",
|
124
|
+
kind: "error",
|
125
|
+
critical: true,
|
126
|
+
});
|
127
|
+
}
|
128
|
+
}
|
@@ -22,7 +22,12 @@ 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 {
|
25
|
+
import {
|
26
|
+
formatDate,
|
27
|
+
parseDate,
|
28
|
+
showSnackbar,
|
29
|
+
showToast,
|
30
|
+
} from "@openmrs/esm-framework";
|
26
31
|
import {
|
27
32
|
OperationType,
|
28
33
|
StockOperationType,
|
@@ -43,12 +48,12 @@ const AddStockOperation: React.FC<AddStockOperationProps> = (props) => {
|
|
43
48
|
if (isLoading) return <AccordionSkeleton />;
|
44
49
|
if (isError) {
|
45
50
|
closeOverlay();
|
46
|
-
|
51
|
+
showSnackbar({
|
47
52
|
kind: "error",
|
48
53
|
title: t("error", "Error"),
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
subtitle: t("errorLoadingStockOperation", "Error loading stock item"),
|
55
|
+
timeoutInMs: 5000,
|
56
|
+
isLowContrast: true,
|
52
57
|
});
|
53
58
|
return;
|
54
59
|
}
|