@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,102 +1,102 @@
|
|
|
1
|
-
import type { FC } from 'react';
|
|
2
|
-
|
|
3
|
-
import type { OrderDenialFallbackOfferType } 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
|
-
message?: string;
|
|
18
|
-
offer?: OrderDenialFallbackOfferType;
|
|
19
|
-
canContinue?: boolean;
|
|
20
|
-
closeButtonText?: string;
|
|
21
|
-
continueButtonText?: string;
|
|
22
|
-
onContinue: () => void;
|
|
23
|
-
onClose: () => void;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const splitMessage = (message = '') => {
|
|
27
|
-
const [title = '', ...rest] = message
|
|
28
|
-
.replace(/\\n/g, '\n')
|
|
29
|
-
.split(/\n\s*\n/)
|
|
30
|
-
.map((part) => part.trim())
|
|
31
|
-
.filter(Boolean);
|
|
32
|
-
|
|
33
|
-
return { title, description: rest.join('\n\n') };
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const OrderDenialModal: FC<Props> = ({
|
|
37
|
-
isOpen,
|
|
38
|
-
message,
|
|
39
|
-
offer,
|
|
40
|
-
canContinue = true,
|
|
41
|
-
closeButtonText = 'Close',
|
|
42
|
-
continueButtonText = 'Continue',
|
|
43
|
-
onContinue,
|
|
44
|
-
onClose,
|
|
45
|
-
}) => {
|
|
46
|
-
const { title, description } = splitMessage(message);
|
|
47
|
-
const showOffer = !!offer?.title && !!offer?.templatePackageId;
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<AlertDialog
|
|
51
|
-
open={isOpen}
|
|
52
|
-
onOpenChange={(open) => {
|
|
53
|
-
if (!open) onClose();
|
|
54
|
-
}}
|
|
55
|
-
>
|
|
56
|
-
<AlertDialogContent data-testid="sdk-order-denial-modal">
|
|
57
|
-
<AlertDialogHeader>
|
|
58
|
-
<AlertDialogTitle className="whitespace-pre-line">
|
|
59
|
-
{title}
|
|
60
|
-
</AlertDialogTitle>
|
|
61
|
-
{description && (
|
|
62
|
-
<AlertDialogDescription className="whitespace-pre-line">
|
|
63
|
-
{description}
|
|
64
|
-
</AlertDialogDescription>
|
|
65
|
-
)}
|
|
66
|
-
</AlertDialogHeader>
|
|
67
|
-
|
|
68
|
-
{showOffer && (
|
|
69
|
-
<div
|
|
70
|
-
className="flex flex-col gap-1 rounded-2xl bg-muted p-4 text-sm"
|
|
71
|
-
data-testid="sdk-order-denial-offer"
|
|
72
|
-
>
|
|
73
|
-
<p className="font-medium">{offer?.title}</p>
|
|
74
|
-
{offer?.description && (
|
|
75
|
-
<p className="text-muted-foreground">
|
|
76
|
-
{offer.description}
|
|
77
|
-
</p>
|
|
78
|
-
)}
|
|
79
|
-
{offer?.price && (
|
|
80
|
-
<p className="mt-1 font-semibold tabular-nums">
|
|
81
|
-
{offer.price}
|
|
82
|
-
</p>
|
|
83
|
-
)}
|
|
84
|
-
</div>
|
|
85
|
-
)}
|
|
86
|
-
|
|
87
|
-
<AlertDialogFooter>
|
|
88
|
-
<AlertDialogCancel variant="ghost">
|
|
89
|
-
{closeButtonText}
|
|
90
|
-
</AlertDialogCancel>
|
|
91
|
-
{canContinue && (
|
|
92
|
-
<AlertDialogAction onClick={onContinue}>
|
|
93
|
-
{continueButtonText}
|
|
94
|
-
</AlertDialogAction>
|
|
95
|
-
)}
|
|
96
|
-
</AlertDialogFooter>
|
|
97
|
-
</AlertDialogContent>
|
|
98
|
-
</AlertDialog>
|
|
99
|
-
);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export default OrderDenialModal;
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { OrderDenialFallbackOfferType } 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
|
+
message?: string;
|
|
18
|
+
offer?: OrderDenialFallbackOfferType;
|
|
19
|
+
canContinue?: boolean;
|
|
20
|
+
closeButtonText?: string;
|
|
21
|
+
continueButtonText?: string;
|
|
22
|
+
onContinue: () => void;
|
|
23
|
+
onClose: () => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const splitMessage = (message = '') => {
|
|
27
|
+
const [title = '', ...rest] = message
|
|
28
|
+
.replace(/\\n/g, '\n')
|
|
29
|
+
.split(/\n\s*\n/)
|
|
30
|
+
.map((part) => part.trim())
|
|
31
|
+
.filter(Boolean);
|
|
32
|
+
|
|
33
|
+
return { title, description: rest.join('\n\n') };
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const OrderDenialModal: FC<Props> = ({
|
|
37
|
+
isOpen,
|
|
38
|
+
message,
|
|
39
|
+
offer,
|
|
40
|
+
canContinue = true,
|
|
41
|
+
closeButtonText = 'Close',
|
|
42
|
+
continueButtonText = 'Continue',
|
|
43
|
+
onContinue,
|
|
44
|
+
onClose,
|
|
45
|
+
}) => {
|
|
46
|
+
const { title, description } = splitMessage(message);
|
|
47
|
+
const showOffer = !!offer?.title && !!offer?.templatePackageId;
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<AlertDialog
|
|
51
|
+
open={isOpen}
|
|
52
|
+
onOpenChange={(open) => {
|
|
53
|
+
if (!open) onClose();
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
<AlertDialogContent data-testid="sdk-order-denial-modal">
|
|
57
|
+
<AlertDialogHeader>
|
|
58
|
+
<AlertDialogTitle className="whitespace-pre-line">
|
|
59
|
+
{title}
|
|
60
|
+
</AlertDialogTitle>
|
|
61
|
+
{description && (
|
|
62
|
+
<AlertDialogDescription className="whitespace-pre-line">
|
|
63
|
+
{description}
|
|
64
|
+
</AlertDialogDescription>
|
|
65
|
+
)}
|
|
66
|
+
</AlertDialogHeader>
|
|
67
|
+
|
|
68
|
+
{showOffer && (
|
|
69
|
+
<div
|
|
70
|
+
className="flex flex-col gap-1 rounded-2xl bg-muted p-4 text-sm"
|
|
71
|
+
data-testid="sdk-order-denial-offer"
|
|
72
|
+
>
|
|
73
|
+
<p className="font-medium">{offer?.title}</p>
|
|
74
|
+
{offer?.description && (
|
|
75
|
+
<p className="text-muted-foreground">
|
|
76
|
+
{offer.description}
|
|
77
|
+
</p>
|
|
78
|
+
)}
|
|
79
|
+
{offer?.price && (
|
|
80
|
+
<p className="mt-1 font-semibold tabular-nums">
|
|
81
|
+
{offer.price}
|
|
82
|
+
</p>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
)}
|
|
86
|
+
|
|
87
|
+
<AlertDialogFooter>
|
|
88
|
+
<AlertDialogCancel variant="ghost">
|
|
89
|
+
{closeButtonText}
|
|
90
|
+
</AlertDialogCancel>
|
|
91
|
+
{canContinue && (
|
|
92
|
+
<AlertDialogAction onClick={onContinue}>
|
|
93
|
+
{continueButtonText}
|
|
94
|
+
</AlertDialogAction>
|
|
95
|
+
)}
|
|
96
|
+
</AlertDialogFooter>
|
|
97
|
+
</AlertDialogContent>
|
|
98
|
+
</AlertDialog>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export default OrderDenialModal;
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import type { FC } from 'react';
|
|
2
|
-
|
|
3
|
-
import formFieldsMapper from '../FormFields/FormFieldsMapper';
|
|
4
|
-
import ToggleField from '../FormFields/ToggleFiled';
|
|
5
|
-
import type { OrderFormFieldType } from '../../types/general';
|
|
6
|
-
import { FieldGroup, FieldLegend, FieldSet } from '../ui/field';
|
|
7
|
-
|
|
8
|
-
type FieldListProps = {
|
|
9
|
-
fields: OrderFormFieldType[];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const FieldList: FC<FieldListProps> = ({ fields }) => (
|
|
13
|
-
<>
|
|
14
|
-
{fields.map((field) => {
|
|
15
|
-
const Component = formFieldsMapper[field.name];
|
|
16
|
-
|
|
17
|
-
return Component ? (
|
|
18
|
-
<Component
|
|
19
|
-
key={field.name}
|
|
20
|
-
name={field.name}
|
|
21
|
-
label={field.label}
|
|
22
|
-
required={field.required || false}
|
|
23
|
-
readOnly={field.readOnly || false}
|
|
24
|
-
/>
|
|
25
|
-
) : null;
|
|
26
|
-
})}
|
|
27
|
-
</>
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
type Props = {
|
|
31
|
-
label?: string;
|
|
32
|
-
orderFields: OrderFormFieldType[];
|
|
33
|
-
invoiceOrderFields: OrderFormFieldType[];
|
|
34
|
-
showOrderFields: boolean;
|
|
35
|
-
showInvoiceToggle: boolean;
|
|
36
|
-
showInvoiceFields: boolean;
|
|
37
|
-
invoiceToggleLabel?: string;
|
|
38
|
-
onInvoiceToggle?: (value: boolean) => void;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const ContactDetailsSection: FC<Props> = ({
|
|
42
|
-
label,
|
|
43
|
-
orderFields,
|
|
44
|
-
invoiceOrderFields,
|
|
45
|
-
showOrderFields,
|
|
46
|
-
showInvoiceToggle,
|
|
47
|
-
showInvoiceFields,
|
|
48
|
-
invoiceToggleLabel,
|
|
49
|
-
onInvoiceToggle,
|
|
50
|
-
}) => (
|
|
51
|
-
<div className="sdk-order-details-section">
|
|
52
|
-
<FieldSet>
|
|
53
|
-
{label && <FieldLegend variant="label">{label}</FieldLegend>}
|
|
54
|
-
<FieldGroup>
|
|
55
|
-
{showOrderFields && <FieldList fields={orderFields} />}
|
|
56
|
-
{showInvoiceToggle && (
|
|
57
|
-
<ToggleField
|
|
58
|
-
name="invoiceAddressSelection"
|
|
59
|
-
label={invoiceToggleLabel ?? 'Invoice Address'}
|
|
60
|
-
toggleCallback={onInvoiceToggle}
|
|
61
|
-
/>
|
|
62
|
-
)}
|
|
63
|
-
{showInvoiceFields && (
|
|
64
|
-
<FieldList fields={invoiceOrderFields} />
|
|
65
|
-
)}
|
|
66
|
-
</FieldGroup>
|
|
67
|
-
</FieldSet>
|
|
68
|
-
</div>
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
export default ContactDetailsSection;
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
|
|
3
|
+
import formFieldsMapper from '../FormFields/FormFieldsMapper';
|
|
4
|
+
import ToggleField from '../FormFields/ToggleFiled';
|
|
5
|
+
import type { OrderFormFieldType } from '../../types/general';
|
|
6
|
+
import { FieldGroup, FieldLegend, FieldSet } from '../ui/field';
|
|
7
|
+
|
|
8
|
+
type FieldListProps = {
|
|
9
|
+
fields: OrderFormFieldType[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const FieldList: FC<FieldListProps> = ({ fields }) => (
|
|
13
|
+
<>
|
|
14
|
+
{fields.map((field) => {
|
|
15
|
+
const Component = formFieldsMapper[field.name];
|
|
16
|
+
|
|
17
|
+
return Component ? (
|
|
18
|
+
<Component
|
|
19
|
+
key={field.name}
|
|
20
|
+
name={field.name}
|
|
21
|
+
label={field.label}
|
|
22
|
+
required={field.required || false}
|
|
23
|
+
readOnly={field.readOnly || false}
|
|
24
|
+
/>
|
|
25
|
+
) : null;
|
|
26
|
+
})}
|
|
27
|
+
</>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
type Props = {
|
|
31
|
+
label?: string;
|
|
32
|
+
orderFields: OrderFormFieldType[];
|
|
33
|
+
invoiceOrderFields: OrderFormFieldType[];
|
|
34
|
+
showOrderFields: boolean;
|
|
35
|
+
showInvoiceToggle: boolean;
|
|
36
|
+
showInvoiceFields: boolean;
|
|
37
|
+
invoiceToggleLabel?: string;
|
|
38
|
+
onInvoiceToggle?: (value: boolean) => void;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const ContactDetailsSection: FC<Props> = ({
|
|
42
|
+
label,
|
|
43
|
+
orderFields,
|
|
44
|
+
invoiceOrderFields,
|
|
45
|
+
showOrderFields,
|
|
46
|
+
showInvoiceToggle,
|
|
47
|
+
showInvoiceFields,
|
|
48
|
+
invoiceToggleLabel,
|
|
49
|
+
onInvoiceToggle,
|
|
50
|
+
}) => (
|
|
51
|
+
<div className="sdk-order-details-section">
|
|
52
|
+
<FieldSet>
|
|
53
|
+
{label && <FieldLegend variant="label">{label}</FieldLegend>}
|
|
54
|
+
<FieldGroup>
|
|
55
|
+
{showOrderFields && <FieldList fields={orderFields} />}
|
|
56
|
+
{showInvoiceToggle && (
|
|
57
|
+
<ToggleField
|
|
58
|
+
name="invoiceAddressSelection"
|
|
59
|
+
label={invoiceToggleLabel ?? 'Invoice Address'}
|
|
60
|
+
toggleCallback={onInvoiceToggle}
|
|
61
|
+
/>
|
|
62
|
+
)}
|
|
63
|
+
{showInvoiceFields && (
|
|
64
|
+
<FieldList fields={invoiceOrderFields} />
|
|
65
|
+
)}
|
|
66
|
+
</FieldGroup>
|
|
67
|
+
</FieldSet>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
export default ContactDetailsSection;
|