@tap-payments/os-micro-frontend-shared 0.1.260 → 0.1.261-test.2
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/build/components/Chip/style.d.ts +0 -1
- package/build/components/CountBadge/style.d.ts +0 -1
- package/build/components/CountryFilter/CountryFilter.d.ts +13 -0
- package/build/components/CountryFilter/CountryFilter.js +71 -0
- package/build/components/CountryFilter/index.d.ts +2 -0
- package/build/components/CountryFilter/index.js +2 -0
- package/build/components/CountryFilter/style.d.ts +6 -0
- package/build/components/CountryFilter/style.js +7 -0
- package/build/components/Customer/CustomerDropdown/CustomerDropdown.d.ts +8 -0
- package/build/components/Customer/CustomerDropdown/CustomerDropdown.js +39 -0
- package/build/components/Customer/CustomerDropdown/index.d.ts +1 -0
- package/build/components/Customer/CustomerDropdown/index.js +1 -0
- package/build/components/Customer/CustomerDropdown/style.d.ts +10 -0
- package/build/components/Customer/CustomerDropdown/style.js +30 -0
- package/build/components/Customer/CustomerForms/EmailForm.d.ts +12 -0
- package/build/components/Customer/CustomerForms/EmailForm.js +76 -0
- package/build/components/Customer/CustomerForms/FullInfo.d.ts +13 -0
- package/build/components/Customer/CustomerForms/FullInfo.js +72 -0
- package/build/components/Customer/CustomerForms/FullInfoForm.d.ts +12 -0
- package/build/components/Customer/CustomerForms/FullInfoForm.js +74 -0
- package/build/components/Customer/CustomerForms/PhoneNumberForm.d.ts +12 -0
- package/build/components/Customer/CustomerForms/PhoneNumberForm.js +71 -0
- package/build/components/Customer/CustomerForms/index.d.ts +9 -0
- package/build/components/Customer/CustomerForms/index.js +9 -0
- package/build/components/Customer/CustomerForms/style.d.ts +25 -0
- package/build/components/Customer/CustomerForms/style.js +71 -0
- package/build/components/Customer/CustomerForms/validation.d.ts +30 -0
- package/build/components/Customer/CustomerForms/validation.js +42 -0
- package/build/components/Customer/index.d.ts +2 -0
- package/build/components/Customer/index.js +2 -0
- package/build/components/Dialog/style.d.ts +0 -1
- package/build/components/Error/Error.d.ts +1 -1
- package/build/components/FlippingCard/style.d.ts +0 -1
- package/build/components/ImageWrapper/ImageWrapper.d.ts +0 -1
- package/build/components/Inputs/CountriesDropDown/CountriesDropdown.d.ts +3 -3
- package/build/components/Inputs/CountriesDropDown/CountriesDropdown.js +3 -3
- package/build/components/JSONViewer/style.d.ts +0 -1
- package/build/components/LeftPeekRightExpandingChip/style.d.ts +0 -1
- package/build/components/PhoneFilter/PhoneFilter.d.ts +9 -0
- package/build/components/PhoneFilter/PhoneFilter.js +13 -0
- package/build/components/PhoneFilter/index.d.ts +2 -0
- package/build/components/PhoneFilter/index.js +2 -0
- package/build/components/RightLeftExpandingCenterChip/style.d.ts +0 -1
- package/build/components/SearchButton/styles.d.ts +0 -1
- package/build/components/StatusIcons/AuthIcons/style.d.ts +0 -1
- package/build/components/StatusIcons/AuthorizationAutoIcons/style.d.ts +0 -1
- package/build/components/StatusIcons/ChargeStatusIcon/style.d.ts +0 -1
- package/build/components/StatusIcons/SourceIcons/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ActionCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ApplicationStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/AuthenticationCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/AuthenticationStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/AuthenticationTypeCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/BalanceCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ChannelsCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/CheckoutStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/DestinationStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/DueDateCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/IDButton/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/IntentsStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/InvoiceStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/PayoutStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ProductsCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/ReferenceCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/RefundChargeCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/RefundStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/SalesChannelCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/SegmentsCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/SourceCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/StatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/TokenStatusCell/style.d.ts +0 -1
- package/build/components/TableCells/CustomCells/style.d.ts +0 -1
- package/build/components/VirtualTables/components/style.d.ts +0 -1
- package/build/components/index.d.ts +3 -0
- package/build/components/index.js +3 -0
- package/build/constants/apps.d.ts +11 -0
- package/build/constants/apps.js +4 -0
- package/build/types/account.d.ts +2 -1
- package/build/types/account.js +1 -0
- package/package.json +20 -19
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
/// <reference types="react" />
|
|
3
2
|
import { GetSourceAnimationFunction } from './type';
|
|
4
3
|
export declare const ChipStyled: import("@emotion/styled").StyledComponent<import("react").RefAttributes<unknown> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
|
|
5
4
|
variant?: import("./type").ChipVariant | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SxProps } from '@mui/material';
|
|
2
|
+
interface CountryFilterProps {
|
|
3
|
+
onCountriesChange: (countries: string[]) => void;
|
|
4
|
+
sx?: SxProps;
|
|
5
|
+
selectedCountries?: string[];
|
|
6
|
+
countriesOptions: {
|
|
7
|
+
label: string;
|
|
8
|
+
value: string;
|
|
9
|
+
icon: string;
|
|
10
|
+
}[];
|
|
11
|
+
}
|
|
12
|
+
export default function CountryFilter({ onCountriesChange, sx, selectedCountries, countriesOptions }: CountryFilterProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useRef, useState } from 'react';
|
|
3
|
+
import Box from '@mui/material/Box';
|
|
4
|
+
import { ClickAwayListener } from '@mui/material';
|
|
5
|
+
import { Menu, MenuItem } from '../index.js';
|
|
6
|
+
import { rightArrow } from '../../constants/index.js';
|
|
7
|
+
export default function CountryFilter({ onCountriesChange, sx, selectedCountries, countriesOptions }) {
|
|
8
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
9
|
+
const containerRef = useRef(null);
|
|
10
|
+
const open = Boolean(anchorEl);
|
|
11
|
+
const onOpen = () => {
|
|
12
|
+
if (!open) {
|
|
13
|
+
setAnchorEl(containerRef.current);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
onClose();
|
|
17
|
+
};
|
|
18
|
+
const onClose = () => {
|
|
19
|
+
setAnchorEl(null);
|
|
20
|
+
};
|
|
21
|
+
const checkIsSelected = (countryCode) => { var _a; return (_a = selectedCountries === null || selectedCountries === void 0 ? void 0 : selectedCountries.includes(countryCode)) !== null && _a !== void 0 ? _a : false; };
|
|
22
|
+
const onClickCountry = (countryCodes) => {
|
|
23
|
+
onCountriesChange(countryCodes);
|
|
24
|
+
};
|
|
25
|
+
const handleCheckboxChange = (value) => {
|
|
26
|
+
const newCountries = (selectedCountries === null || selectedCountries === void 0 ? void 0 : selectedCountries.includes(value)) ? selectedCountries === null || selectedCountries === void 0 ? void 0 : selectedCountries.filter((c) => c !== value) : [...(selectedCountries !== null && selectedCountries !== void 0 ? selectedCountries : []), value];
|
|
27
|
+
onClickCountry(newCountries);
|
|
28
|
+
onCountriesChange(newCountries);
|
|
29
|
+
};
|
|
30
|
+
const isAllCountriesSelected = useMemo(() => {
|
|
31
|
+
return (selectedCountries === null || selectedCountries === void 0 ? void 0 : selectedCountries.length) === countriesOptions.length;
|
|
32
|
+
}, [selectedCountries, countriesOptions]);
|
|
33
|
+
return (_jsx(ClickAwayListener, Object.assign({ onClickAway: onClose }, { children: _jsxs(Box, Object.assign({ ref: containerRef, sx: sx }, { children: [_jsx(Box, { children: _jsxs(MenuItem, Object.assign({ onMouseEnter: (e) => {
|
|
34
|
+
e.stopPropagation();
|
|
35
|
+
onOpen();
|
|
36
|
+
}, sx: {
|
|
37
|
+
display: 'flex',
|
|
38
|
+
alignItems: 'center',
|
|
39
|
+
paddingInline: '16px',
|
|
40
|
+
gap: '4px',
|
|
41
|
+
borderBlock: '1px solid #F2F2F2',
|
|
42
|
+
'&:hover': {
|
|
43
|
+
backgroundColor: '#fff',
|
|
44
|
+
boxShadow: '0px 0px 16px 0px #00000021',
|
|
45
|
+
},
|
|
46
|
+
}, hideCheckbox: true }, { children: [_jsx("span", { children: "Country" }), _jsx(Box, { component: "img", src: rightArrow, width: 16, height: 12, sx: { marginLeft: 'auto' } })] })) }), _jsxs(Menu, Object.assign({ open: open, anchorEl: anchorEl, sx: { marginTop: '8px', marginBottom: '8px', maxHeight: '190px', overflow: 'auto' }, placement: "right-start", popperSx: {
|
|
47
|
+
zIndex: 99999,
|
|
48
|
+
} }, { children: [_jsx(MenuItem, Object.assign({ sx: {
|
|
49
|
+
color: (theme) => theme.palette.info.dark,
|
|
50
|
+
backgroundColor: '#F4F4F4',
|
|
51
|
+
fontWeight: 600,
|
|
52
|
+
paddingInline: '16px',
|
|
53
|
+
}, onClick: (e) => {
|
|
54
|
+
e.stopPropagation();
|
|
55
|
+
if (isAllCountriesSelected) {
|
|
56
|
+
onClickCountry([]);
|
|
57
|
+
onCountriesChange([]);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
onClickCountry(countriesOptions.map(({ value }) => value));
|
|
61
|
+
onCountriesChange(countriesOptions.map(({ value }) => value));
|
|
62
|
+
}
|
|
63
|
+
}, isSelected: isAllCountriesSelected }, { children: isAllCountriesSelected ? 'Unselect All' : 'Select All' })), countriesOptions.map(({ value, label, icon }) => (_jsxs(MenuItem, Object.assign({ sx: {
|
|
64
|
+
gap: '0px',
|
|
65
|
+
paddingInline: '16px',
|
|
66
|
+
'&:hover': {
|
|
67
|
+
backgroundColor: '#fff',
|
|
68
|
+
boxShadow: '0px 0px 16px 0px #00000021',
|
|
69
|
+
},
|
|
70
|
+
}, isSelected: checkIsSelected(value), onClick: () => handleCheckboxChange(value) }, { children: [_jsx(Box, { component: "img", src: icon, width: 16, height: 12, sx: { marginRight: '4px', borderRadius: '2px' } }), label] }), value)))] }))] })) })));
|
|
71
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const FilterButton: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
3
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
4
|
+
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
|
|
5
|
+
isActive?: boolean | undefined;
|
|
6
|
+
}, {}, {}>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Box, styled } from '@mui/material';
|
|
2
|
+
export const FilterButton = styled(Box, { shouldForwardProp: (props) => props !== 'isActive' })(({ theme, isActive }) => (Object.assign({ borderRadius: '4px', border: `1px solid ${theme.palette.divider}`, height: 32, width: 30, display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', backgroundColor: theme.palette.common.white, ':hover': {
|
|
3
|
+
opacity: 0.7,
|
|
4
|
+
} }, (isActive && {
|
|
5
|
+
boxShadow: `0px 0px 4px 0px ${theme.palette.info.dark}80`,
|
|
6
|
+
border: `1px solid ${theme.palette.info.dark}`,
|
|
7
|
+
}))));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FullInfoProps } from '../CustomerForms/FullInfo';
|
|
3
|
+
interface CustomerDropdownProps extends FullInfoProps {
|
|
4
|
+
isDisabled?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare function CustomerDropdown({ ...props }: Readonly<CustomerDropdownProps>): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
declare const _default: import("react").MemoExoticComponent<typeof CustomerDropdown>;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { memo, useMemo, useState } from 'react';
|
|
14
|
+
import Popper from '@mui/material/Popper';
|
|
15
|
+
import { useTranslation } from 'react-i18next';
|
|
16
|
+
import { getRandomGradientColor } from '../../../utils/index.js';
|
|
17
|
+
import { CustomBackdrop } from '../../index.js';
|
|
18
|
+
import { customerIcon2 } from '../../../constants/index.js';
|
|
19
|
+
import { Wrapper, AvatarStyled, Button } from './style';
|
|
20
|
+
import FullInfo from '../CustomerForms/FullInfo';
|
|
21
|
+
function CustomerDropdown(_a) {
|
|
22
|
+
var _b, _c;
|
|
23
|
+
var props = __rest(_a, []);
|
|
24
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
25
|
+
const { firstName, lastName } = props.customer;
|
|
26
|
+
const { t } = useTranslation();
|
|
27
|
+
const open = Boolean(anchorEl);
|
|
28
|
+
const openDropdown = (event) => {
|
|
29
|
+
if (!open)
|
|
30
|
+
setAnchorEl(event.currentTarget);
|
|
31
|
+
};
|
|
32
|
+
const closeDropdown = () => {
|
|
33
|
+
if (open)
|
|
34
|
+
setAnchorEl(null);
|
|
35
|
+
};
|
|
36
|
+
const AvatarColor = useMemo(() => getRandomGradientColor(), []);
|
|
37
|
+
return (_jsxs(Wrapper, Object.assign({ sx: Object.assign({}, (props.isDisabled && { pointerEvents: 'none', opacity: 0.7 })) }, { children: [_jsxs(Button, Object.assign({ onClick: openDropdown }, { children: [(!firstName || !lastName) && (_jsxs(_Fragment, { children: [_jsx("img", { src: customerIcon2, alt: "c" }), _jsx("span", { children: t('customer') })] })), firstName && lastName && (_jsxs(_Fragment, { children: [_jsx(AvatarStyled, Object.assign({ src: "#", alt: "a", sx: { background: AvatarColor } }, { children: `${(_b = firstName[0]) === null || _b === void 0 ? void 0 : _b.toUpperCase()}${((_c = lastName[0]) === null || _c === void 0 ? void 0 : _c.toUpperCase()) || ''}` })), `${firstName} ${lastName}`] }))] })), open && _jsx(CustomBackdrop, { onClick: closeDropdown }), _jsx(Popper, Object.assign({ open: open, anchorEl: anchorEl, placement: "bottom-start" }, { children: _jsx(FullInfo, Object.assign({}, props)) }))] })));
|
|
38
|
+
}
|
|
39
|
+
export default memo(CustomerDropdown);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './CustomerDropdown';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './CustomerDropdown';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Wrapper: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
3
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
4
|
+
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
5
|
+
export declare const Button: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
6
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
7
|
+
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
8
|
+
export declare const AvatarStyled: import("@emotion/styled").StyledComponent<import("@mui/material/Avatar").AvatarOwnProps & import("@mui/material/Avatar").AvatarSlotsAndSlotProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
9
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
10
|
+
}, "classes" | "className" | "style" | "children" | "sx" | "variant" | "slotProps" | "slots" | "sizes" | "src" | "alt" | "srcSet" | "imgProps"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Avatar from '@mui/material/Avatar';
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
export const Wrapper = styled(Box)(() => ({
|
|
5
|
+
position: 'relative',
|
|
6
|
+
flexGrow: 0
|
|
7
|
+
}));
|
|
8
|
+
export const Button = styled(Box)(({ theme }) => ({
|
|
9
|
+
fontSize: '11px',
|
|
10
|
+
color: theme.palette.text.primary,
|
|
11
|
+
display: 'flex',
|
|
12
|
+
padding: theme.spacing(1),
|
|
13
|
+
gap: theme.spacing(1),
|
|
14
|
+
border: `1px solid ${theme.palette.divider}`,
|
|
15
|
+
borderRadius: '4px',
|
|
16
|
+
backgroundColor: theme.palette.common.white,
|
|
17
|
+
alignItems: 'center',
|
|
18
|
+
height: 32,
|
|
19
|
+
textTransform: 'capitalize',
|
|
20
|
+
cursor: 'pointer'
|
|
21
|
+
}));
|
|
22
|
+
export const AvatarStyled = styled(Avatar)(({ theme }) => ({
|
|
23
|
+
width: 16,
|
|
24
|
+
height: 16,
|
|
25
|
+
cursor: 'pointer',
|
|
26
|
+
fontSize: '5.667px',
|
|
27
|
+
color: theme.palette.common.white,
|
|
28
|
+
fontWeight: 500,
|
|
29
|
+
border: `1px solid ${theme.palette.common.white}`
|
|
30
|
+
}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Item } from '../../../types/index.js';
|
|
3
|
+
import { FullInfoProps } from './FullInfo';
|
|
4
|
+
export interface EmailFormProps extends Pick<FullInfoProps, 'onCustomerChange' | 'isCustomerNotValid' | 'customer'> {
|
|
5
|
+
items: Item[];
|
|
6
|
+
isItemsNotValid: boolean;
|
|
7
|
+
submitButtonText: string;
|
|
8
|
+
onSubmit: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare function EmailForm({ submitButtonText, onSubmit, customer, isItemsNotValid, items, onCustomerChange }: Readonly<EmailFormProps>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
declare const _default: import("react").MemoExoticComponent<typeof EmailForm>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { memo, useEffect, useRef } from 'react';
|
|
14
|
+
import { yupResolver } from '@hookform/resolvers/yup';
|
|
15
|
+
import Box from '@mui/material/Box';
|
|
16
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
17
|
+
import { useTranslation } from 'react-i18next';
|
|
18
|
+
import { FormWrapper, InputStyled, SubmitButton, ErrorStyled } from './style';
|
|
19
|
+
import { validationEmailFromSchema } from './validation';
|
|
20
|
+
function EmailForm({ submitButtonText, onSubmit, customer, isItemsNotValid, items, onCustomerChange }) {
|
|
21
|
+
const firstNameRef = useRef();
|
|
22
|
+
const lastNameRef = useRef();
|
|
23
|
+
const emailRef = useRef();
|
|
24
|
+
const { t } = useTranslation();
|
|
25
|
+
const { control, formState: { isValid, errors }, watch, trigger, } = useForm({
|
|
26
|
+
mode: 'onChange',
|
|
27
|
+
resolver: yupResolver(validationEmailFromSchema),
|
|
28
|
+
defaultValues: {
|
|
29
|
+
firstName: customer.firstName,
|
|
30
|
+
email: customer.email,
|
|
31
|
+
lastName: customer.lastName,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
// revalidate default values
|
|
36
|
+
if (customer.firstName && customer.email && customer.lastName) {
|
|
37
|
+
trigger();
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
watch(({ firstName = '', lastName = '', email = '' }) => {
|
|
42
|
+
onCustomerChange(Object.assign(Object.assign({}, customer), { email,
|
|
43
|
+
firstName,
|
|
44
|
+
lastName }));
|
|
45
|
+
});
|
|
46
|
+
}, [watch, errors, customer]);
|
|
47
|
+
const onMouseLeave = (e) => {
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
};
|
|
50
|
+
return (_jsxs(FormWrapper, Object.assign({ onMouseLeave: onMouseLeave }, { children: [_jsx(Controller, { control: control, name: "email", render: (_a) => {
|
|
51
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
52
|
+
return (_jsxs(Box, Object.assign({ ref: emailRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { "data-testid": "EmailForm_email", placeholder: t('email'), inputProps: {
|
|
53
|
+
autoComplete: 'off',
|
|
54
|
+
form: {
|
|
55
|
+
autoComplete: 'off',
|
|
56
|
+
},
|
|
57
|
+
}, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
58
|
+
} }), _jsx(Controller, { control: control, name: "firstName", render: (_a) => {
|
|
59
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
60
|
+
return (_jsxs(Box, Object.assign({ ref: firstNameRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { "data-testid": "EmailForm_firstName", placeholder: t('firstName'), inputProps: {
|
|
61
|
+
autoComplete: 'off',
|
|
62
|
+
form: {
|
|
63
|
+
autoComplete: 'off',
|
|
64
|
+
},
|
|
65
|
+
}, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
66
|
+
} }), _jsx(Controller, { control: control, name: "lastName", render: (_a) => {
|
|
67
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
68
|
+
return (_jsxs(Box, Object.assign({ ref: lastNameRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { "data-testid": "EmailForm_lastName", placeholder: t('lastName'), inputProps: {
|
|
69
|
+
autoComplete: 'off',
|
|
70
|
+
form: {
|
|
71
|
+
autoComplete: 'off',
|
|
72
|
+
},
|
|
73
|
+
}, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
74
|
+
} }), _jsx(SubmitButton, Object.assign({ type: "button", "data-testid": "EmailForm_submit", onClick: onSubmit, disabled: !isValid || isItemsNotValid || !items.length }, { children: submitButtonText }))] })));
|
|
75
|
+
}
|
|
76
|
+
export default memo(EmailForm);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Country, CustomerInfo, SegmentCountry } from '../../../types/index.js';
|
|
2
|
+
export interface FullInfoProps {
|
|
3
|
+
customer: CustomerInfo;
|
|
4
|
+
country: Country;
|
|
5
|
+
defaultCountry: SegmentCountry;
|
|
6
|
+
countries: Country[];
|
|
7
|
+
isCountriesLoading: boolean;
|
|
8
|
+
onCountryChange: (country: Country) => void;
|
|
9
|
+
onCustomerChange: (customer: CustomerInfo) => void;
|
|
10
|
+
isCustomerNotValid?: (value: boolean, err?: string) => void;
|
|
11
|
+
}
|
|
12
|
+
declare function FullInfo({ customer, country, defaultCountry, countries, isCountriesLoading, onCustomerChange, onCountryChange, isCustomerNotValid, }: Readonly<FullInfoProps>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export default FullInfo;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useEffect, useRef, useCallback } from 'react';
|
|
14
|
+
import { yupResolver } from '@hookform/resolvers/yup';
|
|
15
|
+
import Box from '@mui/material/Box';
|
|
16
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
17
|
+
import { useTranslation } from 'react-i18next';
|
|
18
|
+
import { MobileWrapper, FormWrapper, InputStyled, InputNumberStyled, ErrorStyled } from './style';
|
|
19
|
+
import { validationFullInfoSchema } from './validation';
|
|
20
|
+
import CountriesDropdown from '../../Inputs/CountriesDropDown';
|
|
21
|
+
function FullInfo({ customer, country, defaultCountry, countries, isCountriesLoading, onCustomerChange, onCountryChange, isCustomerNotValid, }) {
|
|
22
|
+
const firstNameRef = useRef();
|
|
23
|
+
const lastNameRef = useRef();
|
|
24
|
+
const emailRef = useRef();
|
|
25
|
+
const phoneNumberRef = useRef();
|
|
26
|
+
const { t } = useTranslation();
|
|
27
|
+
const { control, watch, formState: { errors, isValid }, } = useForm({
|
|
28
|
+
mode: 'onChange',
|
|
29
|
+
resolver: yupResolver(validationFullInfoSchema(country.max_digits)),
|
|
30
|
+
defaultValues: {
|
|
31
|
+
firstName: customer.firstName,
|
|
32
|
+
email: customer.email,
|
|
33
|
+
lastName: customer.lastName,
|
|
34
|
+
phoneNumber: customer.phoneNumber,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
watch(({ firstName = '', lastName = '', email = '', phoneNumber = '' }) => {
|
|
39
|
+
onCustomerChange({
|
|
40
|
+
firstName,
|
|
41
|
+
lastName,
|
|
42
|
+
email,
|
|
43
|
+
phoneNumber,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}, [watch, errors, customer]);
|
|
47
|
+
const getFirstError = useCallback(() => { var _a, _b, _c, _d, _e, _f, _g; return (_f = (_d = (_b = (_a = errors.firstName) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : (_c = errors.lastName) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : (_e = errors.email) === null || _e === void 0 ? void 0 : _e.message) !== null && _f !== void 0 ? _f : (_g = errors.phoneNumber) === null || _g === void 0 ? void 0 : _g.message; }, [errors]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
isCustomerNotValid === null || isCustomerNotValid === void 0 ? void 0 : isCustomerNotValid(!isValid, getFirstError());
|
|
50
|
+
}, [isValid, getFirstError]);
|
|
51
|
+
const onMouseLeave = (e) => {
|
|
52
|
+
e.stopPropagation();
|
|
53
|
+
};
|
|
54
|
+
return (_jsxs(FormWrapper, Object.assign({ onMouseLeave: onMouseLeave }, { children: [_jsx(Controller, { control: control, name: "firstName", render: (_a) => {
|
|
55
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
56
|
+
return (_jsxs(Box, Object.assign({ ref: firstNameRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { placeholder: t('firstName'), inputProps: { autoComplete: 'off' }, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
57
|
+
} }, "fullInfoFirstName"), _jsx(Controller, { control: control, name: "lastName", render: (_a) => {
|
|
58
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
59
|
+
return (_jsxs(Box, Object.assign({ ref: lastNameRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { placeholder: t('lastName'), inputProps: { autoComplete: 'off' }, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
60
|
+
} }, "fullInfoLastName"), _jsx(Controller, { control: control, name: "email", render: (_a) => {
|
|
61
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
62
|
+
return (_jsxs(Box, Object.assign({ ref: emailRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { placeholder: t('email'), inputProps: { autoComplete: 'off' }, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
63
|
+
} }, "fullInfoEmail"), _jsx(Controller, { control: control, name: "phoneNumber", render: (_a) => {
|
|
64
|
+
var _b, _c;
|
|
65
|
+
var _d = _a.field, { ref } = _d, field = __rest(_d, ["ref"]), { fieldState: { error } } = _a;
|
|
66
|
+
return (_jsxs(Box, Object.assign({ ref: phoneNumberRef }, { children: [_jsxs(MobileWrapper, Object.assign({ sx: Object.assign({}, ((error === null || error === void 0 ? void 0 : error.message) && { borderBottom: 'none' })) }, { children: [_jsx(CountriesDropdown, { defaultCountry: (_c = (_b = country === null || country === void 0 ? void 0 : country.iso2) !== null && _b !== void 0 ? _b : defaultCountry === null || defaultCountry === void 0 ? void 0 : defaultCountry.code) !== null && _c !== void 0 ? _c : 'SA', value: country, onChangeCountry: onCountryChange, countries: countries, isLoading: isCountriesLoading }), _jsx(InputNumberStyled, Object.assign({}, field, { placeholder: t('mobile'), inputProps: { autoComplete: 'off' }, error: Boolean(error === null || error === void 0 ? void 0 : error.message), sx: {
|
|
67
|
+
border: 'none',
|
|
68
|
+
paddingInlineEnd: 0,
|
|
69
|
+
}, hideArrows: true }))] })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message, { numberLen: country.max_digits }) })] })));
|
|
70
|
+
} }, "fullInfoPhoneNumber")] })));
|
|
71
|
+
}
|
|
72
|
+
export default FullInfo;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Item } from '../../../types/index.js';
|
|
3
|
+
import { FullInfoProps } from './FullInfo';
|
|
4
|
+
export interface FullInfoFormProps extends FullInfoProps {
|
|
5
|
+
items: Item[];
|
|
6
|
+
isItemsNotValid: boolean;
|
|
7
|
+
submitButtonText: string;
|
|
8
|
+
onSubmit: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare function FullInfoForm({ submitButtonText, onSubmit, customer, country, items, isItemsNotValid, defaultCountry, countries, isCountriesLoading, onCustomerChange, onCountryChange, }: Readonly<FullInfoFormProps>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
declare const _default: import("react").MemoExoticComponent<typeof FullInfoForm>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { memo, useEffect, useRef } from 'react';
|
|
14
|
+
import { yupResolver } from '@hookform/resolvers/yup';
|
|
15
|
+
import Box from '@mui/material/Box';
|
|
16
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
17
|
+
import { useTranslation } from 'react-i18next';
|
|
18
|
+
import { InputNumberStyled, MobileWrapper } from '../../index.js';
|
|
19
|
+
import { FormWrapper, SubmitButton, InputStyled, ErrorStyled } from './style';
|
|
20
|
+
import { validationFullInfoSchema } from './validation';
|
|
21
|
+
import CountriesDropdown from '../../Inputs/CountriesDropDown';
|
|
22
|
+
function FullInfoForm({ submitButtonText, onSubmit, customer, country, items, isItemsNotValid, defaultCountry, countries, isCountriesLoading, onCustomerChange, onCountryChange, }) {
|
|
23
|
+
const firstNameRef = useRef();
|
|
24
|
+
const lastNameRef = useRef();
|
|
25
|
+
const emailRef = useRef();
|
|
26
|
+
const phoneNumberRef = useRef();
|
|
27
|
+
const { t } = useTranslation();
|
|
28
|
+
const { control, watch, trigger, formState: { isValid, errors }, } = useForm({
|
|
29
|
+
mode: 'onChange',
|
|
30
|
+
resolver: yupResolver(validationFullInfoSchema(country.max_digits)),
|
|
31
|
+
defaultValues: {
|
|
32
|
+
firstName: customer.firstName,
|
|
33
|
+
email: customer.email,
|
|
34
|
+
lastName: customer.lastName,
|
|
35
|
+
phoneNumber: customer.phoneNumber,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
watch(({ firstName = '', lastName = '', email = '', phoneNumber = '' }) => {
|
|
40
|
+
onCustomerChange({
|
|
41
|
+
email,
|
|
42
|
+
firstName,
|
|
43
|
+
lastName,
|
|
44
|
+
phoneNumber,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}, [watch, errors, customer]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
// revalidate default values
|
|
50
|
+
if (customer.firstName && customer.lastName && (customer.email || customer.phoneNumber)) {
|
|
51
|
+
trigger();
|
|
52
|
+
}
|
|
53
|
+
}, []);
|
|
54
|
+
return (_jsxs(FormWrapper, Object.assign({ onMouseLeave: (e) => {
|
|
55
|
+
e.stopPropagation();
|
|
56
|
+
} }, { children: [_jsx(Controller, { control: control, name: "firstName", render: (_a) => {
|
|
57
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
58
|
+
return (_jsxs(Box, Object.assign({ ref: firstNameRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { placeholder: t('firstName'), inputProps: { autoComplete: 'off' }, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
59
|
+
} }, "fullInfoFormFirstName"), _jsx(Controller, { control: control, name: "lastName", render: (_a) => {
|
|
60
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
61
|
+
return (_jsxs(Box, Object.assign({ ref: lastNameRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { placeholder: t('lastName'), inputProps: { autoComplete: 'off' }, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
62
|
+
} }, "fullInfoFormLastName"), _jsx(Controller, { control: control, name: "email", render: (_a) => {
|
|
63
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
64
|
+
return (_jsxs(Box, Object.assign({ ref: emailRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { placeholder: t('email'), inputProps: { autoComplete: 'off' }, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
65
|
+
} }, "fullInfoFormEmail"), _jsx(Controller, { control: control, name: "phoneNumber", render: (_a) => {
|
|
66
|
+
var _b, _c;
|
|
67
|
+
var _d = _a.field, { ref } = _d, field = __rest(_d, ["ref"]), { fieldState: { error } } = _a;
|
|
68
|
+
return (_jsxs(Box, Object.assign({ ref: phoneNumberRef }, { children: [_jsxs(MobileWrapper, Object.assign({ sx: Object.assign({}, ((error === null || error === void 0 ? void 0 : error.message) && { borderBottom: 'none' })) }, { children: [_jsx(CountriesDropdown, { defaultCountry: (_c = (_b = country === null || country === void 0 ? void 0 : country.iso2) !== null && _b !== void 0 ? _b : defaultCountry === null || defaultCountry === void 0 ? void 0 : defaultCountry.code) !== null && _c !== void 0 ? _c : 'SA', value: country, onChangeCountry: onCountryChange, countries: countries, isLoading: isCountriesLoading }), _jsx(InputNumberStyled, Object.assign({}, field, { placeholder: t('mobile'), inputProps: { autoComplete: 'off' }, error: Boolean(error === null || error === void 0 ? void 0 : error.message), sx: {
|
|
69
|
+
border: 'none',
|
|
70
|
+
paddingInlineEnd: 0,
|
|
71
|
+
}, hideArrows: true }))] })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message, { numberLen: country.max_digits }) })] })));
|
|
72
|
+
} }), _jsx(SubmitButton, Object.assign({ onClick: onSubmit, disabled: !isValid || isItemsNotValid || !items.length }, { children: submitButtonText }))] })));
|
|
73
|
+
}
|
|
74
|
+
export default memo(FullInfoForm);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Item } from '../../../types/index.js';
|
|
3
|
+
import { FullInfoProps } from './FullInfo';
|
|
4
|
+
export interface PhoneNumberFormProps extends Pick<FullInfoProps, 'customer' | 'country' | 'onCountryChange' | 'onCustomerChange' | 'defaultCountry' | 'countries' | 'isCountriesLoading'> {
|
|
5
|
+
isItemsNotValid: boolean;
|
|
6
|
+
items: Item[];
|
|
7
|
+
submitButtonText: string;
|
|
8
|
+
onSubmit: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare function PhoneNumberForm({ submitButtonText, onSubmit, customer, country, isItemsNotValid, items, defaultCountry, countries, isCountriesLoading, onCustomerChange, onCountryChange, }: Readonly<PhoneNumberFormProps>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
declare const _default: import("react").MemoExoticComponent<typeof PhoneNumberForm>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { memo, useEffect, useRef } from 'react';
|
|
14
|
+
import { yupResolver } from '@hookform/resolvers/yup';
|
|
15
|
+
import Box from '@mui/material/Box';
|
|
16
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
17
|
+
import { useTranslation } from 'react-i18next';
|
|
18
|
+
import { CountriesDropdown, InputNumberStyled, MobileWrapper } from '../../index.js';
|
|
19
|
+
import { FormWrapper, SubmitButton, InputStyled, ErrorStyled } from './style';
|
|
20
|
+
import { validationPhoneNumberSchema } from './validation';
|
|
21
|
+
function PhoneNumberForm({ submitButtonText, onSubmit, customer, country, isItemsNotValid, items, defaultCountry, countries, isCountriesLoading, onCustomerChange, onCountryChange, }) {
|
|
22
|
+
const firstNameRef = useRef();
|
|
23
|
+
const lastNameRef = useRef();
|
|
24
|
+
const phoneNumberRef = useRef();
|
|
25
|
+
const { t } = useTranslation();
|
|
26
|
+
const { control, formState: { isValid, errors }, watch, trigger, } = useForm({
|
|
27
|
+
mode: 'onChange',
|
|
28
|
+
resolver: yupResolver(validationPhoneNumberSchema(country.max_digits)),
|
|
29
|
+
defaultValues: {
|
|
30
|
+
firstName: customer.firstName,
|
|
31
|
+
phoneNumber: customer.phoneNumber,
|
|
32
|
+
lastName: customer.lastName,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
// revalidate default values
|
|
37
|
+
if (customer.firstName && customer.phoneNumber && customer.lastName) {
|
|
38
|
+
trigger();
|
|
39
|
+
}
|
|
40
|
+
}, []);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
watch(({ firstName = '', lastName = '', phoneNumber = '' }) => {
|
|
43
|
+
onCustomerChange(Object.assign(Object.assign({}, customer), { firstName,
|
|
44
|
+
lastName,
|
|
45
|
+
phoneNumber }));
|
|
46
|
+
});
|
|
47
|
+
}, [watch, errors, customer]);
|
|
48
|
+
const onMouseLeave = (e) => {
|
|
49
|
+
e.stopPropagation();
|
|
50
|
+
};
|
|
51
|
+
return (_jsxs(FormWrapper, Object.assign({ onMouseLeave: onMouseLeave }, { children: [_jsx(Controller, { control: control, name: "phoneNumber", render: (_a) => {
|
|
52
|
+
var _b, _c;
|
|
53
|
+
var _d = _a.field, { ref } = _d, field = __rest(_d, ["ref"]), { fieldState: { error } } = _a;
|
|
54
|
+
return (_jsxs(Box, Object.assign({ ref: phoneNumberRef }, { children: [_jsxs(MobileWrapper, Object.assign({ sx: Object.assign({}, ((error === null || error === void 0 ? void 0 : error.message) && { borderBottom: 'none' })) }, { children: [_jsx(CountriesDropdown, { defaultCountry: (_c = (_b = country === null || country === void 0 ? void 0 : country.iso2) !== null && _b !== void 0 ? _b : defaultCountry === null || defaultCountry === void 0 ? void 0 : defaultCountry.code) !== null && _c !== void 0 ? _c : 'SA', value: country, onChangeCountry: onCountryChange, countries: countries, isLoading: isCountriesLoading }), _jsx(InputNumberStyled, Object.assign({}, field, { placeholder: t('mobile'), error: Boolean(error === null || error === void 0 ? void 0 : error.message), sx: {
|
|
55
|
+
border: 'none',
|
|
56
|
+
paddingInlineEnd: 0,
|
|
57
|
+
}, inputProps: {
|
|
58
|
+
autoComplete: 'off',
|
|
59
|
+
form: {
|
|
60
|
+
autoComplete: 'off',
|
|
61
|
+
},
|
|
62
|
+
}, hideArrows: true }))] })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message, { numberLen: country.max_digits }) })] })));
|
|
63
|
+
} }, "phoneNumberFormPhone"), _jsx(Controller, { control: control, name: "firstName", render: (_a) => {
|
|
64
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
65
|
+
return (_jsxs(Box, Object.assign({ ref: firstNameRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { placeholder: t('firstName'), inputProps: { autoComplete: 'off' }, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
66
|
+
} }, "phoneNumberFormFirstName"), _jsx(Controller, { control: control, name: "lastName", render: (_a) => {
|
|
67
|
+
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]), { fieldState: { error } } = _a;
|
|
68
|
+
return (_jsxs(Box, Object.assign({ ref: lastNameRef }, { children: [_jsx(InputStyled, Object.assign({}, field, { placeholder: t('lastName'), inputProps: { autoComplete: 'off' }, error: Boolean(error === null || error === void 0 ? void 0 : error.message) })), (error === null || error === void 0 ? void 0 : error.message) && _jsx(ErrorStyled, { error: t(error.message) })] })));
|
|
69
|
+
} }, "phoneNumberFormLastName"), _jsx(SubmitButton, Object.assign({ onClick: onSubmit, disabled: !isValid || isItemsNotValid || !items.length }, { children: submitButtonText }))] })));
|
|
70
|
+
}
|
|
71
|
+
export default memo(PhoneNumberForm);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './validation';
|
|
2
|
+
export * from './EmailForm';
|
|
3
|
+
export { default as EmailForm } from './EmailForm';
|
|
4
|
+
export * from './FullInfo';
|
|
5
|
+
export { default as FullInfo } from './FullInfo';
|
|
6
|
+
export * from './FullInfoForm';
|
|
7
|
+
export { default as FullInfoForm } from './FullInfoForm';
|
|
8
|
+
export * from './PhoneNumberForm';
|
|
9
|
+
export { default as PhoneNumberForm } from './PhoneNumberForm';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './validation';
|
|
2
|
+
export * from './EmailForm';
|
|
3
|
+
export { default as EmailForm } from './EmailForm';
|
|
4
|
+
export * from './FullInfo';
|
|
5
|
+
export { default as FullInfo } from './FullInfo';
|
|
6
|
+
export * from './FullInfoForm';
|
|
7
|
+
export { default as FullInfoForm } from './FullInfoForm';
|
|
8
|
+
export * from './PhoneNumberForm';
|
|
9
|
+
export { default as PhoneNumberForm } from './PhoneNumberForm';
|