@openmrs/esm-stock-management-app 1.0.1-pre.417 → 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-reports/generate-report/create-stock-report.component.tsx +59 -3
- package/src/stock-reports/report-validation-schema.ts +73 -36
- 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(() => {
|
@@ -355,7 +355,7 @@ const CreateReport: React.FC<CreateReportProps> = ({ model }) => {
|
|
355
355
|
if (displayDate) {
|
356
356
|
parameters += getReportParameter(
|
357
357
|
ReportParameter.Date,
|
358
|
-
JSON.stringify(report.date).replaceAll('"', ""),
|
358
|
+
report.date ? JSON.stringify(report.date).replaceAll('"', "") : "",
|
359
359
|
formatDisplayDate(report.date) ?? "",
|
360
360
|
t("stockmanagement.report.edit.date"),
|
361
361
|
newLine
|
@@ -364,7 +364,9 @@ const CreateReport: React.FC<CreateReportProps> = ({ model }) => {
|
|
364
364
|
if (displayStartDate) {
|
365
365
|
parameters += getReportParameter(
|
366
366
|
ReportParameter.StartDate,
|
367
|
-
|
367
|
+
report.startDate
|
368
|
+
? JSON.stringify(report.startDate).replaceAll('"', "")
|
369
|
+
: "",
|
368
370
|
formatDisplayDate(report.startDate) ?? "",
|
369
371
|
t(getReportStartDateLabel(report.reportSystemName)),
|
370
372
|
newLine
|
@@ -373,7 +375,9 @@ const CreateReport: React.FC<CreateReportProps> = ({ model }) => {
|
|
373
375
|
if (displayEndDate) {
|
374
376
|
parameters += getReportParameter(
|
375
377
|
ReportParameter.EndDate,
|
376
|
-
|
378
|
+
report.endDate
|
379
|
+
? JSON.stringify(report.endDate).replaceAll('"', "")
|
380
|
+
: "",
|
377
381
|
formatDisplayDate(report.endDate) ?? "",
|
378
382
|
t(getReportEndDateLabel(report.reportSystemName)),
|
379
383
|
newLine
|
@@ -529,6 +533,30 @@ const CreateReport: React.FC<CreateReportProps> = ({ model }) => {
|
|
529
533
|
)}
|
530
534
|
/>
|
531
535
|
)}
|
536
|
+
{displayInventoryGroupBy && (
|
537
|
+
<Select
|
538
|
+
id="inventoryGroupBy"
|
539
|
+
defaultValue={model?.inventoryGroupBy}
|
540
|
+
invalid={errors?.inventoryGroupBy?.message}
|
541
|
+
invalidText={errors?.inventoryGroupBy?.message}
|
542
|
+
labelText={t("inventoryBy", "Inventory by")}
|
543
|
+
onChange={(e) => setValue("inventoryGroupBy", e.target.value)}
|
544
|
+
>
|
545
|
+
<SelectItem value="" text={t("SelectOption", "Select an option")} />
|
546
|
+
<SelectItem
|
547
|
+
value="StockItemOnly"
|
548
|
+
text={t("stockItem", "Stock Item")}
|
549
|
+
/>
|
550
|
+
<SelectItem
|
551
|
+
value="LocationStockItem"
|
552
|
+
text={t("lcationstockitem", "Location and Stock Item")}
|
553
|
+
/>
|
554
|
+
<SelectItem
|
555
|
+
value="LocationStockItemBatchNo"
|
556
|
+
text={t("locationBatchno", "Location and Batch")}
|
557
|
+
/>
|
558
|
+
</Select>
|
559
|
+
)}
|
532
560
|
{displayLocation && (
|
533
561
|
<Select
|
534
562
|
name="location"
|
@@ -537,6 +565,8 @@ const CreateReport: React.FC<CreateReportProps> = ({ model }) => {
|
|
537
565
|
id="location"
|
538
566
|
onChange={(e) => setValue("location", e.target.value)}
|
539
567
|
defaultValue=""
|
568
|
+
invalid={errors?.location?.message}
|
569
|
+
invalidText={errors?.location?.message}
|
540
570
|
>
|
541
571
|
<SelectItem
|
542
572
|
disabled
|
@@ -674,6 +704,32 @@ const CreateReport: React.FC<CreateReportProps> = ({ model }) => {
|
|
674
704
|
/>
|
675
705
|
</div>
|
676
706
|
)}
|
707
|
+
{displayDate && (
|
708
|
+
<Controller
|
709
|
+
control={control}
|
710
|
+
name="date"
|
711
|
+
render={({ field: { onChange, value } }) => (
|
712
|
+
<DatePicker
|
713
|
+
datePickerType="single"
|
714
|
+
maxDate={formatForDatePicker(today())}
|
715
|
+
locale="en"
|
716
|
+
dateFormat={DATE_PICKER_CONTROL_FORMAT}
|
717
|
+
onChange={onChange}
|
718
|
+
value={value}
|
719
|
+
>
|
720
|
+
<DatePickerInput
|
721
|
+
id="date"
|
722
|
+
name="date"
|
723
|
+
placeholder={DATE_PICKER_FORMAT}
|
724
|
+
labelText={t("date", "Date")}
|
725
|
+
defaultValue=""
|
726
|
+
invalid={errors?.date?.message}
|
727
|
+
invalidText={errors?.date?.message}
|
728
|
+
/>
|
729
|
+
</DatePicker>
|
730
|
+
)}
|
731
|
+
/>
|
732
|
+
)}
|
677
733
|
</div>
|
678
734
|
<div className={styles.reportButton}>
|
679
735
|
<Button kind="secondary" onClick={closeOverlay}>
|
@@ -1,40 +1,77 @@
|
|
1
1
|
import { z } from "zod";
|
2
2
|
|
3
|
-
export const reportSchema = z
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
3
|
+
export const reportSchema = z
|
4
|
+
.object({
|
5
|
+
startDate: z.coerce.date().optional(),
|
6
|
+
endDate: z.coerce.date().optional(),
|
7
|
+
location: z.string({ required_error: "Location Required" }).min(1, {
|
8
|
+
message: "Location Required",
|
9
|
+
}),
|
10
|
+
reportName: z.string({ required_error: "Report Name Required" }).min(1, {
|
11
|
+
message: "Report Name Required",
|
12
|
+
}),
|
13
|
+
stockReportItemCategory: z.string().optional(),
|
14
|
+
mostLeastMoving: z.string().optional(),
|
15
|
+
mostLeastMovingName: z.string().optional(),
|
16
|
+
stockItemUuid: z.string().optional(),
|
17
|
+
stockItemName: z.string().optional(),
|
18
|
+
patientUuid: z.string().optional(),
|
19
|
+
patientName: z.string().optional(),
|
20
|
+
locationUuid: z.string().optional(),
|
21
|
+
childLocations: z.boolean().optional(),
|
22
|
+
stockSourceUuid: z.string().optional(),
|
23
|
+
stockSource: z.string().optional(),
|
24
|
+
stockSourceDestinationUuid: z.string().optional(),
|
25
|
+
stockSourceDestination: z.string().optional(),
|
26
|
+
inventoryGroupBy: z.string().optional(),
|
27
|
+
stockItemCategory: z.string().optional(),
|
28
|
+
inventoryGroupByName: z.string().optional(),
|
29
|
+
stockItemCategoryConceptUuid: z.string().optional(),
|
30
|
+
reportSystemName: z.string().optional(),
|
31
|
+
maxReorderLevelRatio: z.number().optional(),
|
32
|
+
fullFillment: z.string().array().optional(),
|
33
|
+
limit: z.string().optional(),
|
34
|
+
date: z.coerce.date().optional(),
|
35
|
+
})
|
36
|
+
.superRefine((data, ctx) => {
|
37
|
+
if (
|
38
|
+
data.reportName !== "Stock Status Report" &&
|
39
|
+
data.reportName !== "Stock-Out Report"
|
40
|
+
) {
|
41
|
+
if (!data.startDate) {
|
42
|
+
ctx.addIssue({
|
43
|
+
code: z.ZodIssueCode.custom,
|
44
|
+
message: "Start Date is required ",
|
45
|
+
path: ["startDate"],
|
46
|
+
});
|
47
|
+
}
|
48
|
+
if (!data.endDate) {
|
49
|
+
ctx.addIssue({
|
50
|
+
code: z.ZodIssueCode.custom,
|
51
|
+
message: "End Date is required",
|
52
|
+
path: ["endDate"],
|
53
|
+
});
|
54
|
+
}
|
55
|
+
}
|
56
|
+
if (
|
57
|
+
data.reportName === "Stock Status Report" ||
|
58
|
+
data.reportName === "Stock-Out Report"
|
59
|
+
) {
|
60
|
+
if (!data.date) {
|
61
|
+
ctx.addIssue({
|
62
|
+
code: z.ZodIssueCode.custom,
|
63
|
+
message: "Date is required ",
|
64
|
+
path: ["date"],
|
65
|
+
});
|
66
|
+
}
|
67
|
+
if (!data.inventoryGroupBy) {
|
68
|
+
ctx.addIssue({
|
69
|
+
code: z.ZodIssueCode.custom,
|
70
|
+
message: "Inventory by is required ",
|
71
|
+
path: ["inventoryGroupBy"],
|
72
|
+
});
|
73
|
+
}
|
74
|
+
}
|
75
|
+
});
|
39
76
|
|
40
77
|
export type StockReportSchema = z.infer<typeof reportSchema>;
|
@@ -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
|
+
};
|