@infosoftas/s4-orders-js-sdk 0.1.21 → 0.2.0
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/.editorconfig +8 -8
- package/.release-it.json +10 -10
- package/README.md +565 -471
- package/package.json +62 -58
- package/src/App.completion.test.tsx +738 -0
- package/src/App.tsx +753 -639
- package/src/ErrorBoundary.tsx +41 -41
- package/src/api/InvoiceApi.ts +23 -23
- package/src/api/OrdersApi.ts +74 -59
- package/src/api/SubscribeApi.ts +18 -18
- package/src/bundle.ts +4 -4
- package/src/components/Alert/Alert.tsx +23 -23
- package/src/components/Button/Button.tsx +39 -39
- package/src/components/EHFForm/EHFForm.tsx +253 -253
- package/src/components/FormFields/AddressField.tsx +55 -55
- package/src/components/FormFields/EmailField.tsx +53 -53
- package/src/components/FormFields/FormFields.helper.ts +34 -34
- package/src/components/FormFields/FormFieldsMapper.ts +34 -34
- package/src/components/FormFields/InputField.tsx +52 -52
- package/src/components/FormFields/NameField.tsx +52 -52
- package/src/components/FormFields/PhoneField.tsx +53 -53
- package/src/components/FormFields/TermsCheckbox.tsx +70 -70
- package/src/components/FormFields/ToggleFiled.tsx +52 -52
- package/src/components/FormFields/fieldValidators.ts +71 -71
- package/src/components/MainIframe/MainIframe.tsx +42 -42
- package/src/components/OIOForm/OIOForm.tsx +307 -307
- package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -102
- package/src/components/OrderForm/ContactDetailsSection.tsx +71 -71
- package/src/components/OrderForm/OrderForm.tsx +420 -420
- package/src/components/OrderForm/PaymentMethodContent.tsx +62 -62
- package/src/components/OrderForm/PaymentMethodSection.tsx +79 -79
- package/src/components/OrderForm/SubmitConfirmationDialog.tsx +55 -55
- package/src/components/OrderForm/orderFormState.ts +171 -171
- package/src/components/OrderForm/useSlotElement.tsx +89 -89
- package/src/constants/index.ts +13 -13
- package/src/enums/api.ts +5 -5
- package/src/enums/general.ts +40 -40
- package/src/hooks/useIframe.tsx +59 -59
- package/src/hooks/useMessageEvent.tsx +194 -194
- package/src/hooks/useOrderForm.tsx +403 -403
- package/src/hooks/useQueryParams.ts +5 -5
- package/src/index.tsx +30 -30
- package/src/lib/utils.ts +1 -1
- package/src/types/api.ts +28 -28
- package/src/types/general.ts +154 -136
- package/src/types/order.ts +91 -70
- package/src/utils/fetcher.ts +131 -113
- package/src/utils/helper.ts +78 -78
- package/src/utils/order.helper.ts +272 -272
- package/src/utils/waitForOrderCompletion.ts +125 -0
- package/tsconfig.json +38 -38
|
@@ -1,253 +1,253 @@
|
|
|
1
|
-
import { type FC, useMemo } from 'react';
|
|
2
|
-
import { FormProvider, useForm, type SubmitHandler } from 'react-hook-form';
|
|
3
|
-
import { zodResolver } from '@hookform/resolvers/zod';
|
|
4
|
-
import z from 'zod';
|
|
5
|
-
|
|
6
|
-
import Alert from '../Alert/Alert';
|
|
7
|
-
import Button from '../Button/Button';
|
|
8
|
-
import OrderDenialModal from '../OrderDenialModal/OrderDenialModal';
|
|
9
|
-
import InputField from '../FormFields/InputField';
|
|
10
|
-
import { FieldGroup } from '../ui/field';
|
|
11
|
-
import { PaymentMethodEnum, UserActionEnum } from '../../enums/general';
|
|
12
|
-
import type {
|
|
13
|
-
OrderFormFieldType,
|
|
14
|
-
PaymentMethodSettingsType,
|
|
15
|
-
ContactRequestType,
|
|
16
|
-
OrderDenialFallbackOfferType,
|
|
17
|
-
} from '../../types/general';
|
|
18
|
-
import type { OrderFormInputsType, OrderInfoType } from '../../types/order';
|
|
19
|
-
import { orderInvoiceContactFields } from '../../utils/order.helper';
|
|
20
|
-
import useOrderForm from '../../hooks/useOrderForm';
|
|
21
|
-
import { DEFAULT_ORDER_FORM_FIELDS } from '../FormFields/FormFields.helper';
|
|
22
|
-
|
|
23
|
-
type Props = {
|
|
24
|
-
callback: (url: string | null, orderInfo?: OrderInfoType | null) => void;
|
|
25
|
-
onBack: () => void;
|
|
26
|
-
submitStartCallback?: (id: string) => void;
|
|
27
|
-
userActionCallback?: (
|
|
28
|
-
action: UserActionEnum,
|
|
29
|
-
args: object | null | undefined
|
|
30
|
-
) => void;
|
|
31
|
-
setContactCallback?: (contactInfo: ContactRequestType) => void;
|
|
32
|
-
className?: string;
|
|
33
|
-
backButtonText?: string;
|
|
34
|
-
verifyButtonText?: string;
|
|
35
|
-
orderDenialCloseButtonText?: string;
|
|
36
|
-
orderDenialContinueButtonText?: string;
|
|
37
|
-
organizationNumberLabel?: string;
|
|
38
|
-
organizationNumber?: string;
|
|
39
|
-
glnLabel?: string;
|
|
40
|
-
templatePackageId: string;
|
|
41
|
-
subscriberId?: string;
|
|
42
|
-
userId?: string;
|
|
43
|
-
identityProviderId?: string;
|
|
44
|
-
organizationId: string;
|
|
45
|
-
redirectUrl?: string;
|
|
46
|
-
showIframe?: boolean;
|
|
47
|
-
language: string;
|
|
48
|
-
merchantAgreementUrl: string;
|
|
49
|
-
orderValues?: OrderFormInputsType;
|
|
50
|
-
paymentMethodsOptions?: PaymentMethodSettingsType;
|
|
51
|
-
invoiceAddressSelection?: {
|
|
52
|
-
enabled?: boolean;
|
|
53
|
-
label?: string;
|
|
54
|
-
fields?: OrderFormFieldType[];
|
|
55
|
-
paymentMethods?: PaymentMethodEnum[];
|
|
56
|
-
};
|
|
57
|
-
invoiceLookupNotFoundText?: string;
|
|
58
|
-
errorReqMsg?: string;
|
|
59
|
-
errorValidationTitleMsg?: string;
|
|
60
|
-
errorValidationDenialOrderBlockingMsg?: string;
|
|
61
|
-
errorValidationBlockingOffersMsg?: string;
|
|
62
|
-
orderDenialOfferBaseText?: string;
|
|
63
|
-
orderDenialOfferWithFallbackText?: string;
|
|
64
|
-
orderDenialAmountText?: string;
|
|
65
|
-
fetchDenialFallbackOffer?: (
|
|
66
|
-
organizationId: string
|
|
67
|
-
) => Promise<OrderDenialFallbackOfferType | undefined>;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const buildFormSchema = (errorReqMsg?: string) => {
|
|
71
|
-
const message = errorReqMsg || 'This field is required!';
|
|
72
|
-
|
|
73
|
-
return z.object({
|
|
74
|
-
organizationNumber: z.string().min(1, message).regex(/\S/, message),
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
type EHFFormInputsType = { organizationNumber: string };
|
|
79
|
-
|
|
80
|
-
const initialData = {
|
|
81
|
-
organizationNumber: '',
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const EHFForm: FC<Props> = ({
|
|
85
|
-
callback,
|
|
86
|
-
onBack,
|
|
87
|
-
submitStartCallback,
|
|
88
|
-
userActionCallback,
|
|
89
|
-
setContactCallback,
|
|
90
|
-
className = '',
|
|
91
|
-
backButtonText = '',
|
|
92
|
-
verifyButtonText = '',
|
|
93
|
-
orderDenialCloseButtonText = 'Close',
|
|
94
|
-
orderDenialContinueButtonText = 'Continue',
|
|
95
|
-
organizationNumberLabel = '',
|
|
96
|
-
organizationNumber = '',
|
|
97
|
-
templatePackageId,
|
|
98
|
-
subscriberId,
|
|
99
|
-
userId,
|
|
100
|
-
identityProviderId,
|
|
101
|
-
organizationId,
|
|
102
|
-
redirectUrl,
|
|
103
|
-
showIframe,
|
|
104
|
-
language,
|
|
105
|
-
merchantAgreementUrl,
|
|
106
|
-
orderValues,
|
|
107
|
-
paymentMethodsOptions,
|
|
108
|
-
invoiceAddressSelection,
|
|
109
|
-
invoiceLookupNotFoundText,
|
|
110
|
-
errorReqMsg,
|
|
111
|
-
errorValidationTitleMsg,
|
|
112
|
-
errorValidationDenialOrderBlockingMsg,
|
|
113
|
-
errorValidationBlockingOffersMsg,
|
|
114
|
-
orderDenialOfferBaseText,
|
|
115
|
-
orderDenialOfferWithFallbackText,
|
|
116
|
-
orderDenialAmountText,
|
|
117
|
-
fetchDenialFallbackOffer,
|
|
118
|
-
}) => {
|
|
119
|
-
const formSchema = useMemo(
|
|
120
|
-
() => buildFormSchema(errorReqMsg),
|
|
121
|
-
[errorReqMsg]
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
const methods = useForm<EHFFormInputsType>({
|
|
125
|
-
resolver: zodResolver(formSchema),
|
|
126
|
-
defaultValues: {
|
|
127
|
-
...initialData,
|
|
128
|
-
organizationNumber,
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const { handleSubmit } = methods;
|
|
133
|
-
|
|
134
|
-
const invoiceOrderFields =
|
|
135
|
-
invoiceAddressSelection?.fields || orderInvoiceContactFields;
|
|
136
|
-
|
|
137
|
-
const orderFields =
|
|
138
|
-
paymentMethodsOptions?.[orderValues?.paymentMethod as PaymentMethodEnum]
|
|
139
|
-
?.orderFormFields ?? DEFAULT_ORDER_FORM_FIELDS;
|
|
140
|
-
|
|
141
|
-
const {
|
|
142
|
-
orderSubmit,
|
|
143
|
-
continueWithFallbackOffer,
|
|
144
|
-
loading,
|
|
145
|
-
apiErrorMsg,
|
|
146
|
-
errorsMsg,
|
|
147
|
-
orderDenialType,
|
|
148
|
-
orderDenialMessage,
|
|
149
|
-
orderDenialFallbackOffer,
|
|
150
|
-
dismissOrderDenial,
|
|
151
|
-
} = useOrderForm({
|
|
152
|
-
callback,
|
|
153
|
-
submitStartCallback,
|
|
154
|
-
userActionCallback,
|
|
155
|
-
setContactCallback,
|
|
156
|
-
organizationId,
|
|
157
|
-
subscriberId,
|
|
158
|
-
userId,
|
|
159
|
-
identityProviderId,
|
|
160
|
-
orderFields,
|
|
161
|
-
redirectUrl,
|
|
162
|
-
showIframe,
|
|
163
|
-
language,
|
|
164
|
-
merchantAgreementUrl,
|
|
165
|
-
paymentMethodsOptions,
|
|
166
|
-
templatePackageId,
|
|
167
|
-
invoiceAddressToggle: orderValues?.invoiceAddressSelection,
|
|
168
|
-
invoiceOrderFields,
|
|
169
|
-
invoiceLookupNotFoundText,
|
|
170
|
-
errorValidationTitleMsg,
|
|
171
|
-
errorValidationDenialOrderBlockingMsg,
|
|
172
|
-
errorValidationBlockingOffersMsg,
|
|
173
|
-
orderDenialOfferBaseText,
|
|
174
|
-
orderDenialOfferWithFallbackText,
|
|
175
|
-
orderDenialAmountText,
|
|
176
|
-
fetchDenialFallbackOffer,
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
const onSubmit: SubmitHandler<EHFFormInputsType> = async (
|
|
180
|
-
data
|
|
181
|
-
): Promise<void> => {
|
|
182
|
-
orderSubmit({
|
|
183
|
-
...orderValues,
|
|
184
|
-
organizationNumber: data.organizationNumber,
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const handleBack = () => {
|
|
189
|
-
userActionCallback?.(UserActionEnum.RETURN_TO_MAIN, null);
|
|
190
|
-
onBack?.();
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
return (
|
|
194
|
-
<FormProvider {...methods}>
|
|
195
|
-
<form
|
|
196
|
-
className={`${className}`}
|
|
197
|
-
noValidate
|
|
198
|
-
onSubmit={handleSubmit(onSubmit)}
|
|
199
|
-
data-testid="ehf-form-id"
|
|
200
|
-
>
|
|
201
|
-
<FieldGroup className="mb-5">
|
|
202
|
-
<InputField
|
|
203
|
-
name="organizationNumber"
|
|
204
|
-
label={organizationNumberLabel}
|
|
205
|
-
required
|
|
206
|
-
readOnly={false}
|
|
207
|
-
/>
|
|
208
|
-
</FieldGroup>
|
|
209
|
-
<div className="flex justify-center flex-wrap gap-2">
|
|
210
|
-
<Button
|
|
211
|
-
type="button"
|
|
212
|
-
btnType="default"
|
|
213
|
-
disable={loading}
|
|
214
|
-
buttonText={backButtonText}
|
|
215
|
-
onClick={handleBack}
|
|
216
|
-
/>
|
|
217
|
-
|
|
218
|
-
<Button
|
|
219
|
-
type="submit"
|
|
220
|
-
loading={loading}
|
|
221
|
-
buttonText={verifyButtonText}
|
|
222
|
-
/>
|
|
223
|
-
</div>
|
|
224
|
-
|
|
225
|
-
{apiErrorMsg && <Alert className="mt-2" msg={apiErrorMsg} />}
|
|
226
|
-
{errorsMsg?.length > 0 &&
|
|
227
|
-
errorsMsg.map((i, index) => (
|
|
228
|
-
<Alert key={index} className="mt-2" msg={i} />
|
|
229
|
-
))}
|
|
230
|
-
<OrderDenialModal
|
|
231
|
-
isOpen={!!orderDenialType}
|
|
232
|
-
message={orderDenialMessage}
|
|
233
|
-
closeButtonText={orderDenialCloseButtonText}
|
|
234
|
-
continueButtonText={orderDenialContinueButtonText}
|
|
235
|
-
canContinue={
|
|
236
|
-
orderDenialType === 'offer' &&
|
|
237
|
-
!!orderDenialFallbackOffer?.templatePackageId
|
|
238
|
-
}
|
|
239
|
-
offer={
|
|
240
|
-
orderDenialType === 'offer' &&
|
|
241
|
-
!!orderDenialFallbackOffer?.templatePackageId
|
|
242
|
-
? orderDenialFallbackOffer
|
|
243
|
-
: undefined
|
|
244
|
-
}
|
|
245
|
-
onClose={dismissOrderDenial}
|
|
246
|
-
onContinue={continueWithFallbackOffer}
|
|
247
|
-
/>
|
|
248
|
-
</form>
|
|
249
|
-
</FormProvider>
|
|
250
|
-
);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
export default EHFForm;
|
|
1
|
+
import { type FC, useMemo } from 'react';
|
|
2
|
+
import { FormProvider, useForm, type SubmitHandler } from 'react-hook-form';
|
|
3
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
4
|
+
import z from 'zod';
|
|
5
|
+
|
|
6
|
+
import Alert from '../Alert/Alert';
|
|
7
|
+
import Button from '../Button/Button';
|
|
8
|
+
import OrderDenialModal from '../OrderDenialModal/OrderDenialModal';
|
|
9
|
+
import InputField from '../FormFields/InputField';
|
|
10
|
+
import { FieldGroup } from '../ui/field';
|
|
11
|
+
import { PaymentMethodEnum, UserActionEnum } from '../../enums/general';
|
|
12
|
+
import type {
|
|
13
|
+
OrderFormFieldType,
|
|
14
|
+
PaymentMethodSettingsType,
|
|
15
|
+
ContactRequestType,
|
|
16
|
+
OrderDenialFallbackOfferType,
|
|
17
|
+
} from '../../types/general';
|
|
18
|
+
import type { OrderFormInputsType, OrderInfoType } from '../../types/order';
|
|
19
|
+
import { orderInvoiceContactFields } from '../../utils/order.helper';
|
|
20
|
+
import useOrderForm from '../../hooks/useOrderForm';
|
|
21
|
+
import { DEFAULT_ORDER_FORM_FIELDS } from '../FormFields/FormFields.helper';
|
|
22
|
+
|
|
23
|
+
type Props = {
|
|
24
|
+
callback: (url: string | null, orderInfo?: OrderInfoType | null) => void;
|
|
25
|
+
onBack: () => void;
|
|
26
|
+
submitStartCallback?: (id: string) => void;
|
|
27
|
+
userActionCallback?: (
|
|
28
|
+
action: UserActionEnum,
|
|
29
|
+
args: object | null | undefined
|
|
30
|
+
) => void;
|
|
31
|
+
setContactCallback?: (contactInfo: ContactRequestType) => void;
|
|
32
|
+
className?: string;
|
|
33
|
+
backButtonText?: string;
|
|
34
|
+
verifyButtonText?: string;
|
|
35
|
+
orderDenialCloseButtonText?: string;
|
|
36
|
+
orderDenialContinueButtonText?: string;
|
|
37
|
+
organizationNumberLabel?: string;
|
|
38
|
+
organizationNumber?: string;
|
|
39
|
+
glnLabel?: string;
|
|
40
|
+
templatePackageId: string;
|
|
41
|
+
subscriberId?: string;
|
|
42
|
+
userId?: string;
|
|
43
|
+
identityProviderId?: string;
|
|
44
|
+
organizationId: string;
|
|
45
|
+
redirectUrl?: string;
|
|
46
|
+
showIframe?: boolean;
|
|
47
|
+
language: string;
|
|
48
|
+
merchantAgreementUrl: string;
|
|
49
|
+
orderValues?: OrderFormInputsType;
|
|
50
|
+
paymentMethodsOptions?: PaymentMethodSettingsType;
|
|
51
|
+
invoiceAddressSelection?: {
|
|
52
|
+
enabled?: boolean;
|
|
53
|
+
label?: string;
|
|
54
|
+
fields?: OrderFormFieldType[];
|
|
55
|
+
paymentMethods?: PaymentMethodEnum[];
|
|
56
|
+
};
|
|
57
|
+
invoiceLookupNotFoundText?: string;
|
|
58
|
+
errorReqMsg?: string;
|
|
59
|
+
errorValidationTitleMsg?: string;
|
|
60
|
+
errorValidationDenialOrderBlockingMsg?: string;
|
|
61
|
+
errorValidationBlockingOffersMsg?: string;
|
|
62
|
+
orderDenialOfferBaseText?: string;
|
|
63
|
+
orderDenialOfferWithFallbackText?: string;
|
|
64
|
+
orderDenialAmountText?: string;
|
|
65
|
+
fetchDenialFallbackOffer?: (
|
|
66
|
+
organizationId: string
|
|
67
|
+
) => Promise<OrderDenialFallbackOfferType | undefined>;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const buildFormSchema = (errorReqMsg?: string) => {
|
|
71
|
+
const message = errorReqMsg || 'This field is required!';
|
|
72
|
+
|
|
73
|
+
return z.object({
|
|
74
|
+
organizationNumber: z.string().min(1, message).regex(/\S/, message),
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
type EHFFormInputsType = { organizationNumber: string };
|
|
79
|
+
|
|
80
|
+
const initialData = {
|
|
81
|
+
organizationNumber: '',
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const EHFForm: FC<Props> = ({
|
|
85
|
+
callback,
|
|
86
|
+
onBack,
|
|
87
|
+
submitStartCallback,
|
|
88
|
+
userActionCallback,
|
|
89
|
+
setContactCallback,
|
|
90
|
+
className = '',
|
|
91
|
+
backButtonText = '',
|
|
92
|
+
verifyButtonText = '',
|
|
93
|
+
orderDenialCloseButtonText = 'Close',
|
|
94
|
+
orderDenialContinueButtonText = 'Continue',
|
|
95
|
+
organizationNumberLabel = '',
|
|
96
|
+
organizationNumber = '',
|
|
97
|
+
templatePackageId,
|
|
98
|
+
subscriberId,
|
|
99
|
+
userId,
|
|
100
|
+
identityProviderId,
|
|
101
|
+
organizationId,
|
|
102
|
+
redirectUrl,
|
|
103
|
+
showIframe,
|
|
104
|
+
language,
|
|
105
|
+
merchantAgreementUrl,
|
|
106
|
+
orderValues,
|
|
107
|
+
paymentMethodsOptions,
|
|
108
|
+
invoiceAddressSelection,
|
|
109
|
+
invoiceLookupNotFoundText,
|
|
110
|
+
errorReqMsg,
|
|
111
|
+
errorValidationTitleMsg,
|
|
112
|
+
errorValidationDenialOrderBlockingMsg,
|
|
113
|
+
errorValidationBlockingOffersMsg,
|
|
114
|
+
orderDenialOfferBaseText,
|
|
115
|
+
orderDenialOfferWithFallbackText,
|
|
116
|
+
orderDenialAmountText,
|
|
117
|
+
fetchDenialFallbackOffer,
|
|
118
|
+
}) => {
|
|
119
|
+
const formSchema = useMemo(
|
|
120
|
+
() => buildFormSchema(errorReqMsg),
|
|
121
|
+
[errorReqMsg]
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const methods = useForm<EHFFormInputsType>({
|
|
125
|
+
resolver: zodResolver(formSchema),
|
|
126
|
+
defaultValues: {
|
|
127
|
+
...initialData,
|
|
128
|
+
organizationNumber,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const { handleSubmit } = methods;
|
|
133
|
+
|
|
134
|
+
const invoiceOrderFields =
|
|
135
|
+
invoiceAddressSelection?.fields || orderInvoiceContactFields;
|
|
136
|
+
|
|
137
|
+
const orderFields =
|
|
138
|
+
paymentMethodsOptions?.[orderValues?.paymentMethod as PaymentMethodEnum]
|
|
139
|
+
?.orderFormFields ?? DEFAULT_ORDER_FORM_FIELDS;
|
|
140
|
+
|
|
141
|
+
const {
|
|
142
|
+
orderSubmit,
|
|
143
|
+
continueWithFallbackOffer,
|
|
144
|
+
loading,
|
|
145
|
+
apiErrorMsg,
|
|
146
|
+
errorsMsg,
|
|
147
|
+
orderDenialType,
|
|
148
|
+
orderDenialMessage,
|
|
149
|
+
orderDenialFallbackOffer,
|
|
150
|
+
dismissOrderDenial,
|
|
151
|
+
} = useOrderForm({
|
|
152
|
+
callback,
|
|
153
|
+
submitStartCallback,
|
|
154
|
+
userActionCallback,
|
|
155
|
+
setContactCallback,
|
|
156
|
+
organizationId,
|
|
157
|
+
subscriberId,
|
|
158
|
+
userId,
|
|
159
|
+
identityProviderId,
|
|
160
|
+
orderFields,
|
|
161
|
+
redirectUrl,
|
|
162
|
+
showIframe,
|
|
163
|
+
language,
|
|
164
|
+
merchantAgreementUrl,
|
|
165
|
+
paymentMethodsOptions,
|
|
166
|
+
templatePackageId,
|
|
167
|
+
invoiceAddressToggle: orderValues?.invoiceAddressSelection,
|
|
168
|
+
invoiceOrderFields,
|
|
169
|
+
invoiceLookupNotFoundText,
|
|
170
|
+
errorValidationTitleMsg,
|
|
171
|
+
errorValidationDenialOrderBlockingMsg,
|
|
172
|
+
errorValidationBlockingOffersMsg,
|
|
173
|
+
orderDenialOfferBaseText,
|
|
174
|
+
orderDenialOfferWithFallbackText,
|
|
175
|
+
orderDenialAmountText,
|
|
176
|
+
fetchDenialFallbackOffer,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const onSubmit: SubmitHandler<EHFFormInputsType> = async (
|
|
180
|
+
data
|
|
181
|
+
): Promise<void> => {
|
|
182
|
+
orderSubmit({
|
|
183
|
+
...orderValues,
|
|
184
|
+
organizationNumber: data.organizationNumber,
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const handleBack = () => {
|
|
189
|
+
userActionCallback?.(UserActionEnum.RETURN_TO_MAIN, null);
|
|
190
|
+
onBack?.();
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<FormProvider {...methods}>
|
|
195
|
+
<form
|
|
196
|
+
className={`${className}`}
|
|
197
|
+
noValidate
|
|
198
|
+
onSubmit={handleSubmit(onSubmit)}
|
|
199
|
+
data-testid="ehf-form-id"
|
|
200
|
+
>
|
|
201
|
+
<FieldGroup className="mb-5">
|
|
202
|
+
<InputField
|
|
203
|
+
name="organizationNumber"
|
|
204
|
+
label={organizationNumberLabel}
|
|
205
|
+
required
|
|
206
|
+
readOnly={false}
|
|
207
|
+
/>
|
|
208
|
+
</FieldGroup>
|
|
209
|
+
<div className="flex justify-center flex-wrap gap-2">
|
|
210
|
+
<Button
|
|
211
|
+
type="button"
|
|
212
|
+
btnType="default"
|
|
213
|
+
disable={loading}
|
|
214
|
+
buttonText={backButtonText}
|
|
215
|
+
onClick={handleBack}
|
|
216
|
+
/>
|
|
217
|
+
|
|
218
|
+
<Button
|
|
219
|
+
type="submit"
|
|
220
|
+
loading={loading}
|
|
221
|
+
buttonText={verifyButtonText}
|
|
222
|
+
/>
|
|
223
|
+
</div>
|
|
224
|
+
|
|
225
|
+
{apiErrorMsg && <Alert className="mt-2" msg={apiErrorMsg} />}
|
|
226
|
+
{errorsMsg?.length > 0 &&
|
|
227
|
+
errorsMsg.map((i, index) => (
|
|
228
|
+
<Alert key={index} className="mt-2" msg={i} />
|
|
229
|
+
))}
|
|
230
|
+
<OrderDenialModal
|
|
231
|
+
isOpen={!!orderDenialType}
|
|
232
|
+
message={orderDenialMessage}
|
|
233
|
+
closeButtonText={orderDenialCloseButtonText}
|
|
234
|
+
continueButtonText={orderDenialContinueButtonText}
|
|
235
|
+
canContinue={
|
|
236
|
+
orderDenialType === 'offer' &&
|
|
237
|
+
!!orderDenialFallbackOffer?.templatePackageId
|
|
238
|
+
}
|
|
239
|
+
offer={
|
|
240
|
+
orderDenialType === 'offer' &&
|
|
241
|
+
!!orderDenialFallbackOffer?.templatePackageId
|
|
242
|
+
? orderDenialFallbackOffer
|
|
243
|
+
: undefined
|
|
244
|
+
}
|
|
245
|
+
onClose={dismissOrderDenial}
|
|
246
|
+
onContinue={continueWithFallbackOffer}
|
|
247
|
+
/>
|
|
248
|
+
</form>
|
|
249
|
+
</FormProvider>
|
|
250
|
+
);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export default EHFForm;
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { type FC, useId } from 'react';
|
|
2
|
-
import { useFormContext } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { Field, FieldError, FieldLabel } from '../ui/field';
|
|
5
|
-
import { Textarea } from '../ui/textarea';
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
name: string;
|
|
9
|
-
required: boolean;
|
|
10
|
-
readOnly: boolean;
|
|
11
|
-
label?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const AddressField: FC<Props> = ({
|
|
15
|
-
name = 'address',
|
|
16
|
-
required = false,
|
|
17
|
-
readOnly = false,
|
|
18
|
-
label = 'Address',
|
|
19
|
-
}) => {
|
|
20
|
-
const { register, getFieldState, formState } = useFormContext();
|
|
21
|
-
const { error } = getFieldState(name, formState);
|
|
22
|
-
const id = useId();
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<Field data-invalid={!!error} data-testid={`sdk-${name}-field-id`}>
|
|
26
|
-
<FieldLabel htmlFor={id}>
|
|
27
|
-
<span>
|
|
28
|
-
{label}
|
|
29
|
-
{required && (
|
|
30
|
-
<span aria-hidden="true" className="text-destructive">
|
|
31
|
-
{' '}
|
|
32
|
-
*
|
|
33
|
-
</span>
|
|
34
|
-
)}
|
|
35
|
-
</span>
|
|
36
|
-
</FieldLabel>
|
|
37
|
-
<Textarea
|
|
38
|
-
id={id}
|
|
39
|
-
autoComplete="street-address"
|
|
40
|
-
readOnly={readOnly}
|
|
41
|
-
className="read-only:cursor-not-allowed read-only:bg-input/50"
|
|
42
|
-
aria-invalid={!!error}
|
|
43
|
-
aria-required={required}
|
|
44
|
-
required={required}
|
|
45
|
-
{...register(name, {
|
|
46
|
-
setValueAs: (value) =>
|
|
47
|
-
typeof value === 'string' ? value.trim() : value,
|
|
48
|
-
})}
|
|
49
|
-
/>
|
|
50
|
-
<FieldError errors={[error]} />
|
|
51
|
-
</Field>
|
|
52
|
-
);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export default AddressField;
|
|
1
|
+
import { type FC, useId } from 'react';
|
|
2
|
+
import { useFormContext } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Field, FieldError, FieldLabel } from '../ui/field';
|
|
5
|
+
import { Textarea } from '../ui/textarea';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
readOnly: boolean;
|
|
11
|
+
label?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const AddressField: FC<Props> = ({
|
|
15
|
+
name = 'address',
|
|
16
|
+
required = false,
|
|
17
|
+
readOnly = false,
|
|
18
|
+
label = 'Address',
|
|
19
|
+
}) => {
|
|
20
|
+
const { register, getFieldState, formState } = useFormContext();
|
|
21
|
+
const { error } = getFieldState(name, formState);
|
|
22
|
+
const id = useId();
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Field data-invalid={!!error} data-testid={`sdk-${name}-field-id`}>
|
|
26
|
+
<FieldLabel htmlFor={id}>
|
|
27
|
+
<span>
|
|
28
|
+
{label}
|
|
29
|
+
{required && (
|
|
30
|
+
<span aria-hidden="true" className="text-destructive">
|
|
31
|
+
{' '}
|
|
32
|
+
*
|
|
33
|
+
</span>
|
|
34
|
+
)}
|
|
35
|
+
</span>
|
|
36
|
+
</FieldLabel>
|
|
37
|
+
<Textarea
|
|
38
|
+
id={id}
|
|
39
|
+
autoComplete="street-address"
|
|
40
|
+
readOnly={readOnly}
|
|
41
|
+
className="read-only:cursor-not-allowed read-only:bg-input/50"
|
|
42
|
+
aria-invalid={!!error}
|
|
43
|
+
aria-required={required}
|
|
44
|
+
required={required}
|
|
45
|
+
{...register(name, {
|
|
46
|
+
setValueAs: (value) =>
|
|
47
|
+
typeof value === 'string' ? value.trim() : value,
|
|
48
|
+
})}
|
|
49
|
+
/>
|
|
50
|
+
<FieldError errors={[error]} />
|
|
51
|
+
</Field>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default AddressField;
|