@infosoftas/s4-orders-js-sdk 0.2.0 → 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.
- package/.editorconfig +8 -8
- package/.release-it.json +10 -10
- package/README.md +13 -6
- package/build/postcss-scope-tailwind.cjs +0 -0
- package/components.json +0 -0
- package/package.json +1 -1
- package/src/App.completion.test.tsx +46 -107
- package/src/App.css +0 -14
- package/src/App.paymentReturn.test.tsx +341 -0
- package/src/App.tsx +20 -51
- package/src/ErrorBoundary.tsx +41 -41
- package/src/api/InvoiceApi.ts +23 -23
- 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 +0 -3
- 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/OIOForm/OIOForm.tsx +0 -3
- package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -102
- package/src/components/OrderForm/ContactDetailsSection.tsx +71 -71
- package/src/components/OrderForm/OrderForm.tsx +0 -3
- 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/components/ui/alert-dialog.tsx +0 -0
- package/src/components/ui/alert.tsx +0 -0
- package/src/components/ui/button.tsx +0 -0
- package/src/components/ui/card.tsx +0 -0
- package/src/components/ui/checkbox.tsx +0 -0
- package/src/components/ui/field.tsx +0 -0
- package/src/components/ui/input.tsx +0 -0
- package/src/components/ui/label.tsx +0 -0
- package/src/components/ui/radio-group.tsx +0 -0
- package/src/components/ui/separator.tsx +0 -0
- package/src/components/ui/skeleton.tsx +0 -0
- package/src/components/ui/spinner.tsx +0 -0
- package/src/components/ui/switch.tsx +0 -0
- package/src/components/ui/textarea.tsx +0 -0
- package/src/constants/index.ts +13 -13
- package/src/custom.d.ts +0 -0
- package/src/enums/api.ts +5 -5
- package/src/enums/general.ts +4 -2
- package/src/hooks/useOrderForm.tsx +0 -3
- package/src/hooks/usePaymentReturn.tsx +139 -0
- 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 +0 -1
- package/src/utils/helper.ts +78 -78
- package/src/utils/order.helper.test.ts +81 -0
- package/src/utils/order.helper.ts +38 -25
- package/tsconfig.json +1 -0
- package/src/components/MainIframe/MainIframe.tsx +0 -42
- package/src/hooks/useIframe.tsx +0 -59
- package/src/hooks/useMessageEvent.tsx +0 -194
|
@@ -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;
|
|
@@ -55,7 +55,6 @@ type Props = {
|
|
|
55
55
|
identityProviderId?: string;
|
|
56
56
|
organizationId: string;
|
|
57
57
|
redirectUrl?: string;
|
|
58
|
-
showIframe?: boolean;
|
|
59
58
|
language: string;
|
|
60
59
|
merchantAgreementUrl: string;
|
|
61
60
|
paymentMethodsOptions?: PaymentMethodSettingsType;
|
|
@@ -119,7 +118,6 @@ const OrderForm: FC<Props> = ({
|
|
|
119
118
|
identityProviderId,
|
|
120
119
|
organizationId,
|
|
121
120
|
redirectUrl,
|
|
122
|
-
showIframe,
|
|
123
121
|
paymentMethodsOptions,
|
|
124
122
|
defaultValues,
|
|
125
123
|
language,
|
|
@@ -239,7 +237,6 @@ const OrderForm: FC<Props> = ({
|
|
|
239
237
|
identityProviderId,
|
|
240
238
|
orderFields: derived.orderFields,
|
|
241
239
|
redirectUrl,
|
|
242
|
-
showIframe,
|
|
243
240
|
language,
|
|
244
241
|
merchantAgreementUrl,
|
|
245
242
|
paymentMethodsOptions,
|
|
@@ -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;
|