@infosoftas/s4-orders-js-sdk 0.1.21 → 0.2.1

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.
Files changed (72) hide show
  1. package/.editorconfig +0 -0
  2. package/.release-it.json +0 -0
  3. package/README.md +572 -471
  4. package/build/postcss-scope-tailwind.cjs +0 -0
  5. package/components.json +0 -0
  6. package/package.json +62 -58
  7. package/src/App.completion.test.tsx +677 -0
  8. package/src/App.css +0 -14
  9. package/src/App.paymentReturn.test.tsx +341 -0
  10. package/src/App.tsx +722 -639
  11. package/src/ErrorBoundary.tsx +0 -0
  12. package/src/api/InvoiceApi.ts +0 -0
  13. package/src/api/OrdersApi.ts +74 -59
  14. package/src/api/SubscribeApi.ts +0 -0
  15. package/src/bundle.ts +0 -0
  16. package/src/components/Alert/Alert.tsx +0 -0
  17. package/src/components/Button/Button.tsx +0 -0
  18. package/src/components/EHFForm/EHFForm.tsx +250 -253
  19. package/src/components/FormFields/AddressField.tsx +0 -0
  20. package/src/components/FormFields/EmailField.tsx +0 -0
  21. package/src/components/FormFields/FormFields.helper.ts +0 -0
  22. package/src/components/FormFields/FormFieldsMapper.ts +0 -0
  23. package/src/components/FormFields/InputField.tsx +0 -0
  24. package/src/components/FormFields/NameField.tsx +0 -0
  25. package/src/components/FormFields/PhoneField.tsx +0 -0
  26. package/src/components/FormFields/TermsCheckbox.tsx +0 -0
  27. package/src/components/FormFields/ToggleFiled.tsx +0 -0
  28. package/src/components/FormFields/fieldValidators.ts +0 -0
  29. package/src/components/OIOForm/OIOForm.tsx +304 -307
  30. package/src/components/OrderDenialModal/OrderDenialModal.tsx +0 -0
  31. package/src/components/OrderForm/ContactDetailsSection.tsx +0 -0
  32. package/src/components/OrderForm/OrderForm.tsx +417 -420
  33. package/src/components/OrderForm/PaymentMethodContent.tsx +0 -0
  34. package/src/components/OrderForm/PaymentMethodSection.tsx +0 -0
  35. package/src/components/OrderForm/SubmitConfirmationDialog.tsx +0 -0
  36. package/src/components/OrderForm/orderFormState.ts +0 -0
  37. package/src/components/OrderForm/useSlotElement.tsx +0 -0
  38. package/src/components/ui/alert-dialog.tsx +0 -0
  39. package/src/components/ui/alert.tsx +0 -0
  40. package/src/components/ui/button.tsx +0 -0
  41. package/src/components/ui/card.tsx +0 -0
  42. package/src/components/ui/checkbox.tsx +0 -0
  43. package/src/components/ui/field.tsx +0 -0
  44. package/src/components/ui/input.tsx +0 -0
  45. package/src/components/ui/label.tsx +0 -0
  46. package/src/components/ui/radio-group.tsx +0 -0
  47. package/src/components/ui/separator.tsx +0 -0
  48. package/src/components/ui/skeleton.tsx +0 -0
  49. package/src/components/ui/spinner.tsx +0 -0
  50. package/src/components/ui/switch.tsx +0 -0
  51. package/src/components/ui/textarea.tsx +0 -0
  52. package/src/constants/index.ts +0 -0
  53. package/src/custom.d.ts +0 -0
  54. package/src/enums/api.ts +0 -0
  55. package/src/enums/general.ts +42 -40
  56. package/src/hooks/useOrderForm.tsx +400 -403
  57. package/src/hooks/usePaymentReturn.tsx +139 -0
  58. package/src/hooks/useQueryParams.ts +0 -0
  59. package/src/index.tsx +0 -0
  60. package/src/lib/utils.ts +0 -0
  61. package/src/types/api.ts +0 -0
  62. package/src/types/general.ts +153 -136
  63. package/src/types/order.ts +91 -70
  64. package/src/utils/fetcher.ts +131 -113
  65. package/src/utils/helper.ts +0 -0
  66. package/src/utils/order.helper.test.ts +81 -0
  67. package/src/utils/order.helper.ts +285 -272
  68. package/src/utils/waitForOrderCompletion.ts +125 -0
  69. package/tsconfig.json +39 -38
  70. package/src/components/MainIframe/MainIframe.tsx +0 -42
  71. package/src/hooks/useIframe.tsx +0 -59
  72. package/src/hooks/useMessageEvent.tsx +0 -194
File without changes
File without changes
@@ -1,59 +1,74 @@
1
- import type { CreateSubscriberRequestType } from '../types/api';
2
- import type { AgreementsType } from '../types/order';
3
- import fetcher, { getSdkApiKey } from '../utils/fetcher';
4
-
5
- type RequestOrderStartType = {
6
- subscriberId?: string;
7
- subscriptionPlan?: {
8
- organizationId?: string;
9
- templateSubscriptionPlanId?: string;
10
- };
11
- paymentAgreement: AgreementsType;
12
- invoiceContact?: CreateSubscriberRequestType;
13
- orderReference?: string;
14
- };
15
-
16
- type OrderCompleteRequestType = {
17
- userId: string;
18
- identityProviderId: string;
19
- };
20
-
21
- type OrderResponseType = {
22
- terminalRedirectUrl: string | null;
23
- id: string | null;
24
- };
25
-
26
- export const orderStart = (
27
- body: RequestOrderStartType
28
- ): Promise<OrderResponseType> =>
29
- fetcher<OrderResponseType, RequestOrderStartType>({
30
- method: 'POST',
31
- url: '/order',
32
- headers: {
33
- 'S4-ORDERS-API-KEY': getSdkApiKey(),
34
- },
35
- body,
36
- }) as Promise<OrderResponseType>;
37
-
38
- export const orderComplete = (
39
- id: string,
40
- body?: OrderCompleteRequestType
41
- ): Promise<OrderResponseType> =>
42
- fetcher<OrderResponseType, OrderCompleteRequestType | null>({
43
- method: 'POST',
44
- url: `/order/${id}/complete`,
45
- headers: {
46
- 'S4-ORDERS-API-KEY': getSdkApiKey(),
47
- },
48
- body: body || null,
49
- }) as Promise<OrderResponseType>;
50
-
51
- export const orderDelete = (id: string): Promise<OrderResponseType> =>
52
- fetcher<OrderResponseType, null>({
53
- method: 'DELETE',
54
- url: `/order/${id}`,
55
- headers: {
56
- 'S4-ORDERS-API-KEY': getSdkApiKey(),
57
- },
58
- body: null,
59
- }) as Promise<OrderResponseType>;
1
+ import type { CreateSubscriberRequestType } from '../types/api';
2
+ import type { AgreementsType, OrderStatusResponseType } from '../types/order';
3
+ import fetcher, { getSdkApiKey } from '../utils/fetcher';
4
+
5
+ type RequestOrderStartType = {
6
+ subscriberId?: string;
7
+ subscriptionPlan?: {
8
+ organizationId?: string;
9
+ templateSubscriptionPlanId?: string;
10
+ };
11
+ paymentAgreement: AgreementsType;
12
+ invoiceContact?: CreateSubscriberRequestType;
13
+ orderReference?: string;
14
+ };
15
+
16
+ type OrderCompleteRequestType = {
17
+ userId: string;
18
+ identityProviderId: string;
19
+ };
20
+
21
+ type OrderResponseType = {
22
+ terminalRedirectUrl: string | null;
23
+ id: string | null;
24
+ };
25
+
26
+ export const orderStart = (
27
+ body: RequestOrderStartType
28
+ ): Promise<OrderResponseType> =>
29
+ fetcher<OrderResponseType, RequestOrderStartType>({
30
+ method: 'POST',
31
+ url: '/order',
32
+ headers: {
33
+ 'S4-ORDERS-API-KEY': getSdkApiKey(),
34
+ },
35
+ body,
36
+ }) as Promise<OrderResponseType>;
37
+
38
+ export const orderComplete = (
39
+ id: string,
40
+ body?: OrderCompleteRequestType,
41
+ signal?: AbortSignal
42
+ ): Promise<OrderResponseType> =>
43
+ fetcher<OrderResponseType, OrderCompleteRequestType | null>({
44
+ method: 'POST',
45
+ url: `/order/${id}/complete`,
46
+ headers: {
47
+ 'S4-ORDERS-API-KEY': getSdkApiKey(),
48
+ },
49
+ body: body || null,
50
+ signal,
51
+ }) as Promise<OrderResponseType>;
52
+
53
+ export const getOrderStatus = (
54
+ id: string,
55
+ signal: AbortSignal
56
+ ): Promise<OrderStatusResponseType> =>
57
+ fetcher<OrderStatusResponseType>({
58
+ url: `/order/${encodeURIComponent(id)}`,
59
+ headers: {
60
+ 'S4-ORDERS-API-KEY': getSdkApiKey(),
61
+ },
62
+ signal,
63
+ cache: 'no-store',
64
+ }) as Promise<OrderStatusResponseType>;
65
+
66
+ export const orderDelete = (id: string): Promise<OrderResponseType> =>
67
+ fetcher<OrderResponseType, null>({
68
+ method: 'DELETE',
69
+ url: `/order/${id}`,
70
+ headers: {
71
+ 'S4-ORDERS-API-KEY': getSdkApiKey(),
72
+ },
73
+ body: null,
74
+ }) as Promise<OrderResponseType>;
File without changes
package/src/bundle.ts CHANGED
File without changes
File without changes
File without changes
@@ -1,253 +1,250 @@
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
+ language: string;
47
+ merchantAgreementUrl: string;
48
+ orderValues?: OrderFormInputsType;
49
+ paymentMethodsOptions?: PaymentMethodSettingsType;
50
+ invoiceAddressSelection?: {
51
+ enabled?: boolean;
52
+ label?: string;
53
+ fields?: OrderFormFieldType[];
54
+ paymentMethods?: PaymentMethodEnum[];
55
+ };
56
+ invoiceLookupNotFoundText?: string;
57
+ errorReqMsg?: string;
58
+ errorValidationTitleMsg?: string;
59
+ errorValidationDenialOrderBlockingMsg?: string;
60
+ errorValidationBlockingOffersMsg?: string;
61
+ orderDenialOfferBaseText?: string;
62
+ orderDenialOfferWithFallbackText?: string;
63
+ orderDenialAmountText?: string;
64
+ fetchDenialFallbackOffer?: (
65
+ organizationId: string
66
+ ) => Promise<OrderDenialFallbackOfferType | undefined>;
67
+ };
68
+
69
+ const buildFormSchema = (errorReqMsg?: string) => {
70
+ const message = errorReqMsg || 'This field is required!';
71
+
72
+ return z.object({
73
+ organizationNumber: z.string().min(1, message).regex(/\S/, message),
74
+ });
75
+ };
76
+
77
+ type EHFFormInputsType = { organizationNumber: string };
78
+
79
+ const initialData = {
80
+ organizationNumber: '',
81
+ };
82
+
83
+ const EHFForm: FC<Props> = ({
84
+ callback,
85
+ onBack,
86
+ submitStartCallback,
87
+ userActionCallback,
88
+ setContactCallback,
89
+ className = '',
90
+ backButtonText = '',
91
+ verifyButtonText = '',
92
+ orderDenialCloseButtonText = 'Close',
93
+ orderDenialContinueButtonText = 'Continue',
94
+ organizationNumberLabel = '',
95
+ organizationNumber = '',
96
+ templatePackageId,
97
+ subscriberId,
98
+ userId,
99
+ identityProviderId,
100
+ organizationId,
101
+ redirectUrl,
102
+ language,
103
+ merchantAgreementUrl,
104
+ orderValues,
105
+ paymentMethodsOptions,
106
+ invoiceAddressSelection,
107
+ invoiceLookupNotFoundText,
108
+ errorReqMsg,
109
+ errorValidationTitleMsg,
110
+ errorValidationDenialOrderBlockingMsg,
111
+ errorValidationBlockingOffersMsg,
112
+ orderDenialOfferBaseText,
113
+ orderDenialOfferWithFallbackText,
114
+ orderDenialAmountText,
115
+ fetchDenialFallbackOffer,
116
+ }) => {
117
+ const formSchema = useMemo(
118
+ () => buildFormSchema(errorReqMsg),
119
+ [errorReqMsg]
120
+ );
121
+
122
+ const methods = useForm<EHFFormInputsType>({
123
+ resolver: zodResolver(formSchema),
124
+ defaultValues: {
125
+ ...initialData,
126
+ organizationNumber,
127
+ },
128
+ });
129
+
130
+ const { handleSubmit } = methods;
131
+
132
+ const invoiceOrderFields =
133
+ invoiceAddressSelection?.fields || orderInvoiceContactFields;
134
+
135
+ const orderFields =
136
+ paymentMethodsOptions?.[orderValues?.paymentMethod as PaymentMethodEnum]
137
+ ?.orderFormFields ?? DEFAULT_ORDER_FORM_FIELDS;
138
+
139
+ const {
140
+ orderSubmit,
141
+ continueWithFallbackOffer,
142
+ loading,
143
+ apiErrorMsg,
144
+ errorsMsg,
145
+ orderDenialType,
146
+ orderDenialMessage,
147
+ orderDenialFallbackOffer,
148
+ dismissOrderDenial,
149
+ } = useOrderForm({
150
+ callback,
151
+ submitStartCallback,
152
+ userActionCallback,
153
+ setContactCallback,
154
+ organizationId,
155
+ subscriberId,
156
+ userId,
157
+ identityProviderId,
158
+ orderFields,
159
+ redirectUrl,
160
+ language,
161
+ merchantAgreementUrl,
162
+ paymentMethodsOptions,
163
+ templatePackageId,
164
+ invoiceAddressToggle: orderValues?.invoiceAddressSelection,
165
+ invoiceOrderFields,
166
+ invoiceLookupNotFoundText,
167
+ errorValidationTitleMsg,
168
+ errorValidationDenialOrderBlockingMsg,
169
+ errorValidationBlockingOffersMsg,
170
+ orderDenialOfferBaseText,
171
+ orderDenialOfferWithFallbackText,
172
+ orderDenialAmountText,
173
+ fetchDenialFallbackOffer,
174
+ });
175
+
176
+ const onSubmit: SubmitHandler<EHFFormInputsType> = async (
177
+ data
178
+ ): Promise<void> => {
179
+ orderSubmit({
180
+ ...orderValues,
181
+ organizationNumber: data.organizationNumber,
182
+ });
183
+ };
184
+
185
+ const handleBack = () => {
186
+ userActionCallback?.(UserActionEnum.RETURN_TO_MAIN, null);
187
+ onBack?.();
188
+ };
189
+
190
+ return (
191
+ <FormProvider {...methods}>
192
+ <form
193
+ className={`${className}`}
194
+ noValidate
195
+ onSubmit={handleSubmit(onSubmit)}
196
+ data-testid="ehf-form-id"
197
+ >
198
+ <FieldGroup className="mb-5">
199
+ <InputField
200
+ name="organizationNumber"
201
+ label={organizationNumberLabel}
202
+ required
203
+ readOnly={false}
204
+ />
205
+ </FieldGroup>
206
+ <div className="flex justify-center flex-wrap gap-2">
207
+ <Button
208
+ type="button"
209
+ btnType="default"
210
+ disable={loading}
211
+ buttonText={backButtonText}
212
+ onClick={handleBack}
213
+ />
214
+
215
+ <Button
216
+ type="submit"
217
+ loading={loading}
218
+ buttonText={verifyButtonText}
219
+ />
220
+ </div>
221
+
222
+ {apiErrorMsg && <Alert className="mt-2" msg={apiErrorMsg} />}
223
+ {errorsMsg?.length > 0 &&
224
+ errorsMsg.map((i, index) => (
225
+ <Alert key={index} className="mt-2" msg={i} />
226
+ ))}
227
+ <OrderDenialModal
228
+ isOpen={!!orderDenialType}
229
+ message={orderDenialMessage}
230
+ closeButtonText={orderDenialCloseButtonText}
231
+ continueButtonText={orderDenialContinueButtonText}
232
+ canContinue={
233
+ orderDenialType === 'offer' &&
234
+ !!orderDenialFallbackOffer?.templatePackageId
235
+ }
236
+ offer={
237
+ orderDenialType === 'offer' &&
238
+ !!orderDenialFallbackOffer?.templatePackageId
239
+ ? orderDenialFallbackOffer
240
+ : undefined
241
+ }
242
+ onClose={dismissOrderDenial}
243
+ onContinue={continueWithFallbackOffer}
244
+ />
245
+ </form>
246
+ </FormProvider>
247
+ );
248
+ };
249
+
250
+ export default EHFForm;
File without changes
File without changes
File without changes