@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,62 +1,62 @@
|
|
|
1
|
-
import type { FC } from 'react';
|
|
2
|
-
import { cn } from 'cn';
|
|
3
|
-
|
|
4
|
-
import type { PaymentMethodOptionType } from '../../types/general';
|
|
5
|
-
import { FieldDescription, FieldTitle } from '../ui/field';
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
method: PaymentMethodOptionType;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const PaymentMethodContent: FC<Props> = ({ method }) => {
|
|
12
|
-
const hasIcons = !!method.icons?.length;
|
|
13
|
-
|
|
14
|
-
if (!hasIcons) {
|
|
15
|
-
return (
|
|
16
|
-
<div className="flex flex-1 flex-col gap-0.5">
|
|
17
|
-
<FieldTitle className="sdk-payment-method-label">
|
|
18
|
-
{method.label}
|
|
19
|
-
</FieldTitle>
|
|
20
|
-
{method.description && (
|
|
21
|
-
<FieldDescription className="sdk-payment-method-description">
|
|
22
|
-
{method.description}
|
|
23
|
-
</FieldDescription>
|
|
24
|
-
)}
|
|
25
|
-
</div>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<div className="flex flex-1 flex-col gap-0.5">
|
|
31
|
-
<FieldTitle className="sdk-payment-method-icons min-h-5 flex-wrap items-center gap-1.5">
|
|
32
|
-
{method.description && (
|
|
33
|
-
<span className="sdk-payment-method-label sr-only">
|
|
34
|
-
{method.label}
|
|
35
|
-
</span>
|
|
36
|
-
)}
|
|
37
|
-
{method.icons?.map((icon) => (
|
|
38
|
-
<img
|
|
39
|
-
key={icon.src}
|
|
40
|
-
src={icon.src}
|
|
41
|
-
alt={icon.alt ?? ''}
|
|
42
|
-
className={cn(
|
|
43
|
-
'h-5 w-auto object-contain',
|
|
44
|
-
icon.className
|
|
45
|
-
)}
|
|
46
|
-
/>
|
|
47
|
-
))}
|
|
48
|
-
</FieldTitle>
|
|
49
|
-
{method.description ? (
|
|
50
|
-
<FieldDescription className="sdk-payment-method-description">
|
|
51
|
-
{method.description}
|
|
52
|
-
</FieldDescription>
|
|
53
|
-
) : (
|
|
54
|
-
<FieldDescription className="sdk-payment-method-label">
|
|
55
|
-
{method.label}
|
|
56
|
-
</FieldDescription>
|
|
57
|
-
)}
|
|
58
|
-
</div>
|
|
59
|
-
);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export default PaymentMethodContent;
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import { cn } from 'cn';
|
|
3
|
+
|
|
4
|
+
import type { PaymentMethodOptionType } from '../../types/general';
|
|
5
|
+
import { FieldDescription, FieldTitle } from '../ui/field';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
method: PaymentMethodOptionType;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const PaymentMethodContent: FC<Props> = ({ method }) => {
|
|
12
|
+
const hasIcons = !!method.icons?.length;
|
|
13
|
+
|
|
14
|
+
if (!hasIcons) {
|
|
15
|
+
return (
|
|
16
|
+
<div className="flex flex-1 flex-col gap-0.5">
|
|
17
|
+
<FieldTitle className="sdk-payment-method-label">
|
|
18
|
+
{method.label}
|
|
19
|
+
</FieldTitle>
|
|
20
|
+
{method.description && (
|
|
21
|
+
<FieldDescription className="sdk-payment-method-description">
|
|
22
|
+
{method.description}
|
|
23
|
+
</FieldDescription>
|
|
24
|
+
)}
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className="flex flex-1 flex-col gap-0.5">
|
|
31
|
+
<FieldTitle className="sdk-payment-method-icons min-h-5 flex-wrap items-center gap-1.5">
|
|
32
|
+
{method.description && (
|
|
33
|
+
<span className="sdk-payment-method-label sr-only">
|
|
34
|
+
{method.label}
|
|
35
|
+
</span>
|
|
36
|
+
)}
|
|
37
|
+
{method.icons?.map((icon) => (
|
|
38
|
+
<img
|
|
39
|
+
key={icon.src}
|
|
40
|
+
src={icon.src}
|
|
41
|
+
alt={icon.alt ?? ''}
|
|
42
|
+
className={cn(
|
|
43
|
+
'h-5 w-auto object-contain',
|
|
44
|
+
icon.className
|
|
45
|
+
)}
|
|
46
|
+
/>
|
|
47
|
+
))}
|
|
48
|
+
</FieldTitle>
|
|
49
|
+
{method.description ? (
|
|
50
|
+
<FieldDescription className="sdk-payment-method-description">
|
|
51
|
+
{method.description}
|
|
52
|
+
</FieldDescription>
|
|
53
|
+
) : (
|
|
54
|
+
<FieldDescription className="sdk-payment-method-label">
|
|
55
|
+
{method.label}
|
|
56
|
+
</FieldDescription>
|
|
57
|
+
)}
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default PaymentMethodContent;
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { type FC, useId } from 'react';
|
|
2
|
-
import { type Control, Controller } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { PaymentMethodEnum } from '../../enums/general';
|
|
5
|
-
import type { PaymentMethodOptionType } from '../../types/general';
|
|
6
|
-
import type { OrderFormInputsType } from '../../types/order';
|
|
7
|
-
import { Field, FieldError, FieldLabel, FieldLegend, FieldSet } from '../ui/field';
|
|
8
|
-
import { RadioGroup, RadioGroupItem } from '../ui/radio-group';
|
|
9
|
-
import PaymentMethodContent from './PaymentMethodContent';
|
|
10
|
-
|
|
11
|
-
type Props = {
|
|
12
|
-
control: Control<OrderFormInputsType>;
|
|
13
|
-
paymentMethods: PaymentMethodOptionType[];
|
|
14
|
-
label?: string;
|
|
15
|
-
onChange: (paymentMethod: PaymentMethodEnum) => void;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const PaymentMethodSection: FC<Props> = ({
|
|
19
|
-
control,
|
|
20
|
-
paymentMethods,
|
|
21
|
-
label,
|
|
22
|
-
onChange,
|
|
23
|
-
}) => {
|
|
24
|
-
const groupId = useId();
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<div className="sdk-payment-method-section">
|
|
28
|
-
<Controller
|
|
29
|
-
name="paymentMethod"
|
|
30
|
-
control={control}
|
|
31
|
-
render={({ field, fieldState }) => (
|
|
32
|
-
<FieldSet data-invalid={fieldState.invalid}>
|
|
33
|
-
{label && (
|
|
34
|
-
<FieldLegend variant="label">{label}</FieldLegend>
|
|
35
|
-
)}
|
|
36
|
-
<RadioGroup
|
|
37
|
-
name={field.name}
|
|
38
|
-
value={field.value}
|
|
39
|
-
onValueChange={(value) =>
|
|
40
|
-
onChange(value as PaymentMethodEnum)
|
|
41
|
-
}
|
|
42
|
-
inputRef={field.ref}
|
|
43
|
-
aria-invalid={fieldState.invalid}
|
|
44
|
-
>
|
|
45
|
-
{paymentMethods.map((item) => {
|
|
46
|
-
const itemId = `${groupId}-${item.value}`;
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<FieldLabel
|
|
50
|
-
key={item.value}
|
|
51
|
-
htmlFor={itemId}
|
|
52
|
-
className="*:data-[slot=field]:p-3 sm:*:data-[slot=field]:p-4"
|
|
53
|
-
>
|
|
54
|
-
<Field
|
|
55
|
-
orientation="horizontal"
|
|
56
|
-
data-payment-method={item.value}
|
|
57
|
-
>
|
|
58
|
-
<RadioGroupItem
|
|
59
|
-
id={itemId}
|
|
60
|
-
value={item.value}
|
|
61
|
-
aria-invalid={fieldState.invalid}
|
|
62
|
-
/>
|
|
63
|
-
<PaymentMethodContent
|
|
64
|
-
method={item}
|
|
65
|
-
/>
|
|
66
|
-
</Field>
|
|
67
|
-
</FieldLabel>
|
|
68
|
-
);
|
|
69
|
-
})}
|
|
70
|
-
</RadioGroup>
|
|
71
|
-
<FieldError errors={[fieldState.error]} />
|
|
72
|
-
</FieldSet>
|
|
73
|
-
)}
|
|
74
|
-
/>
|
|
75
|
-
</div>
|
|
76
|
-
);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export default PaymentMethodSection;
|
|
1
|
+
import { type FC, useId } from 'react';
|
|
2
|
+
import { type Control, Controller } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { PaymentMethodEnum } from '../../enums/general';
|
|
5
|
+
import type { PaymentMethodOptionType } from '../../types/general';
|
|
6
|
+
import type { OrderFormInputsType } from '../../types/order';
|
|
7
|
+
import { Field, FieldError, FieldLabel, FieldLegend, FieldSet } from '../ui/field';
|
|
8
|
+
import { RadioGroup, RadioGroupItem } from '../ui/radio-group';
|
|
9
|
+
import PaymentMethodContent from './PaymentMethodContent';
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
control: Control<OrderFormInputsType>;
|
|
13
|
+
paymentMethods: PaymentMethodOptionType[];
|
|
14
|
+
label?: string;
|
|
15
|
+
onChange: (paymentMethod: PaymentMethodEnum) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const PaymentMethodSection: FC<Props> = ({
|
|
19
|
+
control,
|
|
20
|
+
paymentMethods,
|
|
21
|
+
label,
|
|
22
|
+
onChange,
|
|
23
|
+
}) => {
|
|
24
|
+
const groupId = useId();
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div className="sdk-payment-method-section">
|
|
28
|
+
<Controller
|
|
29
|
+
name="paymentMethod"
|
|
30
|
+
control={control}
|
|
31
|
+
render={({ field, fieldState }) => (
|
|
32
|
+
<FieldSet data-invalid={fieldState.invalid}>
|
|
33
|
+
{label && (
|
|
34
|
+
<FieldLegend variant="label">{label}</FieldLegend>
|
|
35
|
+
)}
|
|
36
|
+
<RadioGroup
|
|
37
|
+
name={field.name}
|
|
38
|
+
value={field.value}
|
|
39
|
+
onValueChange={(value) =>
|
|
40
|
+
onChange(value as PaymentMethodEnum)
|
|
41
|
+
}
|
|
42
|
+
inputRef={field.ref}
|
|
43
|
+
aria-invalid={fieldState.invalid}
|
|
44
|
+
>
|
|
45
|
+
{paymentMethods.map((item) => {
|
|
46
|
+
const itemId = `${groupId}-${item.value}`;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<FieldLabel
|
|
50
|
+
key={item.value}
|
|
51
|
+
htmlFor={itemId}
|
|
52
|
+
className="*:data-[slot=field]:p-3 sm:*:data-[slot=field]:p-4"
|
|
53
|
+
>
|
|
54
|
+
<Field
|
|
55
|
+
orientation="horizontal"
|
|
56
|
+
data-payment-method={item.value}
|
|
57
|
+
>
|
|
58
|
+
<RadioGroupItem
|
|
59
|
+
id={itemId}
|
|
60
|
+
value={item.value}
|
|
61
|
+
aria-invalid={fieldState.invalid}
|
|
62
|
+
/>
|
|
63
|
+
<PaymentMethodContent
|
|
64
|
+
method={item}
|
|
65
|
+
/>
|
|
66
|
+
</Field>
|
|
67
|
+
</FieldLabel>
|
|
68
|
+
);
|
|
69
|
+
})}
|
|
70
|
+
</RadioGroup>
|
|
71
|
+
<FieldError errors={[fieldState.error]} />
|
|
72
|
+
</FieldSet>
|
|
73
|
+
)}
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default PaymentMethodSection;
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import type { FC } from 'react';
|
|
2
|
-
|
|
3
|
-
import type { SubmitConfirmationType } from '../../types/general';
|
|
4
|
-
import {
|
|
5
|
-
AlertDialog,
|
|
6
|
-
AlertDialogAction,
|
|
7
|
-
AlertDialogCancel,
|
|
8
|
-
AlertDialogContent,
|
|
9
|
-
AlertDialogDescription,
|
|
10
|
-
AlertDialogFooter,
|
|
11
|
-
AlertDialogHeader,
|
|
12
|
-
AlertDialogTitle,
|
|
13
|
-
} from '../ui/alert-dialog';
|
|
14
|
-
|
|
15
|
-
type Props = {
|
|
16
|
-
isOpen: boolean;
|
|
17
|
-
confirmation: SubmitConfirmationType;
|
|
18
|
-
onConfirm: () => void;
|
|
19
|
-
onCancel: () => void;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const SubmitConfirmationDialog: FC<Props> = ({
|
|
23
|
-
isOpen,
|
|
24
|
-
confirmation,
|
|
25
|
-
onConfirm,
|
|
26
|
-
onCancel,
|
|
27
|
-
}) => (
|
|
28
|
-
<AlertDialog
|
|
29
|
-
open={isOpen}
|
|
30
|
-
onOpenChange={(open) => {
|
|
31
|
-
if (!open) onCancel();
|
|
32
|
-
}}
|
|
33
|
-
>
|
|
34
|
-
<AlertDialogContent data-testid="sdk-submit-confirmation-dialog">
|
|
35
|
-
<AlertDialogHeader>
|
|
36
|
-
<AlertDialogTitle>{confirmation.title}</AlertDialogTitle>
|
|
37
|
-
{confirmation.description && (
|
|
38
|
-
<AlertDialogDescription>
|
|
39
|
-
{confirmation.description}
|
|
40
|
-
</AlertDialogDescription>
|
|
41
|
-
)}
|
|
42
|
-
</AlertDialogHeader>
|
|
43
|
-
<AlertDialogFooter>
|
|
44
|
-
<AlertDialogCancel variant="ghost">
|
|
45
|
-
{confirmation.cancelText}
|
|
46
|
-
</AlertDialogCancel>
|
|
47
|
-
<AlertDialogAction onClick={onConfirm}>
|
|
48
|
-
{confirmation.confirmText}
|
|
49
|
-
</AlertDialogAction>
|
|
50
|
-
</AlertDialogFooter>
|
|
51
|
-
</AlertDialogContent>
|
|
52
|
-
</AlertDialog>
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
export default SubmitConfirmationDialog;
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { SubmitConfirmationType } from '../../types/general';
|
|
4
|
+
import {
|
|
5
|
+
AlertDialog,
|
|
6
|
+
AlertDialogAction,
|
|
7
|
+
AlertDialogCancel,
|
|
8
|
+
AlertDialogContent,
|
|
9
|
+
AlertDialogDescription,
|
|
10
|
+
AlertDialogFooter,
|
|
11
|
+
AlertDialogHeader,
|
|
12
|
+
AlertDialogTitle,
|
|
13
|
+
} from '../ui/alert-dialog';
|
|
14
|
+
|
|
15
|
+
type Props = {
|
|
16
|
+
isOpen: boolean;
|
|
17
|
+
confirmation: SubmitConfirmationType;
|
|
18
|
+
onConfirm: () => void;
|
|
19
|
+
onCancel: () => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const SubmitConfirmationDialog: FC<Props> = ({
|
|
23
|
+
isOpen,
|
|
24
|
+
confirmation,
|
|
25
|
+
onConfirm,
|
|
26
|
+
onCancel,
|
|
27
|
+
}) => (
|
|
28
|
+
<AlertDialog
|
|
29
|
+
open={isOpen}
|
|
30
|
+
onOpenChange={(open) => {
|
|
31
|
+
if (!open) onCancel();
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<AlertDialogContent data-testid="sdk-submit-confirmation-dialog">
|
|
35
|
+
<AlertDialogHeader>
|
|
36
|
+
<AlertDialogTitle>{confirmation.title}</AlertDialogTitle>
|
|
37
|
+
{confirmation.description && (
|
|
38
|
+
<AlertDialogDescription>
|
|
39
|
+
{confirmation.description}
|
|
40
|
+
</AlertDialogDescription>
|
|
41
|
+
)}
|
|
42
|
+
</AlertDialogHeader>
|
|
43
|
+
<AlertDialogFooter>
|
|
44
|
+
<AlertDialogCancel variant="ghost">
|
|
45
|
+
{confirmation.cancelText}
|
|
46
|
+
</AlertDialogCancel>
|
|
47
|
+
<AlertDialogAction onClick={onConfirm}>
|
|
48
|
+
{confirmation.confirmText}
|
|
49
|
+
</AlertDialogAction>
|
|
50
|
+
</AlertDialogFooter>
|
|
51
|
+
</AlertDialogContent>
|
|
52
|
+
</AlertDialog>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export default SubmitConfirmationDialog;
|