@infosoftas/s4-orders-js-sdk 0.0.1-alpha2c.3 → 0.0.1-beta1
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/package.json +1 -1
- package/src/App.tsx +20 -4
- package/src/components/EHFForm/EHFForm.tsx +3 -0
- package/src/components/OIOForm/OIOForm.tsx +3 -0
- package/src/components/OrderForm/OrderForm.tsx +91 -35
- package/src/constants/index.ts +5 -0
- package/src/types/general.ts +3 -0
- package/src/types/order.ts +1 -0
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -40,6 +40,7 @@ const App: FC<ConfigType> = ({
|
|
|
40
40
|
paymentMethodsOptions,
|
|
41
41
|
invoiceAddressSelection,
|
|
42
42
|
availablePaymentMethods = [],
|
|
43
|
+
allowedPaymentMethods,
|
|
43
44
|
language = 'en-US',
|
|
44
45
|
merchantAgreementUrl = '',
|
|
45
46
|
settings = {
|
|
@@ -49,10 +50,15 @@ const App: FC<ConfigType> = ({
|
|
|
49
50
|
submitButtonText: 'Start',
|
|
50
51
|
backButtonText: 'Back',
|
|
51
52
|
verifyButtonText: 'Verify',
|
|
52
|
-
organizationNumberLabel: '
|
|
53
|
+
organizationNumberLabel: 'Organization Number',
|
|
53
54
|
paymentMethodLabel: '',
|
|
54
55
|
glnLabel: 'GLN',
|
|
56
|
+
cvrLabel: 'CVR',
|
|
55
57
|
orderDefaultValues: undefined,
|
|
58
|
+
errorReqMsg: '',
|
|
59
|
+
errorInvalidEmailMsg: '',
|
|
60
|
+
errorInvalidPhoneMsg: '',
|
|
61
|
+
paymentMethodNotAllowedMsg: '',
|
|
56
62
|
},
|
|
57
63
|
}) => {
|
|
58
64
|
const [loading, setLoading] = useState<boolean>(false);
|
|
@@ -283,10 +289,11 @@ const App: FC<ConfigType> = ({
|
|
|
283
289
|
callback={handleInvoiceForm}
|
|
284
290
|
backButtonText={settings?.backButtonText}
|
|
285
291
|
verifyButtonText={settings?.verifyButtonText}
|
|
286
|
-
organizationNumberLabel={
|
|
287
|
-
settings?.organizationNumberLabel
|
|
288
|
-
}
|
|
292
|
+
organizationNumberLabel={settings?.cvrLabel}
|
|
289
293
|
glnLabel={settings?.glnLabel}
|
|
294
|
+
organizationNumber={
|
|
295
|
+
orderFormValues?.organizationNumber
|
|
296
|
+
}
|
|
290
297
|
/>
|
|
291
298
|
)}
|
|
292
299
|
{formType === FormTypeEnum.EHF && (
|
|
@@ -298,6 +305,9 @@ const App: FC<ConfigType> = ({
|
|
|
298
305
|
organizationNumberLabel={
|
|
299
306
|
settings?.organizationNumberLabel
|
|
300
307
|
}
|
|
308
|
+
organizationNumber={
|
|
309
|
+
orderFormValues?.organizationNumber
|
|
310
|
+
}
|
|
301
311
|
/>
|
|
302
312
|
)}
|
|
303
313
|
{formType !== FormTypeEnum.OIO &&
|
|
@@ -311,12 +321,18 @@ const App: FC<ConfigType> = ({
|
|
|
311
321
|
identityProviderId={identityProviderId}
|
|
312
322
|
organizationId={organizationId}
|
|
313
323
|
paymentMethods={availablePaymentMethods}
|
|
324
|
+
allowedPaymentMethods={
|
|
325
|
+
allowedPaymentMethods
|
|
326
|
+
}
|
|
314
327
|
submitButtonText={
|
|
315
328
|
settings?.submitButtonText
|
|
316
329
|
}
|
|
317
330
|
paymentMethodLabel={
|
|
318
331
|
settings?.paymentMethodLabel
|
|
319
332
|
}
|
|
333
|
+
paymentMethodNotAllowedMsg={
|
|
334
|
+
settings?.paymentMethodNotAllowedMsg
|
|
335
|
+
}
|
|
320
336
|
errorReqMsg={settings?.errorReqMsg}
|
|
321
337
|
errorInvalidEmailMsg={
|
|
322
338
|
settings?.errorInvalidEmailMsg
|
|
@@ -18,6 +18,7 @@ type Props = {
|
|
|
18
18
|
backButtonText?: string;
|
|
19
19
|
verifyButtonText?: string;
|
|
20
20
|
organizationNumberLabel?: string;
|
|
21
|
+
organizationNumber?: string;
|
|
21
22
|
className?: string;
|
|
22
23
|
};
|
|
23
24
|
|
|
@@ -35,6 +36,7 @@ const EHFForm: FC<Props> = ({
|
|
|
35
36
|
backButtonText = '',
|
|
36
37
|
verifyButtonText = '',
|
|
37
38
|
organizationNumberLabel = '',
|
|
39
|
+
organizationNumber = '',
|
|
38
40
|
className = '',
|
|
39
41
|
}) => {
|
|
40
42
|
const [loading, setLoading] = useState<boolean>(false);
|
|
@@ -44,6 +46,7 @@ const EHFForm: FC<Props> = ({
|
|
|
44
46
|
const methods = useForm<EHFFormInputsType>({
|
|
45
47
|
defaultValues: {
|
|
46
48
|
...initialData,
|
|
49
|
+
organizationNumber,
|
|
47
50
|
},
|
|
48
51
|
});
|
|
49
52
|
|
|
@@ -18,6 +18,7 @@ type Props = {
|
|
|
18
18
|
backButtonText?: string;
|
|
19
19
|
verifyButtonText?: string;
|
|
20
20
|
organizationNumberLabel?: string;
|
|
21
|
+
organizationNumber?: string;
|
|
21
22
|
glnLabel?: string;
|
|
22
23
|
className?: string;
|
|
23
24
|
};
|
|
@@ -38,6 +39,7 @@ const EHFForm: FC<Props> = ({
|
|
|
38
39
|
backButtonText = '',
|
|
39
40
|
verifyButtonText = '',
|
|
40
41
|
organizationNumberLabel = '',
|
|
42
|
+
organizationNumber = '',
|
|
41
43
|
glnLabel = '',
|
|
42
44
|
className = '',
|
|
43
45
|
}) => {
|
|
@@ -48,6 +50,7 @@ const EHFForm: FC<Props> = ({
|
|
|
48
50
|
const methods = useForm<OIOFormInputsType>({
|
|
49
51
|
defaultValues: {
|
|
50
52
|
...initialData,
|
|
53
|
+
cvr: organizationNumber,
|
|
51
54
|
},
|
|
52
55
|
});
|
|
53
56
|
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { FC, ChangeEvent, Suspense, useState } from 'react';
|
|
1
|
+
import { FC, ChangeEvent, Suspense, useState, useMemo } from 'react';
|
|
2
2
|
import { FormProvider, useForm, SubmitHandler } from 'react-hook-form';
|
|
3
3
|
|
|
4
4
|
import { createSubscriber, mapSubscriberToUser } from '../../api/SubscribeApi';
|
|
5
5
|
import { orderStart } from '../../api/OrdersApi';
|
|
6
6
|
import { PaymentMethodEnum } from '../../enums/general';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
WRONG_MSG,
|
|
9
|
+
PAYMENT_METHOD_DEFAULT,
|
|
10
|
+
INVOICE_ALLOWED_PAYMENT_METHODS,
|
|
11
|
+
} from '../../constants/index';
|
|
8
12
|
import Alert from '../Alert/Alert';
|
|
9
13
|
import Button from '../Button/Button';
|
|
10
14
|
import ToggleField from '../FormFields/ToggleFiled';
|
|
@@ -44,8 +48,10 @@ type Props = {
|
|
|
44
48
|
paymentMethodsOptions?: PaymentMethodOptionsType;
|
|
45
49
|
defaultValues?: OrderFormInputsType;
|
|
46
50
|
paymentMethods?: { label: string; value: PaymentMethodEnum }[];
|
|
51
|
+
allowedPaymentMethods?: PaymentMethodEnum[];
|
|
47
52
|
submitButtonText?: string;
|
|
48
53
|
paymentMethodLabel?: string;
|
|
54
|
+
paymentMethodNotAllowedMsg?: string;
|
|
49
55
|
errorReqMsg?: string;
|
|
50
56
|
errorInvalidEmailMsg?: string;
|
|
51
57
|
errorInvalidPhoneMsg?: string;
|
|
@@ -53,6 +59,7 @@ type Props = {
|
|
|
53
59
|
enabled?: boolean;
|
|
54
60
|
label?: string;
|
|
55
61
|
fields?: OrderFormFiledType[];
|
|
62
|
+
paymentMethods?: PaymentMethodEnum[];
|
|
56
63
|
};
|
|
57
64
|
};
|
|
58
65
|
|
|
@@ -84,9 +91,11 @@ const OrderForm: FC<Props> = ({
|
|
|
84
91
|
language,
|
|
85
92
|
merchantAgreementUrl,
|
|
86
93
|
paymentMethods = [],
|
|
94
|
+
allowedPaymentMethods,
|
|
87
95
|
invoiceAddressSelection,
|
|
88
96
|
submitButtonText = 'Start',
|
|
89
97
|
paymentMethodLabel = 'Select Payment Method',
|
|
98
|
+
paymentMethodNotAllowedMsg = 'This payment method not allowed!',
|
|
90
99
|
errorReqMsg = '',
|
|
91
100
|
errorInvalidEmailMsg = '',
|
|
92
101
|
errorInvalidPhoneMsg = '',
|
|
@@ -111,6 +120,10 @@ const OrderForm: FC<Props> = ({
|
|
|
111
120
|
const invoiceOrderFields =
|
|
112
121
|
invoiceAddressSelection?.fields || orderInvoiceContactFields;
|
|
113
122
|
|
|
123
|
+
const invoicePaymentMethods =
|
|
124
|
+
invoiceAddressSelection?.paymentMethods ||
|
|
125
|
+
INVOICE_ALLOWED_PAYMENT_METHODS;
|
|
126
|
+
|
|
114
127
|
const {
|
|
115
128
|
register,
|
|
116
129
|
handleSubmit,
|
|
@@ -120,6 +133,7 @@ const OrderForm: FC<Props> = ({
|
|
|
120
133
|
} = methods;
|
|
121
134
|
|
|
122
135
|
const invoiceAddressToggle = watch('invoiceAddressSelection');
|
|
136
|
+
const paymentMethodInput = watch('paymentMethod');
|
|
123
137
|
|
|
124
138
|
const onSubmit: SubmitHandler<OrderFormInputsType> = async (
|
|
125
139
|
data
|
|
@@ -221,8 +235,29 @@ const OrderForm: FC<Props> = ({
|
|
|
221
235
|
paymentMethodsOptions?.[e.target.value as PaymentMethodEnum]
|
|
222
236
|
?.orderFormFields ?? DEFAULT_ORDER_FORM_FIELDS;
|
|
223
237
|
setOrderFields(orderFieldsLocal);
|
|
238
|
+
if (
|
|
239
|
+
!invoicePaymentMethods.includes(e.target.value as PaymentMethodEnum)
|
|
240
|
+
) {
|
|
241
|
+
setValue('invoiceAddressSelection', false);
|
|
242
|
+
}
|
|
224
243
|
};
|
|
225
244
|
|
|
245
|
+
const allowPaymentMethod = useMemo(() => {
|
|
246
|
+
if (!allowedPaymentMethods || allowedPaymentMethods?.length === 0) {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (
|
|
251
|
+
allowedPaymentMethods.includes(
|
|
252
|
+
paymentMethodInput as PaymentMethodEnum
|
|
253
|
+
)
|
|
254
|
+
) {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return false;
|
|
259
|
+
}, [allowedPaymentMethods, paymentMethodInput]);
|
|
260
|
+
|
|
226
261
|
return (
|
|
227
262
|
<FormProvider {...methods}>
|
|
228
263
|
<form
|
|
@@ -263,7 +298,7 @@ const OrderForm: FC<Props> = ({
|
|
|
263
298
|
)}
|
|
264
299
|
</div>
|
|
265
300
|
)}
|
|
266
|
-
{orderFields?.length > 0 && (
|
|
301
|
+
{orderFields?.length > 0 && allowPaymentMethod && (
|
|
267
302
|
<Suspense fallback={null}>
|
|
268
303
|
{orderFields.map((field) => {
|
|
269
304
|
const Component = formFieldsMapper[field.name];
|
|
@@ -284,42 +319,63 @@ const OrderForm: FC<Props> = ({
|
|
|
284
319
|
})}
|
|
285
320
|
</Suspense>
|
|
286
321
|
)}
|
|
287
|
-
{invoiceAddressSelection?.enabled &&
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
322
|
+
{invoiceAddressSelection?.enabled &&
|
|
323
|
+
allowPaymentMethod &&
|
|
324
|
+
invoicePaymentMethods.includes(
|
|
325
|
+
paymentMethodInput as PaymentMethodEnum
|
|
326
|
+
) && (
|
|
327
|
+
<ToggleField
|
|
328
|
+
name="invoiceAddressSelection"
|
|
329
|
+
label={
|
|
330
|
+
invoiceAddressSelection?.label ??
|
|
331
|
+
'Invoice Address'
|
|
332
|
+
}
|
|
333
|
+
/>
|
|
334
|
+
)}
|
|
335
|
+
{invoiceAddressToggle &&
|
|
336
|
+
invoiceOrderFields?.length > 0 &&
|
|
337
|
+
allowPaymentMethod && (
|
|
338
|
+
<Suspense fallback={null}>
|
|
339
|
+
{invoiceOrderFields.map((field) => {
|
|
340
|
+
const Component = formFieldsMapper[field.name];
|
|
299
341
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
342
|
+
return Component ? (
|
|
343
|
+
<Component
|
|
344
|
+
key={field.name}
|
|
345
|
+
name={field.name}
|
|
346
|
+
label={field.label}
|
|
347
|
+
required={field.required || false}
|
|
348
|
+
readOnly={field.readOnly || false}
|
|
349
|
+
errors={errors}
|
|
350
|
+
errorReqMsg={errorReqMsg}
|
|
351
|
+
errorInvalidEmailMsg={
|
|
352
|
+
errorInvalidEmailMsg
|
|
353
|
+
}
|
|
354
|
+
errorInvalidPhoneMsg={
|
|
355
|
+
errorInvalidPhoneMsg
|
|
356
|
+
}
|
|
357
|
+
/>
|
|
358
|
+
) : null;
|
|
359
|
+
})}
|
|
360
|
+
</Suspense>
|
|
361
|
+
)}
|
|
362
|
+
{allowPaymentMethod && (
|
|
363
|
+
<Button
|
|
364
|
+
type="submit"
|
|
365
|
+
loading={loading}
|
|
366
|
+
buttonText={submitButtonText}
|
|
367
|
+
/>
|
|
315
368
|
)}
|
|
316
|
-
<
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
369
|
+
<Alert
|
|
370
|
+
className="mt-2"
|
|
371
|
+
msg={
|
|
372
|
+
allowPaymentMethod
|
|
373
|
+
? apiErrorMsg
|
|
374
|
+
: paymentMethodNotAllowedMsg
|
|
375
|
+
}
|
|
320
376
|
/>
|
|
321
|
-
<Alert className="mt-2" msg={apiErrorMsg} />
|
|
322
377
|
{errorsMsg?.length > 0 &&
|
|
378
|
+
allowPaymentMethod &&
|
|
323
379
|
errorsMsg.map((i) => <Alert className="mt-2" msg={i} />)}
|
|
324
380
|
</form>
|
|
325
381
|
</FormProvider>
|
package/src/constants/index.ts
CHANGED
package/src/types/general.ts
CHANGED
|
@@ -36,6 +36,7 @@ export type ConfigType = {
|
|
|
36
36
|
redirectUrl?: string;
|
|
37
37
|
showIframe?: boolean;
|
|
38
38
|
availablePaymentMethods?: { label: string; value: PaymentMethodEnum }[];
|
|
39
|
+
allowedPaymentMethods?: PaymentMethodEnum[];
|
|
39
40
|
paymentMethodsOptions?: PaymentMethodOptionsType;
|
|
40
41
|
language?: string;
|
|
41
42
|
merchantAgreementUrl?: string;
|
|
@@ -51,12 +52,14 @@ export type ConfigType = {
|
|
|
51
52
|
backButtonText?: string;
|
|
52
53
|
verifyButtonText?: string;
|
|
53
54
|
organizationNumberLabel?: string;
|
|
55
|
+
cvrLabel?: string;
|
|
54
56
|
glnLabel?: string;
|
|
55
57
|
orderDefaultValues?: OrderFormInputsType;
|
|
56
58
|
paymentMethodLabel?: string;
|
|
57
59
|
errorReqMsg?: string;
|
|
58
60
|
errorInvalidEmailMsg?: string;
|
|
59
61
|
errorInvalidPhoneMsg?: string;
|
|
62
|
+
paymentMethodNotAllowedMsg?: string;
|
|
60
63
|
};
|
|
61
64
|
};
|
|
62
65
|
|