@tap-payments/os-micro-frontend-shared 0.1.261 → 0.1.262
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/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 +1 -0
- package/build/components/Customer/index.js +1 -0
- package/build/components/Error/Error.d.ts +1 -1
- package/build/components/Inputs/CountriesDropDown/CountriesDropdown.d.ts +5 -4
- package/build/components/Inputs/CountriesDropDown/CountriesDropdown.js +3 -3
- package/build/components/index.d.ts +1 -0
- package/build/components/index.js +1 -0
- package/package.json +18 -17
|
@@ -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';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const MobileWrapper: 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 SearchWrapper: 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 FormWrapper: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
9
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
10
|
+
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
11
|
+
export declare const SubmitButton: import("@emotion/styled").StyledComponent<import("@mui/material/Button").ButtonOwnProps & Omit<import("@mui/material").ButtonBaseOwnProps, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
|
12
|
+
ref?: ((instance: HTMLButtonElement | null) => void) | import("react").RefObject<HTMLButtonElement> | null | undefined;
|
|
13
|
+
}, "color" | "disabled" | "classes" | "className" | "style" | "tabIndex" | "children" | "sx" | "variant" | "size" | "fullWidth" | "href" | "action" | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "TouchRippleProps" | "touchRippleRef" | "disableElevation" | "disableFocusRipple" | "endIcon" | "startIcon"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
14
|
+
export declare const InputStyled: import("@emotion/styled").StyledComponent<Readonly<import("@mui/material").InputProps & {
|
|
15
|
+
isError?: boolean | undefined;
|
|
16
|
+
}> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
|
|
17
|
+
error?: boolean | undefined;
|
|
18
|
+
}, {}, {}>;
|
|
19
|
+
export declare const InputNumberStyled: import("@emotion/styled").StyledComponent<Omit<Readonly<import("@mui/material").InputProps & {
|
|
20
|
+
isError?: boolean | undefined;
|
|
21
|
+
hideArrows?: boolean | undefined;
|
|
22
|
+
}>, "ref"> & import("react").RefAttributes<HTMLInputElement> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
|
|
23
|
+
error?: boolean | undefined;
|
|
24
|
+
}, {}, {}>;
|
|
25
|
+
export declare const ErrorStyled: import("@emotion/styled").StyledComponent<import("../../Error/Error").ErrorI & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import Box from '@mui/material/Box';
|
|
2
|
+
import Button from '@mui/material/Button';
|
|
3
|
+
import { styled, alpha } from '@mui/material/styles';
|
|
4
|
+
import { Input, InputNumber, Error } from '../../index.js';
|
|
5
|
+
export const MobileWrapper = styled(Box)(({ theme }) => ({
|
|
6
|
+
border: `1px solid ${theme.palette.divider}`,
|
|
7
|
+
display: 'flex',
|
|
8
|
+
position: 'relative',
|
|
9
|
+
paddingInline: '8px',
|
|
10
|
+
alignItems: 'center',
|
|
11
|
+
borderRadius: '4px',
|
|
12
|
+
height: '40px',
|
|
13
|
+
}));
|
|
14
|
+
export const SearchWrapper = styled(Box)(() => ({
|
|
15
|
+
display: 'flex',
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
}));
|
|
18
|
+
export const FormWrapper = styled(Box)(({ theme }) => ({
|
|
19
|
+
padding: '8px',
|
|
20
|
+
display: 'flex',
|
|
21
|
+
flexDirection: 'column',
|
|
22
|
+
gap: '8px',
|
|
23
|
+
position: 'relative',
|
|
24
|
+
background: theme.palette.common.white,
|
|
25
|
+
borderRadius: '4px',
|
|
26
|
+
width: 'max-content',
|
|
27
|
+
maxWidth: 230,
|
|
28
|
+
boxShadow: theme.shadows[3],
|
|
29
|
+
}));
|
|
30
|
+
export const SubmitButton = styled(Button)(({ theme }) => ({
|
|
31
|
+
display: 'flex',
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
justifyContent: 'center',
|
|
34
|
+
textTransform: 'capitalize',
|
|
35
|
+
padding: '8px 13px',
|
|
36
|
+
minWidth: 89,
|
|
37
|
+
height: 32,
|
|
38
|
+
fontSize: '11px',
|
|
39
|
+
borderRadius: '4px',
|
|
40
|
+
fontWeight: 700,
|
|
41
|
+
background: theme.palette.info.dark,
|
|
42
|
+
color: theme.palette.common.white,
|
|
43
|
+
textAlign: 'center',
|
|
44
|
+
'&.Mui-disabled': {
|
|
45
|
+
backgroundColor: alpha(theme.palette.grey[700], 0.5),
|
|
46
|
+
color: theme.palette.common.white,
|
|
47
|
+
cursor: 'not-allowed',
|
|
48
|
+
},
|
|
49
|
+
'&:hover': {
|
|
50
|
+
background: theme.palette.info.dark,
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
export const InputStyled = styled(Input, { shouldForwardProp: (props) => props !== 'error' })(({ error }) => (Object.assign({ img: {
|
|
54
|
+
cursor: 'pointer',
|
|
55
|
+
} }, (error && {
|
|
56
|
+
borderBottomLeftRadius: 0,
|
|
57
|
+
borderBottomRightRadius: 0,
|
|
58
|
+
borderBottom: 'none',
|
|
59
|
+
}))));
|
|
60
|
+
export const InputNumberStyled = styled(InputNumber, { shouldForwardProp: (props) => props !== 'error' })(({ error }) => (Object.assign({ img: {
|
|
61
|
+
cursor: 'pointer',
|
|
62
|
+
} }, (error && {
|
|
63
|
+
borderBottomLeftRadius: 0,
|
|
64
|
+
borderBottomRightRadius: 0,
|
|
65
|
+
borderBottom: 'none',
|
|
66
|
+
}))));
|
|
67
|
+
export const ErrorStyled = styled(Error)(() => ({
|
|
68
|
+
borderTopLeftRadius: 0,
|
|
69
|
+
borderTopRightRadius: 0,
|
|
70
|
+
height: 25,
|
|
71
|
+
}));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as Yup from 'yup';
|
|
2
|
+
export declare const validationEmailFromSchema: Yup.ObjectSchema<{
|
|
3
|
+
email: string;
|
|
4
|
+
firstName: string;
|
|
5
|
+
lastName: string;
|
|
6
|
+
}, Yup.AnyObject, {
|
|
7
|
+
email: undefined;
|
|
8
|
+
firstName: undefined;
|
|
9
|
+
lastName: undefined;
|
|
10
|
+
}, "">;
|
|
11
|
+
export declare const validationFullInfoSchema: (numberLen: number) => Yup.ObjectSchema<{
|
|
12
|
+
email: string | undefined;
|
|
13
|
+
phoneNumber: string | undefined;
|
|
14
|
+
firstName: string;
|
|
15
|
+
lastName: string;
|
|
16
|
+
}, Yup.AnyObject, {
|
|
17
|
+
email: undefined;
|
|
18
|
+
phoneNumber: undefined;
|
|
19
|
+
firstName: undefined;
|
|
20
|
+
lastName: undefined;
|
|
21
|
+
}, "">;
|
|
22
|
+
export declare const validationPhoneNumberSchema: (numberLen: number) => Yup.ObjectSchema<{
|
|
23
|
+
firstName: string;
|
|
24
|
+
lastName: string;
|
|
25
|
+
phoneNumber: string;
|
|
26
|
+
}, Yup.AnyObject, {
|
|
27
|
+
firstName: undefined;
|
|
28
|
+
lastName: undefined;
|
|
29
|
+
phoneNumber: undefined;
|
|
30
|
+
}, "">;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as Yup from 'yup';
|
|
2
|
+
export const validationEmailFromSchema = Yup.object().shape({
|
|
3
|
+
email: Yup.string()
|
|
4
|
+
.matches(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i, 'invalidEmail')
|
|
5
|
+
.required('requiredEmail'),
|
|
6
|
+
firstName: Yup.string().required('requiredFirstName').min(3, 'invalidFirstName'),
|
|
7
|
+
lastName: Yup.string().required('requiredLastName').min(3, 'invalidLastName'),
|
|
8
|
+
});
|
|
9
|
+
export const validationFullInfoSchema = (numberLen) => Yup.object()
|
|
10
|
+
.shape({
|
|
11
|
+
email: Yup.string()
|
|
12
|
+
.transform((value, originalValue) => {
|
|
13
|
+
if (originalValue === '')
|
|
14
|
+
return undefined;
|
|
15
|
+
return value;
|
|
16
|
+
})
|
|
17
|
+
.matches(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{1,}$/i, 'invalidEmail')
|
|
18
|
+
.optional(),
|
|
19
|
+
phoneNumber: Yup.string()
|
|
20
|
+
.transform((value, originalValue) => {
|
|
21
|
+
if (!originalValue)
|
|
22
|
+
return undefined;
|
|
23
|
+
return value;
|
|
24
|
+
})
|
|
25
|
+
.length(numberLen, `invalidMobile`)
|
|
26
|
+
.optional(),
|
|
27
|
+
firstName: Yup.string().min(3, 'invalidFirstName').required('requiredFirstName'),
|
|
28
|
+
lastName: Yup.string().min(3, 'invalidLastName').required('requiredLastName'),
|
|
29
|
+
})
|
|
30
|
+
.test('atLeastOne', 'atLeastOne', function testAtLeastOne(_, ctx) {
|
|
31
|
+
var _a;
|
|
32
|
+
const { email, phoneNumber } = (_a = this.originalValue) !== null && _a !== void 0 ? _a : {};
|
|
33
|
+
if (!email && !phoneNumber) {
|
|
34
|
+
return ctx.createError({ message: 'atLeastOne' });
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
export const validationPhoneNumberSchema = (numberLen) => Yup.object().shape({
|
|
39
|
+
firstName: Yup.string().required('requiredFirstName').min(3, 'invalidFirstName'),
|
|
40
|
+
lastName: Yup.string().required('requiredLastName').min(3, 'invalidLastName'),
|
|
41
|
+
phoneNumber: Yup.string().length(numberLen, `invalidMobile`).required('requiredMobile'),
|
|
42
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as CustomerDropdown } from './CustomerDropdown';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as CustomerDropdown } from './CustomerDropdown';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { BoxProps } from '@mui/material/Box';
|
|
3
|
-
interface ErrorI extends BoxProps {
|
|
3
|
+
export interface ErrorI extends BoxProps {
|
|
4
4
|
error: string;
|
|
5
5
|
}
|
|
6
6
|
declare function Error({ error, ...props }: ErrorI): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Country } from '../../../types/index.js';
|
|
3
|
-
|
|
3
|
+
type CountriesDropdownProps = {
|
|
4
4
|
value?: Partial<Country>;
|
|
5
5
|
defaultCountry?: string;
|
|
6
6
|
onChangeCountry?: (country: Country) => void;
|
|
7
7
|
required?: boolean;
|
|
8
8
|
countries: Country[];
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
declare
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare function CountriesDropdown({ defaultCountry, value: selectedCountry, onChangeCountry, required, countries, isLoading, }: Readonly<CountriesDropdownProps>): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
declare const _default: import("react").MemoExoticComponent<typeof CountriesDropdown>;
|
|
12
13
|
export default _default;
|
|
@@ -6,7 +6,7 @@ import Popper from '@mui/material/Popper';
|
|
|
6
6
|
import Skeleton from '@mui/material/Skeleton';
|
|
7
7
|
import { downArrowIcon, searchIcon } from '../../../constants/index.js';
|
|
8
8
|
import { CountryStyled, CountriesWrapper, CountriesList, InputStyled, CountryButton, Required } from './style';
|
|
9
|
-
function
|
|
9
|
+
function CountriesDropdown({ defaultCountry, value: selectedCountry, onChangeCountry, required, countries = [], isLoading = false, }) {
|
|
10
10
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
11
11
|
const [filteredCountries, setFilteredCountries] = useState([]);
|
|
12
12
|
const [searchValue, setSearchValue] = useState();
|
|
@@ -45,7 +45,7 @@ function CountriesCode({ defaultCountry, value: selectedCountry, onChangeCountry
|
|
|
45
45
|
}
|
|
46
46
|
setFilteredCountries(countries.filter((country) => country.idd_prefix.toString().startsWith(value.toString())));
|
|
47
47
|
};
|
|
48
|
-
if (
|
|
48
|
+
if (isLoading) {
|
|
49
49
|
return _jsx(Skeleton, { variant: "rectangular", width: 56.5, height: 20, sx: { borderRadius: '4px' } });
|
|
50
50
|
}
|
|
51
51
|
return (_jsx(ClickAwayListener, Object.assign({ onClickAway: closeDropdown }, { children: _jsxs(Box, Object.assign({ "data-testid": "CountriesCode", sx: { position: 'relative' } }, { children: [_jsxs(CountryButton, Object.assign({ type: "button", onClick: openDropdown, sx: {
|
|
@@ -56,4 +56,4 @@ function CountriesCode({ defaultCountry, value: selectedCountry, onChangeCountry
|
|
|
56
56
|
selectNewCode(country);
|
|
57
57
|
} }, { children: [country.logo ? _jsx("img", { src: country.logo, alt: "c", className: "logo" }) : _jsx(Skeleton, { variant: "rectangular", className: "logo" }), _jsx("span", { children: `+${country.idd_prefix}` })] }), `country-code-${country.countryId}`))) })] })) }))] })) })));
|
|
58
58
|
}
|
|
59
|
-
export default memo(
|
|
59
|
+
export default memo(CountriesDropdown);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/os-micro-frontend-shared",
|
|
3
3
|
"description": "Shared components and utilities for Tap Payments micro frontends",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.262",
|
|
5
5
|
"testVersion": 0,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
@@ -102,7 +102,8 @@
|
|
|
102
102
|
"react-window": "^1.8.9",
|
|
103
103
|
"react-window-infinite-loader": "^1.0.9",
|
|
104
104
|
"react18-input-otp": "^1.1.4",
|
|
105
|
-
"recharts": "^2.15.1"
|
|
105
|
+
"recharts": "^2.15.1",
|
|
106
|
+
"yup": "^1.7.1"
|
|
106
107
|
},
|
|
107
108
|
"devDependencies": {
|
|
108
109
|
"@eslint/js": "^9.17.0",
|
|
@@ -129,30 +130,30 @@
|
|
|
129
130
|
"vite-tsconfig-paths": "^4.2.0"
|
|
130
131
|
},
|
|
131
132
|
"peerDependencies": {
|
|
132
|
-
"react": "^18",
|
|
133
|
-
"react-dom": "^18",
|
|
134
|
-
"@mui/material": "^5",
|
|
135
133
|
"@emotion/react": "^11",
|
|
136
134
|
"@emotion/styled": "^11",
|
|
137
|
-
"framer-motion": "^10",
|
|
138
|
-
"react-hook-form": "^7",
|
|
139
135
|
"@hookform/resolvers": "^3",
|
|
140
|
-
"
|
|
141
|
-
"
|
|
142
|
-
"react-i18next": "^12",
|
|
143
|
-
"react-multi-date-picker": "^4",
|
|
136
|
+
"@mui/material": "^5",
|
|
137
|
+
"@uiw/react-json-view": "^2.0.0-alpha",
|
|
144
138
|
"dayjs": "^1",
|
|
139
|
+
"framer-motion": "^10",
|
|
140
|
+
"i18next": "^22",
|
|
141
|
+
"re-resizable": "^6",
|
|
142
|
+
"react": "^18",
|
|
143
|
+
"react-currency-input-field": "^3",
|
|
144
|
+
"react-dom": "^18",
|
|
145
|
+
"react-draggable": "^4",
|
|
145
146
|
"react-dropzone": "^14",
|
|
147
|
+
"react-hook-form": "^7",
|
|
146
148
|
"react-hot-toast": "^2",
|
|
147
|
-
"
|
|
149
|
+
"react-i18next": "^12",
|
|
150
|
+
"react-multi-date-picker": "^4",
|
|
151
|
+
"react-router-dom": "^7",
|
|
152
|
+
"react-virtualized-auto-sizer": "^1",
|
|
148
153
|
"react-window": "^1.8",
|
|
149
154
|
"react-window-infinite-loader": "^1",
|
|
150
|
-
"react-virtualized-auto-sizer": "^1",
|
|
151
|
-
"re-resizable": "^6",
|
|
152
|
-
"react-draggable": "^4",
|
|
153
|
-
"react-currency-input-field": "^3",
|
|
154
155
|
"react18-input-otp": "^1",
|
|
155
|
-
"
|
|
156
|
+
"recharts": "^2"
|
|
156
157
|
},
|
|
157
158
|
"lint-staged": {
|
|
158
159
|
"src/**/*.{ts,tsx,json,js,jsx}": [
|