@openmrs/esm-billing-app 1.0.2-pre.76 → 1.0.2-pre.761
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -9
- package/__mocks__/bills.mock.ts +12 -0
- package/__mocks__/react-i18next.js +6 -5
- package/dist/1119.js +1 -1
- package/dist/1146.js +1 -2
- package/dist/1146.js.map +1 -1
- package/dist/1197.js +1 -1
- package/dist/1856.js +1 -0
- package/dist/1856.js.map +1 -0
- package/dist/2146.js +1 -1
- package/dist/2177.js +2 -0
- package/dist/2177.js.LICENSE.txt +9 -0
- package/dist/2177.js.map +1 -0
- package/dist/2524.js +1 -0
- package/dist/2524.js.map +1 -0
- package/dist/2690.js +1 -1
- package/dist/3041.js +1 -0
- package/dist/3041.js.map +1 -0
- package/dist/3099.js +1 -1
- package/dist/3584.js +1 -1
- package/dist/4055.js +1 -1
- package/dist/4132.js +1 -1
- package/dist/4225.js +1 -0
- package/dist/4225.js.map +1 -0
- package/dist/4300.js +1 -1
- package/dist/4335.js +1 -1
- package/dist/4618.js +1 -1
- package/dist/4652.js +1 -1
- package/dist/4724.js +1 -0
- package/dist/4724.js.map +1 -0
- package/dist/4739.js +1 -1
- package/dist/4739.js.map +1 -1
- package/dist/4944.js +1 -1
- package/dist/5173.js +1 -1
- package/dist/5241.js +1 -1
- package/dist/5422.js +1 -0
- package/dist/5422.js.map +1 -0
- package/dist/5442.js +1 -1
- package/dist/5661.js +1 -1
- package/dist/6022.js +1 -1
- package/dist/6468.js +1 -1
- package/dist/6540.js +1 -1
- package/dist/6540.js.map +1 -1
- package/dist/6606.js +1 -0
- package/dist/6606.js.map +1 -0
- package/dist/6679.js +1 -1
- package/dist/6840.js +1 -1
- package/dist/6859.js +1 -1
- package/dist/7097.js +1 -1
- package/dist/7159.js +1 -1
- package/dist/723.js +1 -1
- package/dist/7452.js +2 -0
- package/dist/7452.js.map +1 -0
- package/dist/7617.js +1 -1
- package/dist/795.js +1 -1
- package/dist/8163.js +1 -1
- package/dist/8349.js +1 -1
- package/dist/8618.js +1 -1
- package/dist/890.js +1 -1
- package/dist/8930.js +2 -0
- package/dist/{6525.js.LICENSE.txt → 8930.js.LICENSE.txt} +16 -4
- package/dist/8930.js.map +1 -0
- package/dist/9214.js +1 -1
- package/dist/942.js +1 -0
- package/dist/942.js.map +1 -0
- package/dist/9538.js +1 -1
- package/dist/9569.js +1 -1
- package/dist/961.js +1 -1
- package/dist/961.js.map +1 -1
- package/dist/986.js +1 -1
- package/dist/9879.js +1 -1
- package/dist/9895.js +1 -1
- package/dist/9900.js +1 -1
- package/dist/9913.js +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-billing-app.js +1 -1
- package/dist/openmrs-esm-billing-app.js.buildmanifest.json +368 -262
- package/dist/openmrs-esm-billing-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/e2e/README.md +19 -18
- package/e2e/specs/sample-test.spec.ts +0 -1
- package/package.json +10 -10
- package/src/bill-history/bill-history.component.tsx +17 -25
- package/src/bill-history/bill-history.scss +4 -94
- package/src/bill-history/bill-history.test.tsx +37 -78
- package/src/bill-item-actions/bill-item-actions.scss +0 -4
- package/src/bill-item-actions/{edit-bill-item.component.tsx → edit-bill-item.modal.tsx} +57 -56
- package/src/bill-item-actions/edit-bill-item.test.tsx +22 -25
- package/src/billable-services/bill-waiver/bill-selection.component.tsx +2 -2
- package/src/billable-services/bill-waiver/patient-bills.component.tsx +3 -3
- package/src/billable-services/billable-service.resource.ts +17 -9
- package/src/billable-services/billable-services-home.component.tsx +1 -1
- package/src/billable-services/billable-services.component.tsx +142 -145
- package/src/billable-services/billable-services.scss +3 -0
- package/src/billable-services/billable-services.test.tsx +2 -45
- package/src/billable-services/cash-point/add-cash-point.modal.tsx +168 -0
- package/src/billable-services/cash-point/cash-point-configuration.component.tsx +18 -192
- package/src/billable-services/cash-point/cash-point-configuration.scss +1 -5
- package/src/billable-services/create-edit/add-billable-service.component.tsx +345 -298
- package/src/billable-services/create-edit/add-billable-service.scss +5 -6
- package/src/billable-services/create-edit/add-billable-service.test.tsx +37 -36
- package/src/billable-services/create-edit/edit-billable-service.modal.tsx +51 -0
- package/src/billable-services/payment-modes/add-payment-mode.modal.tsx +121 -0
- package/src/billable-services/payment-modes/delete-payment-mode.modal.tsx +72 -0
- package/src/billable-services/payment-modes/payment-modes-config.component.tsx +125 -0
- package/src/billable-services/{payyment-modes → payment-modes}/payment-modes-config.scss +5 -4
- package/src/billing-form/billing-checkin-form.component.tsx +2 -3
- package/src/billing-form/billing-checkin-form.test.tsx +97 -24
- package/src/billing-form/billing-form.component.tsx +214 -269
- package/src/billing-form/billing-form.scss +143 -0
- package/src/billing.resource.ts +16 -19
- package/src/bills-table/bills-table.test.tsx +97 -53
- package/src/config-schema.ts +52 -18
- package/src/dashboard.meta.ts +4 -2
- package/src/helpers/functions.ts +5 -4
- package/src/index.ts +17 -6
- package/src/invoice/invoice-table.component.tsx +24 -54
- package/src/invoice/invoice-table.scss +1 -5
- package/src/invoice/invoice-table.test.tsx +21 -47
- package/src/invoice/invoice.component.tsx +36 -29
- package/src/invoice/invoice.scss +7 -4
- package/src/invoice/invoice.test.tsx +22 -48
- package/src/invoice/payments/payment-form/payment-form.component.tsx +29 -29
- package/src/invoice/payments/payment-form/payment-form.scss +5 -6
- package/src/invoice/payments/payment-form/payment-form.test.tsx +215 -67
- package/src/invoice/payments/payment-history/payment-history.component.tsx +6 -4
- package/src/invoice/payments/payment-history/payment-history.test.tsx +9 -14
- package/src/invoice/payments/payments.component.tsx +53 -65
- package/src/invoice/payments/payments.test.tsx +282 -0
- package/src/invoice/payments/utils.ts +5 -23
- package/src/invoice/printable-invoice/print-receipt.component.tsx +3 -2
- package/src/invoice/printable-invoice/print-receipt.test.tsx +14 -25
- package/src/invoice/printable-invoice/printable-footer.component.tsx +2 -2
- package/src/invoice/printable-invoice/printable-footer.test.tsx +4 -13
- package/src/invoice/printable-invoice/printable-invoice-header.component.tsx +12 -11
- package/src/invoice/printable-invoice/printable-invoice-header.test.tsx +16 -14
- package/src/invoice/printable-invoice/printable-invoice.component.tsx +19 -33
- package/src/metrics-cards/metrics-cards.test.tsx +18 -5
- package/src/modal/require-payment-modal.test.tsx +27 -22
- package/src/modal/{require-payment-modal.component.tsx → require-payment.modal.tsx} +17 -18
- package/src/routes.json +22 -2
- package/src/types/index.ts +26 -17
- package/translations/am.json +60 -18
- package/translations/ar.json +60 -18
- package/translations/ar_SY.json +60 -18
- package/translations/bn.json +65 -23
- package/translations/de.json +60 -18
- package/translations/en.json +60 -18
- package/translations/en_US.json +60 -18
- package/translations/es.json +60 -18
- package/translations/es_MX.json +60 -18
- package/translations/fr.json +73 -31
- package/translations/he.json +60 -18
- package/translations/hi.json +60 -18
- package/translations/hi_IN.json +60 -18
- package/translations/id.json +61 -19
- package/translations/it.json +96 -54
- package/translations/ka.json +61 -19
- package/translations/km.json +60 -18
- package/translations/ku.json +60 -18
- package/translations/ky.json +60 -18
- package/translations/lg.json +60 -18
- package/translations/ne.json +60 -18
- package/translations/pl.json +60 -18
- package/translations/pt.json +60 -18
- package/translations/pt_BR.json +60 -18
- package/translations/qu.json +60 -18
- package/translations/ro_RO.json +206 -164
- package/translations/ru_RU.json +60 -18
- package/translations/si.json +60 -18
- package/translations/sw.json +60 -18
- package/translations/sw_KE.json +60 -18
- package/translations/tr.json +60 -18
- package/translations/tr_TR.json +60 -18
- package/translations/uk.json +60 -18
- package/translations/uz.json +60 -18
- package/translations/uz@Latn.json +60 -18
- package/translations/uz_UZ.json +60 -18
- package/translations/vi.json +60 -18
- package/translations/zh.json +60 -18
- package/translations/zh_CN.json +117 -75
- package/dist/1146.js.LICENSE.txt +0 -21
- package/dist/2352.js +0 -1
- package/dist/2352.js.map +0 -1
- package/dist/246.js +0 -1
- package/dist/246.js.map +0 -1
- package/dist/6525.js +0 -2
- package/dist/6525.js.map +0 -1
- package/dist/8556.js +0 -2
- package/dist/8556.js.map +0 -1
- package/dist/8638.js +0 -1
- package/dist/8638.js.map +0 -1
- package/dist/9968.js +0 -1
- package/dist/9968.js.map +0 -1
- package/src/billable-services/payyment-modes/payment-modes-config.component.tsx +0 -280
- package/src/invoice/payments/payments.component.test.tsx +0 -121
- /package/dist/{8556.js.LICENSE.txt → 7452.js.LICENSE.txt} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useRef, useState, useEffect, useMemo } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
Button,
|
|
4
4
|
ComboBox,
|
|
@@ -8,88 +8,160 @@ import {
|
|
|
8
8
|
InlineLoading,
|
|
9
9
|
Layer,
|
|
10
10
|
Search,
|
|
11
|
+
Stack,
|
|
11
12
|
TextInput,
|
|
12
13
|
Tile,
|
|
13
14
|
} from '@carbon/react';
|
|
14
|
-
import { Add, TrashCan
|
|
15
|
-
import { Controller, useFieldArray, useForm } from 'react-hook-form';
|
|
15
|
+
import { Add, TrashCan } from '@carbon/react/icons';
|
|
16
|
+
import { Controller, useFieldArray, useForm, useWatch } from 'react-hook-form';
|
|
16
17
|
import { useTranslation } from 'react-i18next';
|
|
18
|
+
import { type TFunction } from 'i18next';
|
|
17
19
|
import { z } from 'zod';
|
|
18
20
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
19
|
-
import { navigate, showSnackbar, useDebounce
|
|
21
|
+
import { getCoreTranslation, navigate, ResponsiveWrapper, showSnackbar, useDebounce } from '@openmrs/esm-framework';
|
|
20
22
|
import {
|
|
21
|
-
|
|
23
|
+
createBillableService,
|
|
22
24
|
updateBillableService,
|
|
23
25
|
useConceptsSearch,
|
|
24
26
|
usePaymentModes,
|
|
25
27
|
useServiceTypes,
|
|
26
28
|
} from '../billable-service.resource';
|
|
27
|
-
import { type ServiceConcept } from '../../types';
|
|
29
|
+
import { type BillableService, type ServiceConcept, type ServicePrice } from '../../types';
|
|
28
30
|
import styles from './add-billable-service.scss';
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
interface ServiceType {
|
|
33
|
+
uuid: string;
|
|
34
|
+
display: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface PaymentModeForm {
|
|
31
38
|
paymentMode: string;
|
|
32
39
|
price: string | number;
|
|
33
|
-
}
|
|
40
|
+
}
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
interface BillableServiceFormData {
|
|
43
|
+
name: string;
|
|
44
|
+
shortName?: string;
|
|
45
|
+
serviceType: ServiceType | null;
|
|
46
|
+
concept?: ServiceConcept | null;
|
|
47
|
+
payment: PaymentModeForm[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface AddBillableServiceProps {
|
|
51
|
+
serviceToEdit?: BillableService;
|
|
52
|
+
onClose: () => void;
|
|
53
|
+
onServiceUpdated?: () => void;
|
|
54
|
+
isModal?: boolean;
|
|
55
|
+
}
|
|
38
56
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
price: z.union([
|
|
42
|
-
z.number().refine((value) => !!value, 'Price is required'),
|
|
43
|
-
z.string().refine((value) => !!value, 'Price is required'),
|
|
44
|
-
]),
|
|
45
|
-
});
|
|
57
|
+
const DEFAULT_PAYMENT_OPTION: PaymentModeForm = { paymentMode: '', price: 0 };
|
|
58
|
+
const MAX_NAME_LENGTH = 19;
|
|
46
59
|
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
const createBillableServiceSchema = (t: TFunction) => {
|
|
61
|
+
const servicePriceSchema = z.object({
|
|
62
|
+
paymentMode: z
|
|
63
|
+
.string({
|
|
64
|
+
required_error: t('paymentModeRequired', 'Payment mode is required'),
|
|
65
|
+
})
|
|
66
|
+
.trim()
|
|
67
|
+
.min(1, t('paymentModeRequired', 'Payment mode is required')),
|
|
68
|
+
price: z.union([
|
|
69
|
+
z.number().positive(t('priceMustBeGreaterThanZero', 'Price must be greater than 0')),
|
|
70
|
+
z
|
|
71
|
+
.string({
|
|
72
|
+
required_error: t('priceIsRequired', 'Price is required'),
|
|
73
|
+
})
|
|
74
|
+
.trim()
|
|
75
|
+
.min(1, t('priceIsRequired', 'Price is required'))
|
|
76
|
+
.refine(
|
|
77
|
+
(val) => !isNaN(parseFloat(val)) && parseFloat(val) > 0,
|
|
78
|
+
t('priceMustBeValidPositiveNumber', 'Price must be a valid positive number'),
|
|
79
|
+
),
|
|
80
|
+
]),
|
|
81
|
+
});
|
|
50
82
|
|
|
51
|
-
|
|
83
|
+
return z.object({
|
|
84
|
+
name: z
|
|
85
|
+
.string({
|
|
86
|
+
required_error: t('serviceNameRequired', 'Service name is required'),
|
|
87
|
+
})
|
|
88
|
+
.trim()
|
|
89
|
+
.min(1, t('serviceNameRequired', 'Service name is required'))
|
|
90
|
+
.max(
|
|
91
|
+
MAX_NAME_LENGTH,
|
|
92
|
+
t('serviceNameExceedsLimit', 'Service name cannot exceed {{MAX_NAME_LENGTH}} characters', {
|
|
93
|
+
MAX_NAME_LENGTH,
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
96
|
+
shortName: z
|
|
97
|
+
.string()
|
|
98
|
+
.max(
|
|
99
|
+
MAX_NAME_LENGTH,
|
|
100
|
+
t('shortNameExceedsLimit', 'Short name cannot exceed {{MAX_NAME_LENGTH}} characters', { MAX_NAME_LENGTH }),
|
|
101
|
+
)
|
|
102
|
+
.optional(),
|
|
103
|
+
serviceType: z
|
|
104
|
+
.object({
|
|
105
|
+
uuid: z.string(),
|
|
106
|
+
display: z.string(),
|
|
107
|
+
})
|
|
108
|
+
.nullable()
|
|
109
|
+
.refine((val) => val !== null, t('serviceTypeRequired', 'Service type is required')),
|
|
110
|
+
concept: z
|
|
111
|
+
.object({
|
|
112
|
+
uuid: z.string(),
|
|
113
|
+
display: z.string(),
|
|
114
|
+
})
|
|
115
|
+
.nullable()
|
|
116
|
+
.optional(),
|
|
117
|
+
payment: z.array(servicePriceSchema).min(1, t('paymentOptionRequired', 'At least one payment option is required')),
|
|
118
|
+
});
|
|
119
|
+
};
|
|
52
120
|
|
|
53
|
-
const AddBillableService: React.FC<
|
|
121
|
+
const AddBillableService: React.FC<AddBillableServiceProps> = ({
|
|
122
|
+
serviceToEdit,
|
|
123
|
+
onClose,
|
|
124
|
+
onServiceUpdated,
|
|
125
|
+
isModal = false,
|
|
126
|
+
}) => {
|
|
54
127
|
const { t } = useTranslation();
|
|
55
128
|
|
|
56
|
-
const { paymentModes,
|
|
57
|
-
const { serviceTypes,
|
|
58
|
-
|
|
129
|
+
const { paymentModes, isLoadingPaymentModes } = usePaymentModes();
|
|
130
|
+
const { serviceTypes, isLoadingServiceTypes } = useServiceTypes();
|
|
131
|
+
|
|
132
|
+
const billableServiceSchema = useMemo(() => createBillableServiceSchema(t), [t]);
|
|
59
133
|
|
|
60
134
|
const {
|
|
61
135
|
control,
|
|
62
136
|
handleSubmit,
|
|
63
|
-
formState: { errors
|
|
137
|
+
formState: { errors },
|
|
64
138
|
setValue,
|
|
65
|
-
|
|
139
|
+
reset,
|
|
140
|
+
} = useForm<BillableServiceFormData>({
|
|
66
141
|
mode: 'all',
|
|
67
142
|
defaultValues: {
|
|
68
|
-
name:
|
|
69
|
-
|
|
70
|
-
serviceType:
|
|
71
|
-
|
|
72
|
-
payment:
|
|
143
|
+
name: serviceToEdit?.name || '',
|
|
144
|
+
shortName: serviceToEdit?.shortName || '',
|
|
145
|
+
serviceType: serviceToEdit?.serviceType || null,
|
|
146
|
+
concept: serviceToEdit?.concept || null,
|
|
147
|
+
payment: serviceToEdit?.servicePrices?.map((servicePrice: ServicePrice) => ({
|
|
148
|
+
paymentMode: servicePrice.paymentMode?.uuid || '',
|
|
149
|
+
price: servicePrice.price,
|
|
150
|
+
})) || [DEFAULT_PAYMENT_OPTION],
|
|
73
151
|
},
|
|
74
|
-
resolver: zodResolver(
|
|
75
|
-
shouldUnregister: !editingService,
|
|
152
|
+
resolver: zodResolver(billableServiceSchema),
|
|
76
153
|
});
|
|
77
|
-
const { fields, remove, append } = useFieldArray({ name: 'payment', control
|
|
154
|
+
const { fields, remove, append } = useFieldArray({ name: 'payment', control });
|
|
78
155
|
|
|
79
|
-
const handleAppendPaymentMode =
|
|
80
|
-
const handleRemovePaymentMode =
|
|
156
|
+
const handleAppendPaymentMode = () => append(DEFAULT_PAYMENT_OPTION);
|
|
157
|
+
const handleRemovePaymentMode = (index: number) => remove(index);
|
|
81
158
|
|
|
82
|
-
const isTablet = useLayoutType() === 'tablet';
|
|
83
159
|
const searchInputRef = useRef(null);
|
|
84
|
-
const handleSearchTermChange = (event: React.ChangeEvent<HTMLInputElement>) => setSearchTerm(event.target.value);
|
|
85
160
|
|
|
86
|
-
const
|
|
161
|
+
const selectedConcept = useWatch({ control, name: 'concept' });
|
|
87
162
|
const [searchTerm, setSearchTerm] = useState('');
|
|
88
|
-
const debouncedSearchTerm = useDebounce(searchTerm);
|
|
163
|
+
const debouncedSearchTerm = useDebounce(searchTerm.trim());
|
|
89
164
|
const { searchResults, isSearching } = useConceptsSearch(debouncedSearchTerm);
|
|
90
|
-
const handleConceptChange = useCallback((selectedConcept: any) => {
|
|
91
|
-
setSelectedConcept(selectedConcept);
|
|
92
|
-
}, []);
|
|
93
165
|
|
|
94
166
|
const handleNavigateToServiceDashboard = () =>
|
|
95
167
|
navigate({
|
|
@@ -97,66 +169,63 @@ const AddBillableService: React.FC<{ editingService?: any; onClose: () => void }
|
|
|
97
169
|
});
|
|
98
170
|
|
|
99
171
|
useEffect(() => {
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
editingService.servicePrices.map((payment) => ({
|
|
172
|
+
if (serviceToEdit && !isLoadingPaymentModes && !isLoadingServiceTypes) {
|
|
173
|
+
reset({
|
|
174
|
+
name: serviceToEdit.name || '',
|
|
175
|
+
shortName: serviceToEdit.shortName || '',
|
|
176
|
+
serviceType: serviceToEdit.serviceType || null,
|
|
177
|
+
concept: serviceToEdit.concept || null,
|
|
178
|
+
payment: serviceToEdit.servicePrices.map((payment: ServicePrice) => ({
|
|
108
179
|
paymentMode: payment.paymentMode?.uuid || '',
|
|
109
180
|
price: payment.price,
|
|
110
181
|
})),
|
|
111
|
-
);
|
|
112
|
-
setValue('conceptsSearch', editingService.concept);
|
|
113
|
-
|
|
114
|
-
if (editingService.concept) {
|
|
115
|
-
setSelectedConcept(editingService.concept);
|
|
116
|
-
}
|
|
182
|
+
});
|
|
117
183
|
}
|
|
118
|
-
}, [
|
|
184
|
+
}, [serviceToEdit, isLoadingPaymentModes, reset, isLoadingServiceTypes]);
|
|
119
185
|
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
const onSubmit = (data) => {
|
|
186
|
+
const onSubmit = async (data: BillableServiceFormData) => {
|
|
123
187
|
const payload = {
|
|
124
|
-
name:
|
|
125
|
-
shortName:
|
|
126
|
-
serviceType:
|
|
188
|
+
name: data.name,
|
|
189
|
+
shortName: data.shortName || '',
|
|
190
|
+
serviceType: data.serviceType!.uuid,
|
|
127
191
|
servicePrices: data.payment.map((payment) => {
|
|
128
192
|
const mode = paymentModes.find((m) => m.uuid === payment.paymentMode);
|
|
129
193
|
return {
|
|
130
194
|
paymentMode: payment.paymentMode,
|
|
131
195
|
name: mode?.name || 'Unknown',
|
|
132
|
-
price: parseFloat(payment.price),
|
|
196
|
+
price: typeof payment.price === 'string' ? parseFloat(payment.price) : payment.price,
|
|
133
197
|
};
|
|
134
198
|
}),
|
|
135
199
|
serviceStatus: 'ENABLED',
|
|
136
|
-
concept:
|
|
200
|
+
concept: data.concept?.uuid,
|
|
137
201
|
};
|
|
138
202
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
203
|
+
try {
|
|
204
|
+
if (serviceToEdit) {
|
|
205
|
+
await updateBillableService(serviceToEdit.uuid, payload);
|
|
206
|
+
} else {
|
|
207
|
+
await createBillableService(payload);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
showSnackbar({
|
|
211
|
+
title: t('billableService', 'Billable service'),
|
|
212
|
+
subtitle: serviceToEdit
|
|
213
|
+
? t('updatedSuccessfully', 'Billable service updated successfully')
|
|
214
|
+
: t('createdSuccessfully', 'Billable service created successfully'),
|
|
215
|
+
kind: 'success',
|
|
216
|
+
});
|
|
142
217
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
handleNavigateToServiceDashboard();
|
|
155
|
-
},
|
|
156
|
-
(error) => {
|
|
157
|
-
showSnackbar({ title: t('billPaymentError', 'Bill payment error'), kind: 'error', subtitle: error?.message });
|
|
158
|
-
},
|
|
159
|
-
);
|
|
218
|
+
if (onServiceUpdated) {
|
|
219
|
+
onServiceUpdated();
|
|
220
|
+
}
|
|
221
|
+
handleNavigateToServiceDashboard();
|
|
222
|
+
} catch (error) {
|
|
223
|
+
showSnackbar({
|
|
224
|
+
title: t('billPaymentError', 'Bill payment error'),
|
|
225
|
+
kind: 'error',
|
|
226
|
+
subtitle: error instanceof Error ? error.message : String(error),
|
|
227
|
+
});
|
|
228
|
+
}
|
|
160
229
|
};
|
|
161
230
|
|
|
162
231
|
const getPaymentErrorMessage = () => {
|
|
@@ -167,235 +236,213 @@ const AddBillableService: React.FC<{ editingService?: any; onClose: () => void }
|
|
|
167
236
|
return null;
|
|
168
237
|
};
|
|
169
238
|
|
|
170
|
-
if (isLoadingPaymentModes
|
|
239
|
+
if (isLoadingPaymentModes || isLoadingServiceTypes) {
|
|
171
240
|
return (
|
|
172
241
|
<InlineLoading
|
|
173
242
|
status="active"
|
|
174
243
|
iconDescription={t('loadingDescription', 'Loading')}
|
|
175
|
-
description={t('
|
|
244
|
+
description={t('loadingData', 'Loading data') + '...'}
|
|
176
245
|
/>
|
|
177
246
|
);
|
|
178
247
|
}
|
|
179
248
|
|
|
180
249
|
return (
|
|
181
|
-
<Form className={styles.form} onSubmit={handleSubmit(onSubmit)}>
|
|
182
|
-
<
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
<
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
</span>
|
|
250
|
+
<Form id="billable-service-form" className={styles.form} onSubmit={handleSubmit(onSubmit)}>
|
|
251
|
+
<Stack gap={5}>
|
|
252
|
+
<h4>
|
|
253
|
+
{serviceToEdit
|
|
254
|
+
? t('editBillableServices', 'Edit Billable Services')
|
|
255
|
+
: t('addBillableServices', 'Add Billable Services')}
|
|
256
|
+
</h4>
|
|
257
|
+
<section>
|
|
258
|
+
{serviceToEdit ? (
|
|
259
|
+
<FormLabel className={styles.serviceNameLabel}>{serviceToEdit.name}</FormLabel>
|
|
260
|
+
) : (
|
|
261
|
+
<Controller
|
|
262
|
+
name="name"
|
|
263
|
+
control={control}
|
|
264
|
+
render={({ field }) => (
|
|
265
|
+
<Layer>
|
|
266
|
+
<TextInput
|
|
267
|
+
{...field}
|
|
268
|
+
id="serviceName"
|
|
269
|
+
type="text"
|
|
270
|
+
labelText={t('serviceName', 'Service name')}
|
|
271
|
+
placeholder={t('enterServiceName', 'Enter service name')}
|
|
272
|
+
maxLength={MAX_NAME_LENGTH}
|
|
273
|
+
invalid={!!errors.name}
|
|
274
|
+
invalidText={errors.name?.message}
|
|
275
|
+
/>
|
|
276
|
+
</Layer>
|
|
277
|
+
)}
|
|
278
|
+
/>
|
|
211
279
|
)}
|
|
212
|
-
</
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
280
|
+
</section>
|
|
281
|
+
<section>
|
|
282
|
+
<Controller
|
|
283
|
+
name="shortName"
|
|
284
|
+
control={control}
|
|
285
|
+
render={({ field }) => (
|
|
286
|
+
<Layer>
|
|
287
|
+
<TextInput
|
|
288
|
+
{...field}
|
|
289
|
+
value={field.value || ''}
|
|
290
|
+
id="serviceShortName"
|
|
291
|
+
type="text"
|
|
292
|
+
labelText={t('serviceShortName', 'Short Name')}
|
|
293
|
+
placeholder={t('enterServiceShortName', 'Enter service short name')}
|
|
294
|
+
maxLength={MAX_NAME_LENGTH}
|
|
295
|
+
invalid={!!errors.shortName}
|
|
296
|
+
invalidText={errors.shortName?.message}
|
|
297
|
+
/>
|
|
298
|
+
</Layer>
|
|
299
|
+
)}
|
|
231
300
|
/>
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
ref={searchInputRef}
|
|
250
|
-
size="md"
|
|
251
|
-
id="conceptsSearch"
|
|
252
|
-
labelText={t('enterConcept', 'Associated concept')}
|
|
253
|
-
placeholder={t('searchConcepts', 'Search associated concept')}
|
|
254
|
-
className={errors?.search && styles.serviceError}
|
|
255
|
-
onChange={(e) => {
|
|
256
|
-
setSearchTerm(e.target.value);
|
|
257
|
-
onChange(e);
|
|
258
|
-
handleSearchTermChange(e);
|
|
259
|
-
}}
|
|
260
|
-
renderIcon={errors?.search && <WarningFilled />}
|
|
261
|
-
onBlur={onBlur}
|
|
262
|
-
onClear={() => {
|
|
263
|
-
setSearchTerm('');
|
|
264
|
-
setSelectedConcept(null);
|
|
265
|
-
}}
|
|
266
|
-
value={(() => {
|
|
267
|
-
if (selectedConcept) {
|
|
268
|
-
return selectedConcept.display;
|
|
269
|
-
}
|
|
270
|
-
if (debouncedSearchTerm) {
|
|
271
|
-
return value;
|
|
272
|
-
}
|
|
273
|
-
})()}
|
|
274
|
-
/>
|
|
275
|
-
</ResponsiveWrapper>
|
|
276
|
-
)}
|
|
277
|
-
/>
|
|
301
|
+
</section>
|
|
302
|
+
<section>
|
|
303
|
+
<FormLabel className={styles.conceptLabel}>{t('associatedConcept', 'Associated concept')}</FormLabel>
|
|
304
|
+
<ResponsiveWrapper>
|
|
305
|
+
<Search
|
|
306
|
+
ref={searchInputRef}
|
|
307
|
+
id="conceptsSearch"
|
|
308
|
+
labelText={t('enterConcept', 'Associated concept')}
|
|
309
|
+
placeholder={t('searchConcepts', 'Search associated concept')}
|
|
310
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSearchTerm(e.target.value)}
|
|
311
|
+
onClear={() => {
|
|
312
|
+
setSearchTerm('');
|
|
313
|
+
setValue('concept', null);
|
|
314
|
+
}}
|
|
315
|
+
value={selectedConcept?.display || searchTerm}
|
|
316
|
+
/>
|
|
317
|
+
</ResponsiveWrapper>
|
|
278
318
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
319
|
+
{(() => {
|
|
320
|
+
if (!debouncedSearchTerm || selectedConcept) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
if (isSearching) {
|
|
324
|
+
return <InlineLoading className={styles.loader} description={t('searching', 'Searching') + '...'} />;
|
|
325
|
+
}
|
|
326
|
+
if (searchResults && searchResults.length) {
|
|
327
|
+
return (
|
|
328
|
+
<ul className={styles.conceptsList}>
|
|
329
|
+
{searchResults?.map((searchResult) => (
|
|
330
|
+
<li
|
|
331
|
+
role="menuitem"
|
|
332
|
+
className={styles.service}
|
|
333
|
+
key={searchResult.uuid}
|
|
334
|
+
onClick={() => {
|
|
335
|
+
setValue('concept', searchResult);
|
|
336
|
+
setSearchTerm('');
|
|
337
|
+
}}>
|
|
338
|
+
{searchResult.display}
|
|
339
|
+
</li>
|
|
340
|
+
))}
|
|
341
|
+
</ul>
|
|
342
|
+
);
|
|
343
|
+
}
|
|
284
344
|
return (
|
|
285
|
-
<
|
|
286
|
-
{
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
onClick={() => handleConceptChange(searchResult)}>
|
|
293
|
-
{searchResult.display}
|
|
294
|
-
</li>
|
|
295
|
-
))}
|
|
296
|
-
</ul>
|
|
345
|
+
<Layer>
|
|
346
|
+
<Tile className={styles.emptyResults}>
|
|
347
|
+
<span>
|
|
348
|
+
{t('noResultsFor', 'No results for')} <strong>"{debouncedSearchTerm}"</strong>
|
|
349
|
+
</span>
|
|
350
|
+
</Tile>
|
|
351
|
+
</Layer>
|
|
297
352
|
);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
display: selectedItem?.display,
|
|
322
|
-
serviceType: selectedItem,
|
|
323
|
-
});
|
|
324
|
-
}}
|
|
325
|
-
placeholder="Select service type"
|
|
326
|
-
required
|
|
353
|
+
})()}
|
|
354
|
+
</section>
|
|
355
|
+
<section>
|
|
356
|
+
<Controller
|
|
357
|
+
name="serviceType"
|
|
358
|
+
control={control}
|
|
359
|
+
render={({ field }) => (
|
|
360
|
+
<Layer>
|
|
361
|
+
<ComboBox
|
|
362
|
+
id="serviceType"
|
|
363
|
+
items={serviceTypes ?? []}
|
|
364
|
+
titleText={t('serviceType', 'Service type')}
|
|
365
|
+
itemToString={(item: ServiceType) => item?.display || ''}
|
|
366
|
+
selectedItem={field.value}
|
|
367
|
+
onChange={({ selectedItem }: { selectedItem: ServiceType | null }) => {
|
|
368
|
+
field.onChange(selectedItem);
|
|
369
|
+
}}
|
|
370
|
+
placeholder={t('selectServiceType', 'Select service type')}
|
|
371
|
+
invalid={!!errors.serviceType}
|
|
372
|
+
invalidText={errors.serviceType?.message}
|
|
373
|
+
/>
|
|
374
|
+
</Layer>
|
|
375
|
+
)}
|
|
327
376
|
/>
|
|
328
|
-
</
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
<
|
|
377
|
+
</section>
|
|
378
|
+
<section>
|
|
379
|
+
<div>
|
|
380
|
+
{fields.map((field, index) => (
|
|
381
|
+
<div key={field.id} className={styles.paymentMethodContainer}>
|
|
382
|
+
<Controller
|
|
383
|
+
control={control}
|
|
384
|
+
name={`payment.${index}.paymentMode`}
|
|
385
|
+
render={({ field }) => (
|
|
386
|
+
<Layer>
|
|
387
|
+
<Dropdown
|
|
388
|
+
id={`paymentMode-${index}`}
|
|
389
|
+
onChange={({ selectedItem }) => field.onChange(selectedItem.uuid)}
|
|
390
|
+
titleText={t('paymentMode', 'Payment mode')}
|
|
391
|
+
label={t('selectPaymentMode', 'Select payment mode')}
|
|
392
|
+
items={paymentModes ?? []}
|
|
393
|
+
itemToString={(item) => (item ? item.name : '')}
|
|
394
|
+
selectedItem={paymentModes.find((mode) => mode.uuid === field.value)}
|
|
395
|
+
invalid={!!errors?.payment?.[index]?.paymentMode}
|
|
396
|
+
invalidText={errors?.payment?.[index]?.paymentMode?.message}
|
|
397
|
+
/>
|
|
398
|
+
</Layer>
|
|
399
|
+
)}
|
|
400
|
+
/>
|
|
401
|
+
<Controller
|
|
402
|
+
control={control}
|
|
403
|
+
name={`payment.${index}.price`}
|
|
404
|
+
render={({ field }) => (
|
|
405
|
+
<Layer>
|
|
406
|
+
{/* FIXME: this should be a NumberInput */}
|
|
407
|
+
<TextInput
|
|
408
|
+
{...field}
|
|
409
|
+
id={`price-${index}`}
|
|
410
|
+
invalid={!!errors?.payment?.[index]?.price}
|
|
411
|
+
invalidText={errors?.payment?.[index]?.price?.message}
|
|
412
|
+
labelText={t('sellingPrice', 'Selling Price')}
|
|
413
|
+
placeholder={t('enterSellingPrice', 'Enter selling price')}
|
|
414
|
+
/>
|
|
415
|
+
</Layer>
|
|
416
|
+
)}
|
|
417
|
+
/>
|
|
418
|
+
<div className={styles.removeButtonContainer}>
|
|
419
|
+
<TrashCan onClick={() => handleRemovePaymentMode(index)} className={styles.removeButton} size={20} />
|
|
420
|
+
</div>
|
|
370
421
|
</div>
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
422
|
+
))}
|
|
423
|
+
<Button
|
|
424
|
+
kind="tertiary"
|
|
425
|
+
type="button"
|
|
426
|
+
onClick={handleAppendPaymentMode}
|
|
427
|
+
className={styles.paymentButtons}
|
|
428
|
+
renderIcon={(props) => <Add size={24} {...props} />}
|
|
429
|
+
iconDescription={t('add', 'Add')}>
|
|
430
|
+
{t('addPaymentOption', 'Add payment option')}
|
|
431
|
+
</Button>
|
|
432
|
+
{getPaymentErrorMessage() && <div className={styles.errorMessage}>{getPaymentErrorMessage()}</div>}
|
|
433
|
+
</div>
|
|
434
|
+
</section>
|
|
435
|
+
</Stack>
|
|
436
|
+
{!isModal && (
|
|
437
|
+
<section>
|
|
438
|
+
<Button kind="secondary" onClick={onClose}>
|
|
439
|
+
{getCoreTranslation('cancel')}
|
|
380
440
|
</Button>
|
|
381
|
-
|
|
382
|
-
</
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
<section>
|
|
386
|
-
<Button kind="secondary" onClick={onClose}>
|
|
387
|
-
{t('cancel', 'Cancel')}
|
|
388
|
-
</Button>
|
|
389
|
-
<Button type="submit" disabled={!isValid || Object.keys(errors).length > 0}>
|
|
390
|
-
{t('save', 'Save')}
|
|
391
|
-
</Button>
|
|
392
|
-
</section>
|
|
441
|
+
<Button type="submit">{getCoreTranslation('save')}</Button>
|
|
442
|
+
</section>
|
|
443
|
+
)}
|
|
393
444
|
</Form>
|
|
394
445
|
);
|
|
395
446
|
};
|
|
396
447
|
|
|
397
|
-
function ResponsiveWrapper({ children, isTablet }: { children: React.ReactNode; isTablet: boolean }) {
|
|
398
|
-
return isTablet ? <Layer>{children} </Layer> : <>{children}</>;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
448
|
export default AddBillableService;
|