@infosoftas/s4-orders-js-sdk 0.1.21-3 → 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,70 +1,70 @@
|
|
|
1
|
-
import { type FC, type ReactNode, useId } from 'react';
|
|
2
|
-
import { Controller, useFormContext } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { Checkbox } from '../ui/checkbox';
|
|
5
|
-
import { Field, FieldContent, FieldError, FieldLabel } from '../ui/field';
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
name: string;
|
|
9
|
-
required: boolean;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
label?: string | ReactNode;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const TermsCheckbox: FC<Props> = ({
|
|
15
|
-
name,
|
|
16
|
-
required = true,
|
|
17
|
-
disabled = false,
|
|
18
|
-
label = 'I accept the terms and conditions',
|
|
19
|
-
}) => {
|
|
20
|
-
const { control } = useFormContext();
|
|
21
|
-
const id = useId();
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<Controller
|
|
25
|
-
name={name}
|
|
26
|
-
control={control}
|
|
27
|
-
defaultValue={false}
|
|
28
|
-
render={({ field, fieldState }) => (
|
|
29
|
-
<Field
|
|
30
|
-
orientation="horizontal"
|
|
31
|
-
data-invalid={fieldState.invalid}
|
|
32
|
-
data-disabled={disabled}
|
|
33
|
-
data-testid={`sdk-${name}-field-id`}
|
|
34
|
-
>
|
|
35
|
-
<Checkbox
|
|
36
|
-
id={id}
|
|
37
|
-
name={field.name}
|
|
38
|
-
checked={!!field.value}
|
|
39
|
-
onCheckedChange={(checked) => field.onChange(checked)}
|
|
40
|
-
onBlur={field.onBlur}
|
|
41
|
-
inputRef={field.ref}
|
|
42
|
-
disabled={disabled}
|
|
43
|
-
aria-invalid={fieldState.invalid}
|
|
44
|
-
aria-required={required}
|
|
45
|
-
required={required}
|
|
46
|
-
/>
|
|
47
|
-
<FieldContent>
|
|
48
|
-
<FieldLabel htmlFor={id}>
|
|
49
|
-
<span>
|
|
50
|
-
{label}
|
|
51
|
-
{required && (
|
|
52
|
-
<span
|
|
53
|
-
aria-hidden="true"
|
|
54
|
-
className="text-destructive"
|
|
55
|
-
>
|
|
56
|
-
{' '}
|
|
57
|
-
*
|
|
58
|
-
</span>
|
|
59
|
-
)}
|
|
60
|
-
</span>
|
|
61
|
-
</FieldLabel>
|
|
62
|
-
<FieldError errors={[fieldState.error]} />
|
|
63
|
-
</FieldContent>
|
|
64
|
-
</Field>
|
|
65
|
-
)}
|
|
66
|
-
/>
|
|
67
|
-
);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export default TermsCheckbox;
|
|
1
|
+
import { type FC, type ReactNode, useId } from 'react';
|
|
2
|
+
import { Controller, useFormContext } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Checkbox } from '../ui/checkbox';
|
|
5
|
+
import { Field, FieldContent, FieldError, FieldLabel } from '../ui/field';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
label?: string | ReactNode;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const TermsCheckbox: FC<Props> = ({
|
|
15
|
+
name,
|
|
16
|
+
required = true,
|
|
17
|
+
disabled = false,
|
|
18
|
+
label = 'I accept the terms and conditions',
|
|
19
|
+
}) => {
|
|
20
|
+
const { control } = useFormContext();
|
|
21
|
+
const id = useId();
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Controller
|
|
25
|
+
name={name}
|
|
26
|
+
control={control}
|
|
27
|
+
defaultValue={false}
|
|
28
|
+
render={({ field, fieldState }) => (
|
|
29
|
+
<Field
|
|
30
|
+
orientation="horizontal"
|
|
31
|
+
data-invalid={fieldState.invalid}
|
|
32
|
+
data-disabled={disabled}
|
|
33
|
+
data-testid={`sdk-${name}-field-id`}
|
|
34
|
+
>
|
|
35
|
+
<Checkbox
|
|
36
|
+
id={id}
|
|
37
|
+
name={field.name}
|
|
38
|
+
checked={!!field.value}
|
|
39
|
+
onCheckedChange={(checked) => field.onChange(checked)}
|
|
40
|
+
onBlur={field.onBlur}
|
|
41
|
+
inputRef={field.ref}
|
|
42
|
+
disabled={disabled}
|
|
43
|
+
aria-invalid={fieldState.invalid}
|
|
44
|
+
aria-required={required}
|
|
45
|
+
required={required}
|
|
46
|
+
/>
|
|
47
|
+
<FieldContent>
|
|
48
|
+
<FieldLabel htmlFor={id}>
|
|
49
|
+
<span>
|
|
50
|
+
{label}
|
|
51
|
+
{required && (
|
|
52
|
+
<span
|
|
53
|
+
aria-hidden="true"
|
|
54
|
+
className="text-destructive"
|
|
55
|
+
>
|
|
56
|
+
{' '}
|
|
57
|
+
*
|
|
58
|
+
</span>
|
|
59
|
+
)}
|
|
60
|
+
</span>
|
|
61
|
+
</FieldLabel>
|
|
62
|
+
<FieldError errors={[fieldState.error]} />
|
|
63
|
+
</FieldContent>
|
|
64
|
+
</Field>
|
|
65
|
+
)}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default TermsCheckbox;
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { type FC, useId } from 'react';
|
|
2
|
-
import { Controller, useFormContext } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { Field, FieldLabel } from '../ui/field';
|
|
5
|
-
import { Switch } from '../ui/switch';
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
name: string;
|
|
9
|
-
readOnly?: boolean;
|
|
10
|
-
label?: string;
|
|
11
|
-
toggleCallback?: (value: boolean) => void;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const ToggleField: FC<Props> = ({
|
|
15
|
-
name,
|
|
16
|
-
readOnly = false,
|
|
17
|
-
label = '',
|
|
18
|
-
toggleCallback,
|
|
19
|
-
}) => {
|
|
20
|
-
const { control } = useFormContext();
|
|
21
|
-
const id = useId();
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<Controller
|
|
25
|
-
name={name}
|
|
26
|
-
control={control}
|
|
27
|
-
defaultValue={false}
|
|
28
|
-
render={({ field }) => (
|
|
29
|
-
<Field
|
|
30
|
-
orientation="horizontal"
|
|
31
|
-
data-testid={`sdk-${name}-field-id`}
|
|
32
|
-
>
|
|
33
|
-
<FieldLabel htmlFor={id}>{label}</FieldLabel>
|
|
34
|
-
<Switch
|
|
35
|
-
id={id}
|
|
36
|
-
name={field.name}
|
|
37
|
-
checked={!!field.value}
|
|
38
|
-
onCheckedChange={(checked) => {
|
|
39
|
-
field.onChange(checked);
|
|
40
|
-
toggleCallback?.(checked);
|
|
41
|
-
}}
|
|
42
|
-
onBlur={field.onBlur}
|
|
43
|
-
inputRef={field.ref}
|
|
44
|
-
readOnly={readOnly}
|
|
45
|
-
/>
|
|
46
|
-
</Field>
|
|
47
|
-
)}
|
|
48
|
-
/>
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export default ToggleField;
|
|
1
|
+
import { type FC, useId } from 'react';
|
|
2
|
+
import { Controller, useFormContext } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Field, FieldLabel } from '../ui/field';
|
|
5
|
+
import { Switch } from '../ui/switch';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
name: string;
|
|
9
|
+
readOnly?: boolean;
|
|
10
|
+
label?: string;
|
|
11
|
+
toggleCallback?: (value: boolean) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const ToggleField: FC<Props> = ({
|
|
15
|
+
name,
|
|
16
|
+
readOnly = false,
|
|
17
|
+
label = '',
|
|
18
|
+
toggleCallback,
|
|
19
|
+
}) => {
|
|
20
|
+
const { control } = useFormContext();
|
|
21
|
+
const id = useId();
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Controller
|
|
25
|
+
name={name}
|
|
26
|
+
control={control}
|
|
27
|
+
defaultValue={false}
|
|
28
|
+
render={({ field }) => (
|
|
29
|
+
<Field
|
|
30
|
+
orientation="horizontal"
|
|
31
|
+
data-testid={`sdk-${name}-field-id`}
|
|
32
|
+
>
|
|
33
|
+
<FieldLabel htmlFor={id}>{label}</FieldLabel>
|
|
34
|
+
<Switch
|
|
35
|
+
id={id}
|
|
36
|
+
name={field.name}
|
|
37
|
+
checked={!!field.value}
|
|
38
|
+
onCheckedChange={(checked) => {
|
|
39
|
+
field.onChange(checked);
|
|
40
|
+
toggleCallback?.(checked);
|
|
41
|
+
}}
|
|
42
|
+
onBlur={field.onBlur}
|
|
43
|
+
inputRef={field.ref}
|
|
44
|
+
readOnly={readOnly}
|
|
45
|
+
/>
|
|
46
|
+
</Field>
|
|
47
|
+
)}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default ToggleField;
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { z, type ZodTypeAny } from 'zod';
|
|
2
|
-
|
|
3
|
-
import EmailField from './EmailField';
|
|
4
|
-
import PhoneField from './PhoneField';
|
|
5
|
-
import NameField from './NameField';
|
|
6
|
-
import AddressField from './AddressField';
|
|
7
|
-
import TermsCheckbox from './TermsCheckbox';
|
|
8
|
-
import formFieldsMapper from './FormFieldsMapper';
|
|
9
|
-
|
|
10
|
-
export const EMAIL_PATTERN =
|
|
11
|
-
/^[A-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[A-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Z0-9!#$%&'*+/=?^_`{|}~-]{2,20})+$/i;
|
|
12
|
-
export const PHONE_PATTERN = /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\./0-9]{6,14}$/;
|
|
13
|
-
const NON_BLANK_PATTERN = /\S/;
|
|
14
|
-
|
|
15
|
-
export type FieldValidationMessages = {
|
|
16
|
-
errorReqMsg?: string;
|
|
17
|
-
errorInvalidEmailMsg?: string;
|
|
18
|
-
errorInvalidPhoneMsg?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const matchesWhenFilled = (pattern: RegExp) => (value: string) =>
|
|
22
|
-
value === '' || pattern.test(value);
|
|
23
|
-
|
|
24
|
-
export const buildFieldSchema = (
|
|
25
|
-
fieldName: string,
|
|
26
|
-
required: boolean,
|
|
27
|
-
messages: FieldValidationMessages = {}
|
|
28
|
-
): ZodTypeAny => {
|
|
29
|
-
const reqMsg = messages.errorReqMsg || 'This field is required!';
|
|
30
|
-
const Component = formFieldsMapper[fieldName];
|
|
31
|
-
|
|
32
|
-
if (Component === EmailField) {
|
|
33
|
-
const emailMsg =
|
|
34
|
-
messages.errorInvalidEmailMsg || 'Invalid email address!';
|
|
35
|
-
const base = required ? z.string().min(1, reqMsg) : z.string();
|
|
36
|
-
return base.refine(matchesWhenFilled(EMAIL_PATTERN), emailMsg);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (Component === PhoneField) {
|
|
40
|
-
const phoneMsg =
|
|
41
|
-
messages.errorInvalidPhoneMsg || 'Invalid phone number!';
|
|
42
|
-
const base = required ? z.string().min(1, reqMsg) : z.string();
|
|
43
|
-
return base.refine(matchesWhenFilled(PHONE_PATTERN), phoneMsg);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (Component === AddressField) {
|
|
47
|
-
const trimmed = z
|
|
48
|
-
.string()
|
|
49
|
-
.transform((value) => (typeof value === 'string' ? value.trim() : value));
|
|
50
|
-
return required
|
|
51
|
-
? trimmed.refine((value) => value.length > 0, { message: reqMsg })
|
|
52
|
-
: trimmed;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (Component === NameField) {
|
|
56
|
-
return required
|
|
57
|
-
? z.string().min(1, reqMsg).regex(NON_BLANK_PATTERN, reqMsg)
|
|
58
|
-
: z.string();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (Component === TermsCheckbox) {
|
|
62
|
-
const schema = z.boolean();
|
|
63
|
-
return required
|
|
64
|
-
? schema.refine((value) => value === true, { message: reqMsg })
|
|
65
|
-
: schema;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return required
|
|
69
|
-
? z.string().min(1, reqMsg).regex(NON_BLANK_PATTERN, reqMsg)
|
|
70
|
-
: z.string();
|
|
71
|
-
};
|
|
1
|
+
import { z, type ZodTypeAny } from 'zod';
|
|
2
|
+
|
|
3
|
+
import EmailField from './EmailField';
|
|
4
|
+
import PhoneField from './PhoneField';
|
|
5
|
+
import NameField from './NameField';
|
|
6
|
+
import AddressField from './AddressField';
|
|
7
|
+
import TermsCheckbox from './TermsCheckbox';
|
|
8
|
+
import formFieldsMapper from './FormFieldsMapper';
|
|
9
|
+
|
|
10
|
+
export const EMAIL_PATTERN =
|
|
11
|
+
/^[A-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[A-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Z0-9!#$%&'*+/=?^_`{|}~-]{2,20})+$/i;
|
|
12
|
+
export const PHONE_PATTERN = /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\./0-9]{6,14}$/;
|
|
13
|
+
const NON_BLANK_PATTERN = /\S/;
|
|
14
|
+
|
|
15
|
+
export type FieldValidationMessages = {
|
|
16
|
+
errorReqMsg?: string;
|
|
17
|
+
errorInvalidEmailMsg?: string;
|
|
18
|
+
errorInvalidPhoneMsg?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const matchesWhenFilled = (pattern: RegExp) => (value: string) =>
|
|
22
|
+
value === '' || pattern.test(value);
|
|
23
|
+
|
|
24
|
+
export const buildFieldSchema = (
|
|
25
|
+
fieldName: string,
|
|
26
|
+
required: boolean,
|
|
27
|
+
messages: FieldValidationMessages = {}
|
|
28
|
+
): ZodTypeAny => {
|
|
29
|
+
const reqMsg = messages.errorReqMsg || 'This field is required!';
|
|
30
|
+
const Component = formFieldsMapper[fieldName];
|
|
31
|
+
|
|
32
|
+
if (Component === EmailField) {
|
|
33
|
+
const emailMsg =
|
|
34
|
+
messages.errorInvalidEmailMsg || 'Invalid email address!';
|
|
35
|
+
const base = required ? z.string().min(1, reqMsg) : z.string();
|
|
36
|
+
return base.refine(matchesWhenFilled(EMAIL_PATTERN), emailMsg);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (Component === PhoneField) {
|
|
40
|
+
const phoneMsg =
|
|
41
|
+
messages.errorInvalidPhoneMsg || 'Invalid phone number!';
|
|
42
|
+
const base = required ? z.string().min(1, reqMsg) : z.string();
|
|
43
|
+
return base.refine(matchesWhenFilled(PHONE_PATTERN), phoneMsg);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (Component === AddressField) {
|
|
47
|
+
const trimmed = z
|
|
48
|
+
.string()
|
|
49
|
+
.transform((value) => (typeof value === 'string' ? value.trim() : value));
|
|
50
|
+
return required
|
|
51
|
+
? trimmed.refine((value) => value.length > 0, { message: reqMsg })
|
|
52
|
+
: trimmed;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Component === NameField) {
|
|
56
|
+
return required
|
|
57
|
+
? z.string().min(1, reqMsg).regex(NON_BLANK_PATTERN, reqMsg)
|
|
58
|
+
: z.string();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (Component === TermsCheckbox) {
|
|
62
|
+
const schema = z.boolean();
|
|
63
|
+
return required
|
|
64
|
+
? schema.refine((value) => value === true, { message: reqMsg })
|
|
65
|
+
: schema;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return required
|
|
69
|
+
? z.string().min(1, reqMsg).regex(NON_BLANK_PATTERN, reqMsg)
|
|
70
|
+
: z.string();
|
|
71
|
+
};
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { type FC, useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import useIframe from '../../hooks/useIframe';
|
|
4
|
-
|
|
5
|
-
type Props = {
|
|
6
|
-
iframeSrc: string | null;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const MainIframe: FC<Props> = ({ iframeSrc }) => {
|
|
10
|
-
const [loading, setLoading] = useState(false);
|
|
11
|
-
|
|
12
|
-
const { frameRef, messageReceiver } = useIframe();
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (frameRef && iframeSrc) {
|
|
16
|
-
setLoading(true);
|
|
17
|
-
frameRef?.current &&
|
|
18
|
-
(frameRef?.current as HTMLIFrameElement).addEventListener(
|
|
19
|
-
'load',
|
|
20
|
-
() => {
|
|
21
|
-
setLoading(false);
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
messageReceiver();
|
|
25
|
-
}
|
|
26
|
-
}, [frameRef, iframeSrc]);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<div className="sdk-iframe-wrapper" data-testid="sdk-iframe-id">
|
|
30
|
-
{loading && <div>... Loading</div>}
|
|
31
|
-
{iframeSrc && (
|
|
32
|
-
<iframe
|
|
33
|
-
ref={frameRef}
|
|
34
|
-
src={iframeSrc}
|
|
35
|
-
style={{ minHeight: '830px', width: '100%' }}
|
|
36
|
-
></iframe>
|
|
37
|
-
)}
|
|
38
|
-
</div>
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default MainIframe;
|
|
1
|
+
import { type FC, useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import useIframe from '../../hooks/useIframe';
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
iframeSrc: string | null;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const MainIframe: FC<Props> = ({ iframeSrc }) => {
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
|
|
12
|
+
const { frameRef, messageReceiver } = useIframe();
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (frameRef && iframeSrc) {
|
|
16
|
+
setLoading(true);
|
|
17
|
+
frameRef?.current &&
|
|
18
|
+
(frameRef?.current as HTMLIFrameElement).addEventListener(
|
|
19
|
+
'load',
|
|
20
|
+
() => {
|
|
21
|
+
setLoading(false);
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
messageReceiver();
|
|
25
|
+
}
|
|
26
|
+
}, [frameRef, iframeSrc]);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className="sdk-iframe-wrapper" data-testid="sdk-iframe-id">
|
|
30
|
+
{loading && <div>... Loading</div>}
|
|
31
|
+
{iframeSrc && (
|
|
32
|
+
<iframe
|
|
33
|
+
ref={frameRef}
|
|
34
|
+
src={iframeSrc}
|
|
35
|
+
style={{ minHeight: '830px', width: '100%' }}
|
|
36
|
+
></iframe>
|
|
37
|
+
)}
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default MainIframe;
|