@openmrs/esm-stock-management-app 1.0.1-pre.418 → 1.0.1-pre.433
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-number-input/controlled-number-input.component.tsx +2 -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/packaging-units/packaging-units.component.tsx +26 -6
- 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/add-stock-rules.component.tsx +5 -2
- 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
package/src/stock-items/add-stock-item/stock-item-references/stock-item-references.component.tsx
ADDED
@@ -0,0 +1,264 @@
|
|
1
|
+
import React, { useMemo, useEffect } from "react";
|
2
|
+
import { useTranslation } from "react-i18next";
|
3
|
+
import {
|
4
|
+
Button,
|
5
|
+
DataTable,
|
6
|
+
Table,
|
7
|
+
TableBody,
|
8
|
+
TableCell,
|
9
|
+
TableContainer,
|
10
|
+
TableHead,
|
11
|
+
TableHeader,
|
12
|
+
TableRow,
|
13
|
+
DataTableSkeleton,
|
14
|
+
} from "@carbon/react";
|
15
|
+
import styles from "./stock-item-references.scss";
|
16
|
+
import { TrashCan, Save } from "@carbon/react/icons";
|
17
|
+
import { FormProvider, useForm, useFormContext } from "react-hook-form";
|
18
|
+
import StockSourceSelector from "./stock-references-selector.component";
|
19
|
+
import { useStockItemReferencesHook } from "./stock-item-references.resource";
|
20
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
21
|
+
import { StockItemReferenceData } from "./validation-schema";
|
22
|
+
import { stockItemDetailsSchema } from "../../validationSchema";
|
23
|
+
import { StockItemReferenceDTO } from "../../../core/api/types/stockItem/StockItemReference";
|
24
|
+
import ControlledTextInput from "../../../core/components/carbon/controlled-text-input/controlled-text-input.component";
|
25
|
+
import {
|
26
|
+
createStockItemReference,
|
27
|
+
deleteStockItemReference,
|
28
|
+
} from "../../stock-items.resource";
|
29
|
+
import {
|
30
|
+
restBaseUrl,
|
31
|
+
showNotification,
|
32
|
+
showSnackbar,
|
33
|
+
showToast,
|
34
|
+
} from "@openmrs/esm-framework";
|
35
|
+
import { extractErrorMessagesFromResponse } from "../../../constants";
|
36
|
+
import { handleMutate } from "../../../utils";
|
37
|
+
|
38
|
+
interface StockReferencesProps {
|
39
|
+
isEditing?: boolean;
|
40
|
+
onSubmit?: () => void;
|
41
|
+
stockItemUuid: string;
|
42
|
+
}
|
43
|
+
|
44
|
+
const StockReferences: React.FC<StockReferencesProps> = ({
|
45
|
+
isEditing,
|
46
|
+
stockItemUuid,
|
47
|
+
}) => {
|
48
|
+
const { t } = useTranslation();
|
49
|
+
|
50
|
+
// get stock item references
|
51
|
+
const { items, isLoading, setStockItemUuid } = useStockItemReferencesHook();
|
52
|
+
useEffect(() => {
|
53
|
+
setStockItemUuid(stockItemUuid);
|
54
|
+
}, [stockItemUuid, setStockItemUuid]);
|
55
|
+
|
56
|
+
const tableHeaders = useMemo(
|
57
|
+
() => [
|
58
|
+
{
|
59
|
+
key: "source",
|
60
|
+
header: t("source", "Source"),
|
61
|
+
styles: { width: "50%" },
|
62
|
+
},
|
63
|
+
{
|
64
|
+
key: "code",
|
65
|
+
header: t("code", "Code"),
|
66
|
+
styles: { width: "50%" },
|
67
|
+
},
|
68
|
+
{
|
69
|
+
key: "action",
|
70
|
+
header: t("action", "Actions"),
|
71
|
+
styles: { width: "50%" },
|
72
|
+
},
|
73
|
+
],
|
74
|
+
[t]
|
75
|
+
);
|
76
|
+
|
77
|
+
const stockReferenceForm = useForm<StockItemReferenceData>({
|
78
|
+
defaultValues: {},
|
79
|
+
mode: "all",
|
80
|
+
resolver: zodResolver(stockItemDetailsSchema),
|
81
|
+
});
|
82
|
+
|
83
|
+
const handleSaveStockItemReference = () => {
|
84
|
+
const { getValues } = stockReferenceForm;
|
85
|
+
const { code, references } = getValues();
|
86
|
+
|
87
|
+
const payload: StockItemReferenceDTO = {
|
88
|
+
referenceCode: code,
|
89
|
+
stockItemUuid: stockItemUuid,
|
90
|
+
stockSourceUuid: references,
|
91
|
+
};
|
92
|
+
|
93
|
+
createStockItemReference(payload).then(
|
94
|
+
() => {
|
95
|
+
handleMutate(`${restBaseUrl}/stockmanagement/stockitemreference`);
|
96
|
+
|
97
|
+
showSnackbar({
|
98
|
+
title: t("saveReferenceTitle", "StockItem Reference"),
|
99
|
+
subtitle: t(
|
100
|
+
"saveStockItemReferenceMessage",
|
101
|
+
"Stock Item Reference saved successfully"
|
102
|
+
),
|
103
|
+
kind: "success",
|
104
|
+
});
|
105
|
+
},
|
106
|
+
(error) => {
|
107
|
+
handleMutate(`${restBaseUrl}/stockmanagement/stockitemreference`);
|
108
|
+
|
109
|
+
const err = extractErrorMessagesFromResponse(error);
|
110
|
+
showSnackbar({
|
111
|
+
title: t("saveStockItemReferenceErrorTitle", "StockItem Reference"),
|
112
|
+
subtitle: t(
|
113
|
+
"saveStockItemReferenceErrorMessage",
|
114
|
+
"Error saving stock item reference" + err.join(",")
|
115
|
+
),
|
116
|
+
kind: "error",
|
117
|
+
});
|
118
|
+
}
|
119
|
+
);
|
120
|
+
};
|
121
|
+
|
122
|
+
if (isLoading)
|
123
|
+
return (
|
124
|
+
<DataTableSkeleton
|
125
|
+
showHeader={false}
|
126
|
+
rowCount={5}
|
127
|
+
columnCount={5}
|
128
|
+
zebra
|
129
|
+
/>
|
130
|
+
);
|
131
|
+
|
132
|
+
return (
|
133
|
+
<FormProvider {...stockReferenceForm}>
|
134
|
+
<DataTable
|
135
|
+
rows={items ?? []}
|
136
|
+
headers={tableHeaders}
|
137
|
+
isSortable={false}
|
138
|
+
useZebraStyles={true}
|
139
|
+
render={({ headers, getHeaderProps, getTableProps }) => (
|
140
|
+
<TableContainer className={styles.referencesTableContainer}>
|
141
|
+
<Table {...getTableProps()} className={styles.referencesTable}>
|
142
|
+
<TableHead>
|
143
|
+
<TableRow>
|
144
|
+
{headers.map((header) => (
|
145
|
+
<TableHeader
|
146
|
+
{...getHeaderProps({
|
147
|
+
header,
|
148
|
+
isSortable: false,
|
149
|
+
})}
|
150
|
+
style={header.styles}
|
151
|
+
key={header.key}
|
152
|
+
>
|
153
|
+
{header.header?.content ?? header.header}
|
154
|
+
</TableHeader>
|
155
|
+
))}
|
156
|
+
<TableHeader style={{ width: "70%" }} />
|
157
|
+
</TableRow>
|
158
|
+
</TableHead>
|
159
|
+
<TableBody className={styles.referencesTableBody}>
|
160
|
+
{items?.map((row: StockItemReferenceDTO, index) => (
|
161
|
+
<StockReferencesRow row={row} key={`${index}-${row?.uuid}`} />
|
162
|
+
))}
|
163
|
+
<StockReferencesRow row={{}} key="bottom-row" isEditing />
|
164
|
+
</TableBody>
|
165
|
+
</Table>
|
166
|
+
</TableContainer>
|
167
|
+
)}
|
168
|
+
/>
|
169
|
+
|
170
|
+
<Button
|
171
|
+
name="save"
|
172
|
+
type="submit"
|
173
|
+
className="submitButton"
|
174
|
+
onClick={handleSaveStockItemReference}
|
175
|
+
kind="primary"
|
176
|
+
renderIcon={Save}
|
177
|
+
>
|
178
|
+
{t("save", "Save")}
|
179
|
+
</Button>
|
180
|
+
</FormProvider>
|
181
|
+
);
|
182
|
+
};
|
183
|
+
export default StockReferences;
|
184
|
+
|
185
|
+
const StockReferencesRow: React.FC<{
|
186
|
+
isEditing?: boolean;
|
187
|
+
row: StockItemReferenceDTO;
|
188
|
+
key?: string;
|
189
|
+
}> = ({ isEditing, row, key }) => {
|
190
|
+
const { t } = useTranslation();
|
191
|
+
|
192
|
+
const {
|
193
|
+
control,
|
194
|
+
formState: { errors },
|
195
|
+
} = useFormContext();
|
196
|
+
|
197
|
+
const handleDelete = (e) => {
|
198
|
+
e.preventDefault();
|
199
|
+
deleteStockItemReference(row.uuid).then(
|
200
|
+
() => {
|
201
|
+
showSnackbar({
|
202
|
+
title: t("deletePackagingUnitTitle", `Delete StockItem reference`),
|
203
|
+
kind: "success",
|
204
|
+
subtitle: t(
|
205
|
+
"deleteStockItemReferenceMesaage",
|
206
|
+
`StockItem reference deleted Successfully`
|
207
|
+
),
|
208
|
+
});
|
209
|
+
},
|
210
|
+
(error) => {
|
211
|
+
const err = extractErrorMessagesFromResponse(error);
|
212
|
+
showSnackbar({
|
213
|
+
title: t(
|
214
|
+
"deleteStockItemReferenceTitle",
|
215
|
+
`Error Deleting a stockitem reference`
|
216
|
+
),
|
217
|
+
kind: "error",
|
218
|
+
subtitle: err.join(","),
|
219
|
+
});
|
220
|
+
}
|
221
|
+
);
|
222
|
+
};
|
223
|
+
|
224
|
+
return (
|
225
|
+
<TableRow>
|
226
|
+
<TableCell>
|
227
|
+
{isEditing ? (
|
228
|
+
<StockSourceSelector
|
229
|
+
row={row}
|
230
|
+
name="references"
|
231
|
+
controllerName={"references"}
|
232
|
+
control={control}
|
233
|
+
placeholder={t("filter", "Filter...")}
|
234
|
+
/>
|
235
|
+
) : (
|
236
|
+
(!isEditing || !row.uuid.startsWith("new-item")) &&
|
237
|
+
row?.stockSourceName
|
238
|
+
)}
|
239
|
+
</TableCell>
|
240
|
+
<TableCell>
|
241
|
+
<div className={styles.referencesTableCell}>
|
242
|
+
<ControlledTextInput
|
243
|
+
id={`${row.uuid}-${key}`}
|
244
|
+
name="code"
|
245
|
+
control={control}
|
246
|
+
size={"md"}
|
247
|
+
value={row?.referenceCode ?? ""}
|
248
|
+
controllerName="code"
|
249
|
+
labelText={""}
|
250
|
+
/>
|
251
|
+
<Button
|
252
|
+
type="button"
|
253
|
+
size="sm"
|
254
|
+
className="submitButton clear-padding-margin"
|
255
|
+
iconDescription={"Delete"}
|
256
|
+
kind="ghost"
|
257
|
+
renderIcon={TrashCan}
|
258
|
+
onClick={(e) => handleDelete(e)}
|
259
|
+
/>
|
260
|
+
</div>
|
261
|
+
</TableCell>
|
262
|
+
</TableRow>
|
263
|
+
);
|
264
|
+
};
|
package/src/stock-items/add-stock-item/stock-item-references/stock-item-references.resource.ts
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
import { ResourceRepresentation } from "../../../core/api/api";
|
2
|
+
import {
|
3
|
+
StockItemReferenceFilter,
|
4
|
+
useStockItemReferences,
|
5
|
+
} from "../../stock-items.resource";
|
6
|
+
import { useEffect, useState } from "react";
|
7
|
+
|
8
|
+
export function useStockItemReferencesHook(v?: ResourceRepresentation) {
|
9
|
+
const [stockItemReferenceFilter, setStockItemReferenceFilter] =
|
10
|
+
useState<StockItemReferenceFilter>({
|
11
|
+
startIndex: 0,
|
12
|
+
v: v || ResourceRepresentation.Default,
|
13
|
+
q: null,
|
14
|
+
totalCount: true,
|
15
|
+
});
|
16
|
+
|
17
|
+
const [stockItemUuid, setStockItemUuid] = useState<string | null>();
|
18
|
+
|
19
|
+
useEffect(() => {
|
20
|
+
setStockItemReferenceFilter({
|
21
|
+
startIndex: 0,
|
22
|
+
v: ResourceRepresentation.Default,
|
23
|
+
totalCount: true,
|
24
|
+
stockItemUuid: stockItemUuid,
|
25
|
+
});
|
26
|
+
}, [stockItemUuid]);
|
27
|
+
|
28
|
+
const { items, isLoading, isError } = useStockItemReferences(
|
29
|
+
stockItemReferenceFilter
|
30
|
+
);
|
31
|
+
|
32
|
+
return {
|
33
|
+
items: items.results,
|
34
|
+
totalCount: items.totalCount,
|
35
|
+
isLoading,
|
36
|
+
isError,
|
37
|
+
setStockItemUuid,
|
38
|
+
};
|
39
|
+
}
|
@@ -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;
|
@@ -67,7 +67,10 @@ const StockRulesAddOrUpdate: React.FC<AddStockRuleProps> = ({
|
|
67
67
|
isLoading: loadingRoles,
|
68
68
|
} = useRoles({ v: ResourceRepresentation.Default });
|
69
69
|
|
70
|
-
const [formModel, setFormModel] = useState<StockRule>(
|
70
|
+
const [formModel, setFormModel] = useState<StockRule>({
|
71
|
+
enabled: true,
|
72
|
+
...model,
|
73
|
+
});
|
71
74
|
|
72
75
|
useEffect(() => {
|
73
76
|
if (model != null && Object.keys(model).length != 0) {
|
@@ -190,7 +193,7 @@ const StockRulesAddOrUpdate: React.FC<AddStockRuleProps> = ({
|
|
190
193
|
)
|
191
194
|
.catch();
|
192
195
|
},
|
193
|
-
[formModel, model, t]
|
196
|
+
[formModel, model, t, stockItemUuid]
|
194
197
|
);
|
195
198
|
|
196
199
|
return (
|
@@ -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"),
|