@tap-payments/os-micro-frontend-shared 0.1.253 → 0.1.254-test.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/Chip/style.d.ts +0 -1
- package/build/components/CountBadge/style.d.ts +0 -1
- package/build/components/Dialog/style.d.ts +0 -1
- package/build/components/FilterDropdown/FilterDropdown.d.ts +10 -0
- package/build/components/FilterDropdown/FilterDropdown.js +54 -0
- package/build/components/FilterDropdown/components/BrandItem/BrandItem.d.ts +12 -0
- package/build/components/FilterDropdown/components/BrandItem/BrandItem.js +39 -0
- package/build/components/FilterDropdown/components/BrandItem/index.d.ts +2 -0
- package/build/components/FilterDropdown/components/BrandItem/index.js +2 -0
- package/build/components/FilterDropdown/components/BrandItem/style.d.ts +4 -0
- package/build/components/FilterDropdown/components/BrandItem/style.js +9 -0
- package/build/components/FilterDropdown/components/CountriesItem/CountriesItem.d.ts +12 -0
- package/build/components/FilterDropdown/components/CountriesItem/CountriesItem.js +54 -0
- package/build/components/FilterDropdown/components/CountriesItem/index.d.ts +1 -0
- package/build/components/FilterDropdown/components/CountriesItem/index.js +1 -0
- package/build/components/FilterDropdown/components/CurrenciesItem/CurrenciesItem.d.ts +12 -0
- package/build/components/FilterDropdown/components/CurrenciesItem/CurrenciesItem.js +59 -0
- package/build/components/FilterDropdown/components/CurrenciesItem/index.d.ts +1 -0
- package/build/components/FilterDropdown/components/CurrenciesItem/index.js +1 -0
- package/build/components/FilterDropdown/components/FlatMerchantsListMenu/FlatMerchantsListMenu.d.ts +11 -0
- package/build/components/FilterDropdown/components/FlatMerchantsListMenu/FlatMerchantsListMenu.js +39 -0
- package/build/components/FilterDropdown/components/FlatMerchantsListMenu/index.d.ts +2 -0
- package/build/components/FilterDropdown/components/FlatMerchantsListMenu/index.js +2 -0
- package/build/components/FilterDropdown/components/FlatMerchantsListMenu/style.d.ts +12 -0
- package/build/components/FilterDropdown/components/FlatMerchantsListMenu/style.js +23 -0
- package/build/components/FilterDropdown/components/MerchantItem/MerchantItem.d.ts +13 -0
- package/build/components/FilterDropdown/components/MerchantItem/MerchantItem.js +43 -0
- package/build/components/FilterDropdown/components/MerchantItem/index.d.ts +2 -0
- package/build/components/FilterDropdown/components/MerchantItem/index.js +2 -0
- package/build/components/FilterDropdown/components/RetailersItem/RetailersItem.d.ts +14 -0
- package/build/components/FilterDropdown/components/RetailersItem/RetailersItem.js +70 -0
- package/build/components/FilterDropdown/components/RetailersItem/index.d.ts +1 -0
- package/build/components/FilterDropdown/components/RetailersItem/index.js +1 -0
- package/build/components/FilterDropdown/components/RetailersItem/style.d.ts +4 -0
- package/build/components/FilterDropdown/components/RetailersItem/style.js +8 -0
- package/build/components/FilterDropdown/components/index.d.ts +4 -0
- package/build/components/FilterDropdown/components/index.js +4 -0
- package/build/components/FilterDropdown/index.d.ts +3 -0
- package/build/components/FilterDropdown/index.js +3 -0
- package/build/components/FilterDropdown/style.d.ts +20 -0
- package/build/components/FilterDropdown/style.js +60 -0
- package/build/components/FilterDropdown/type.d.ts +4 -0
- package/build/components/FilterDropdown/type.js +1 -0
- package/build/components/FlippingCard/style.d.ts +0 -1
- package/build/components/ImageWrapper/ImageWrapper.d.ts +0 -1
- package/build/components/JSONViewer/style.d.ts +0 -1
- package/build/components/LeftPeekRightExpandingChip/style.d.ts +0 -1
- package/build/components/MenuItem/MenuItem.d.ts +1 -1
- package/build/components/MerchantCurrencyDropdown/MerchantCurrencyDropdown.d.ts +12 -0
- package/build/components/MerchantCurrencyDropdown/MerchantCurrencyDropdown.js +38 -0
- package/build/components/MerchantCurrencyDropdown/SelectedCurrency.d.ts +5 -0
- package/build/components/MerchantCurrencyDropdown/SelectedCurrency.js +6 -0
- package/build/components/MerchantCurrencyDropdown/index.d.ts +1 -0
- package/build/components/MerchantCurrencyDropdown/index.js +1 -0
- package/build/components/MerchantCurrencyDropdown/style.d.ts +13 -0
- package/build/components/MerchantCurrencyDropdown/style.js +64 -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 +2 -0
- package/build/components/index.js +2 -0
- package/build/types/destination.d.ts +14 -0
- package/build/types/index.d.ts +1 -0
- package/build/types/index.js +1 -0
- package/package.json +3 -3
|
@@ -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,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface FilterDropdownProps {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
onConfirm: () => void;
|
|
5
|
+
onCancel: () => void;
|
|
6
|
+
isOkayButDisabled?: boolean;
|
|
7
|
+
isDisabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export default function FilterDropdown({ onConfirm, onCancel, isOkayButDisabled, children, isDisabled }: Readonly<FilterDropdownProps>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { useState, useEffect } from 'react';
|
|
5
|
+
import { ClickAwayListener } from '@mui/material';
|
|
6
|
+
import { darkFilterIcon } from '../../constants/index.js';
|
|
7
|
+
import { Menu, CustomBackdrop } from '../index.js';
|
|
8
|
+
import { CancelButton, FilterButton, Footer, OkayButton, TitleStyled } from './style';
|
|
9
|
+
export default function FilterDropdown({ onConfirm, onCancel, isOkayButDisabled, children, isDisabled }) {
|
|
10
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
11
|
+
const open = Boolean(anchorEl);
|
|
12
|
+
const { t } = useTranslation();
|
|
13
|
+
// Lock body scroll when filter dropdown is open (Safari fix)
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (open) {
|
|
16
|
+
const scrollY = window.scrollY;
|
|
17
|
+
document.body.style.position = 'fixed';
|
|
18
|
+
document.body.style.top = `-${scrollY}px`;
|
|
19
|
+
document.body.style.width = '100%';
|
|
20
|
+
document.body.style.overflow = 'hidden';
|
|
21
|
+
return () => {
|
|
22
|
+
document.body.style.position = '';
|
|
23
|
+
document.body.style.top = '';
|
|
24
|
+
document.body.style.width = '';
|
|
25
|
+
document.body.style.overflow = '';
|
|
26
|
+
window.scrollTo(0, scrollY);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}, [open]);
|
|
30
|
+
const onOpen = (e) => {
|
|
31
|
+
if (isDisabled)
|
|
32
|
+
return;
|
|
33
|
+
if (!open) {
|
|
34
|
+
setAnchorEl(e.currentTarget);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
onClose();
|
|
38
|
+
};
|
|
39
|
+
const onClose = () => {
|
|
40
|
+
setAnchorEl(null);
|
|
41
|
+
onCancel();
|
|
42
|
+
};
|
|
43
|
+
const handleCancel = () => {
|
|
44
|
+
if (!open)
|
|
45
|
+
return;
|
|
46
|
+
onCancel();
|
|
47
|
+
onClose();
|
|
48
|
+
};
|
|
49
|
+
const handleConfirm = () => {
|
|
50
|
+
onConfirm();
|
|
51
|
+
onClose();
|
|
52
|
+
};
|
|
53
|
+
return (_jsx(ClickAwayListener, Object.assign({ onClickAway: handleCancel }, { children: _jsxs(Box, { children: [_jsx(FilterButton, Object.assign({ isActive: open, onClick: onOpen, sx: Object.assign({}, (isDisabled && { pointerEvents: 'none', opacity: 0.5 })) }, { children: _jsx(Box, { component: "img", src: darkFilterIcon, alt: "filter" }) })), _jsxs(Menu, Object.assign({ anchorEl: anchorEl, open: open, sx: { marginTop: '8px', marginBottom: '8px', width: 193 }, placement: "bottom-end" }, { children: [_jsx(TitleStyled, Object.assign({ component: "span" }, { children: t('filterBy') })), children, _jsxs(Footer, { children: [_jsx(CancelButton, Object.assign({ onClick: handleCancel }, { children: t('cancel') })), _jsx(OkayButton, Object.assign({ disabled: isOkayButDisabled, onClick: handleConfirm }, { children: t('okay') }))] })] })), open && _jsx(CustomBackdrop, { onClick: onClose })] }) })));
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MerchantItemProps } from '../MerchantItem';
|
|
3
|
+
import { BrandProps } from '../../type';
|
|
4
|
+
interface BrandItemProps extends Pick<MerchantItemProps, 'atLeastOneMerchantSelected' | 'merchantsIds'> {
|
|
5
|
+
brand: BrandProps;
|
|
6
|
+
isDisabled?: boolean;
|
|
7
|
+
showSearchInput?: boolean;
|
|
8
|
+
renderBrandLogo: (logo: string) => React.ReactNode;
|
|
9
|
+
onChangeMerchant?: (value: string[]) => void;
|
|
10
|
+
}
|
|
11
|
+
export default function BrandItem({ brand, merchantsIds, isDisabled, atLeastOneMerchantSelected, showSearchInput, renderBrandLogo, onChangeMerchant, }: Readonly<BrandItemProps>): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useMemo } from 'react';
|
|
3
|
+
import { MenuItem, Text } from '../../../index.js';
|
|
4
|
+
import { rightArrow } from '../../../../constants/index.js';
|
|
5
|
+
import { getNameText } from '../../../../utils/index.js';
|
|
6
|
+
import FlatMerchantsListMenu from '../FlatMerchantsListMenu';
|
|
7
|
+
import { Brand } from './style';
|
|
8
|
+
export default function BrandItem({ brand, merchantsIds, isDisabled, atLeastOneMerchantSelected = false, showSearchInput = false, renderBrandLogo, onChangeMerchant, }) {
|
|
9
|
+
var _a;
|
|
10
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
11
|
+
const open = Boolean(anchorEl);
|
|
12
|
+
const onOpen = (e) => {
|
|
13
|
+
setAnchorEl(e.currentTarget);
|
|
14
|
+
};
|
|
15
|
+
const onClose = () => {
|
|
16
|
+
setAnchorEl(null);
|
|
17
|
+
};
|
|
18
|
+
const selectedBrandMerchants = useMemo(() => brand.merchants.filter((merchant) => merchantsIds.includes(merchant.legacy_id)), [merchantsIds, brand.merchants]);
|
|
19
|
+
const isAllBrandsSelected = useMemo(() => selectedBrandMerchants.length === brand.merchants.length, [selectedBrandMerchants.length, brand.merchants.length]);
|
|
20
|
+
const isSomeSelected = useMemo(() => !isAllBrandsSelected && selectedBrandMerchants.length > 0, [isAllBrandsSelected, selectedBrandMerchants]);
|
|
21
|
+
const onClickBrand = (e) => {
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
if (isAllBrandsSelected) {
|
|
24
|
+
onChangeMerchant === null || onChangeMerchant === void 0 ? void 0 : onChangeMerchant(merchantsIds.filter((merchantId) => !brand.merchants.some(({ legacy_id }) => merchantId === legacy_id)));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (isSomeSelected) {
|
|
28
|
+
const uniqueMids = [...new Set([...merchantsIds, ...selectedBrandMerchants.map(({ legacy_id }) => legacy_id)])];
|
|
29
|
+
onChangeMerchant === null || onChangeMerchant === void 0 ? void 0 : onChangeMerchant(uniqueMids);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
onChangeMerchant === null || onChangeMerchant === void 0 ? void 0 : onChangeMerchant([...merchantsIds, ...brand.merchants.map(({ legacy_id }) => legacy_id)]);
|
|
33
|
+
};
|
|
34
|
+
return (_jsxs(MenuItem, Object.assign({ isSelected: isAllBrandsSelected, isIndeterminate: isSomeSelected, onMouseEnter: onOpen, onMouseLeave: onClose, onClick: (e) => {
|
|
35
|
+
if (isDisabled)
|
|
36
|
+
return;
|
|
37
|
+
onClickBrand(e);
|
|
38
|
+
}, isDisabled: isDisabled, sx: Object.assign({ maxHeight: 35, minHeight: 35 }, (open && { boxShadow: '0px 0px 16px 0px #00000021' })) }, { children: [_jsxs(Brand, { children: [renderBrandLogo === null || renderBrandLogo === void 0 ? void 0 : renderBrandLogo(brand.logo), _jsx(Text, Object.assign({ sx: { fontSize: '11px' } }, { children: getNameText(brand.name) }))] }), ((_a = brand.merchants) === null || _a === void 0 ? void 0 : _a.length) > 0 && _jsx("img", { src: rightArrow, alt: "arrow", style: { height: 12 } }), _jsx(FlatMerchantsListMenu, { anchorEl: anchorEl, brand: brand, merchantsIds: merchantsIds, onChangeMerchant: onChangeMerchant, atLeastOneMerchantSelected: atLeastOneMerchantSelected, showSearchInput: showSearchInput })] })));
|
|
39
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Brand: 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>, {}, {}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface CountriesItemProps {
|
|
3
|
+
countries: string[];
|
|
4
|
+
isLoading?: boolean;
|
|
5
|
+
countriesIds: string[];
|
|
6
|
+
onFilterChange?: (value: string[]) => void;
|
|
7
|
+
atLeastOneCountrySelected?: boolean;
|
|
8
|
+
hideCheckbox?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function CountriesItem({ countriesIds, isLoading, countries, onFilterChange, atLeastOneCountrySelected, hideCheckbox, }: Readonly<CountriesItemProps>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
declare const _default: import("react").MemoExoticComponent<typeof CountriesItem>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CountryFlag, Menu, MenuItem, Text } from '../../../index.js';
|
|
3
|
+
import { rightArrow } from '../../../../constants/index.js';
|
|
4
|
+
import { getCountryNameByISO } from '../../../../utils/index.js';
|
|
5
|
+
import { memo, useCallback, useMemo, useState } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
function CountriesItem({ countriesIds = [], isLoading, countries = [], onFilterChange, atLeastOneCountrySelected = false, hideCheckbox = false, }) {
|
|
8
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
9
|
+
const open = Boolean(anchorEl);
|
|
10
|
+
const { t } = useTranslation();
|
|
11
|
+
const onOpen = (e) => {
|
|
12
|
+
if (!open)
|
|
13
|
+
setAnchorEl(e.currentTarget);
|
|
14
|
+
};
|
|
15
|
+
const onClose = () => {
|
|
16
|
+
if (open)
|
|
17
|
+
setAnchorEl(null);
|
|
18
|
+
};
|
|
19
|
+
const isCountrySelected = useCallback((countryCode) => countriesIds === null || countriesIds === void 0 ? void 0 : countriesIds.includes(countryCode), [countriesIds]);
|
|
20
|
+
const isAllSelected = useMemo(() => {
|
|
21
|
+
if (!countries.length)
|
|
22
|
+
return false;
|
|
23
|
+
return countries.every((country) => isCountrySelected(country));
|
|
24
|
+
}, [countries, isCountrySelected]);
|
|
25
|
+
const isSomeSelected = useMemo(() => !isAllSelected && countriesIds.length > 0, [countriesIds, isAllSelected]);
|
|
26
|
+
const onClick = () => {
|
|
27
|
+
if (atLeastOneCountrySelected)
|
|
28
|
+
return;
|
|
29
|
+
if (isAllSelected) {
|
|
30
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange([]);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(countries);
|
|
34
|
+
};
|
|
35
|
+
const isLastCountryToBeDisabled = (currMid) => {
|
|
36
|
+
return countriesIds.length === 1 && countriesIds[0] === currMid && atLeastOneCountrySelected;
|
|
37
|
+
};
|
|
38
|
+
const onClickCountry = (e, countryCode) => {
|
|
39
|
+
e.stopPropagation();
|
|
40
|
+
if (isLastCountryToBeDisabled(countryCode))
|
|
41
|
+
return;
|
|
42
|
+
if (isCountrySelected(countryCode)) {
|
|
43
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(countriesIds.filter((country) => country !== countryCode));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const uniqueMids = [...new Set([...countriesIds, countryCode])];
|
|
47
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(uniqueMids);
|
|
48
|
+
};
|
|
49
|
+
const isDisabled = isLoading || (countries === null || countries === void 0 ? void 0 : countries.length) <= 0 || atLeastOneCountrySelected;
|
|
50
|
+
return (_jsxs(MenuItem, Object.assign({ isDisabled: isDisabled, isSelected: isAllSelected, hideCheckbox: hideCheckbox, isIndeterminate: isSomeSelected, sx: Object.assign(Object.assign({ maxHeight: 35, minHeight: 35, padding: '12px 8px 12px 16px' }, (open && { boxShadow: '0px 0px 16px 0px #00000021' })), (!(countries === null || countries === void 0 ? void 0 : countries.length) && { opacity: 0.5, pointerEvents: 'none' })), onMouseEnter: onOpen, onMouseLeave: onClose, onClick: onClick }, { children: [_jsx(Text, Object.assign({ sx: { fontSize: '11px', flex: 1 } }, { children: t('walletCountry') })), (countries === null || countries === void 0 ? void 0 : countries.length) > 0 && _jsx("img", { src: rightArrow, alt: "arrow", style: { height: 12 } }), _jsx(Menu, Object.assign({ open: open, anchorEl: anchorEl, placement: "right-start", sx: { width: 200, overflow: 'auto' } }, { children: countries === null || countries === void 0 ? void 0 : countries.map((country, index) => (_jsxs(MenuItem, Object.assign({ isSelected: isCountrySelected(country), isDisabled: isLoading || isLastCountryToBeDisabled(country), onClick: (e) => {
|
|
51
|
+
onClickCountry(e, country);
|
|
52
|
+
}, sx: { maxHeight: 35, minHeight: 35 } }, { children: [_jsx(CountryFlag, { countryCode: country }), _jsx(Text, Object.assign({ sx: { fontSize: '11px !important', fontWeight: '500 !important' } }, { children: getCountryNameByISO(country) }))] }), `key-${country}-${index}`))) }))] })));
|
|
53
|
+
}
|
|
54
|
+
export default memo(CountriesItem);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './CountriesItem';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './CountriesItem';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface CurrenciesItemProps {
|
|
3
|
+
currencies: string[];
|
|
4
|
+
isLoading?: boolean;
|
|
5
|
+
currenciesIds: string[];
|
|
6
|
+
atLeastOneCurrencySelected?: boolean;
|
|
7
|
+
hideCheckbox?: boolean;
|
|
8
|
+
onFilterChange?: (value: string[]) => void;
|
|
9
|
+
}
|
|
10
|
+
declare function CurrenciesItem({ currenciesIds, isLoading, currencies, onFilterChange, atLeastOneCurrencySelected, hideCheckbox, }: Readonly<CurrenciesItemProps>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
declare const _default: import("react").MemoExoticComponent<typeof CurrenciesItem>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CountryFlag, Menu, MenuItem, Text } from '../../../index.js';
|
|
3
|
+
import { rightArrow, SUPPORTED_CURRENCY_DETAILS } from '../../../../constants/index.js';
|
|
4
|
+
import { memo, useCallback, useMemo, useState } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
function CurrenciesItem({ currenciesIds = [], isLoading, currencies = [], onFilterChange, atLeastOneCurrencySelected = false, hideCheckbox = false, }) {
|
|
7
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
8
|
+
const open = Boolean(anchorEl);
|
|
9
|
+
const { t } = useTranslation();
|
|
10
|
+
const onOpen = (e) => {
|
|
11
|
+
if (!open)
|
|
12
|
+
setAnchorEl(e.currentTarget);
|
|
13
|
+
};
|
|
14
|
+
const onClose = () => {
|
|
15
|
+
if (open)
|
|
16
|
+
setAnchorEl(null);
|
|
17
|
+
};
|
|
18
|
+
const isCurrencySelected = useCallback((currencyCode) => currenciesIds === null || currenciesIds === void 0 ? void 0 : currenciesIds.includes(currencyCode), [currenciesIds]);
|
|
19
|
+
const isAllSelected = useMemo(() => {
|
|
20
|
+
if (!currencies.length)
|
|
21
|
+
return false;
|
|
22
|
+
return currencies.every((currency) => isCurrencySelected(currency));
|
|
23
|
+
}, [currencies, isCurrencySelected]);
|
|
24
|
+
const isSomeSelected = useMemo(() => !isAllSelected && currenciesIds.length > 0, [currenciesIds, isAllSelected]);
|
|
25
|
+
const onClick = () => {
|
|
26
|
+
if (atLeastOneCurrencySelected)
|
|
27
|
+
return;
|
|
28
|
+
if (isAllSelected) {
|
|
29
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange([]);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(currencies);
|
|
33
|
+
};
|
|
34
|
+
const isLastCurrencyToBeDisabled = (currMid) => {
|
|
35
|
+
return currenciesIds.length === 1 && currenciesIds[0] === currMid && atLeastOneCurrencySelected;
|
|
36
|
+
};
|
|
37
|
+
const onClickCurrency = (e, currencyCode) => {
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
if (isLastCurrencyToBeDisabled(currencyCode))
|
|
40
|
+
return;
|
|
41
|
+
if (isCurrencySelected(currencyCode)) {
|
|
42
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(currenciesIds.filter((currency) => currency !== currencyCode));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const uniqueMids = [...new Set([...currenciesIds, currencyCode])];
|
|
46
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(uniqueMids);
|
|
47
|
+
};
|
|
48
|
+
const isDisabled = isLoading || (currencies === null || currencies === void 0 ? void 0 : currencies.length) <= 0 || atLeastOneCurrencySelected;
|
|
49
|
+
return (_jsxs(MenuItem, Object.assign({ isDisabled: isDisabled, isSelected: isAllSelected, hideCheckbox: hideCheckbox, isIndeterminate: isSomeSelected, sx: Object.assign(Object.assign({ maxHeight: 35, minHeight: 35, padding: '12px 8px 12px 16px' }, (open && { boxShadow: '0px 0px 16px 0px #00000021' })), (!(currencies === null || currencies === void 0 ? void 0 : currencies.length) && { opacity: 0.5, pointerEvents: 'none' })), onMouseEnter: onOpen, onMouseLeave: onClose, onClick: onClick }, { children: [_jsx(Text, Object.assign({ sx: { fontSize: '11px', flex: 1 } }, { children: t('currency') })), (currencies === null || currencies === void 0 ? void 0 : currencies.length) > 0 && _jsx("img", { src: rightArrow, alt: "arrow", style: { height: 12 } }), _jsx(Menu, Object.assign({ open: open, anchorEl: anchorEl, placement: "right-start", sx: { width: 200, overflow: 'auto' } }, { children: currencies === null || currencies === void 0 ? void 0 : currencies.map((currency, index) => {
|
|
50
|
+
var _a;
|
|
51
|
+
const countryCode = (_a = SUPPORTED_CURRENCY_DETAILS[currency]) === null || _a === void 0 ? void 0 : _a.country;
|
|
52
|
+
if (!countryCode)
|
|
53
|
+
return null;
|
|
54
|
+
return (_jsxs(MenuItem, Object.assign({ isSelected: isCurrencySelected(currency), isDisabled: isLoading || isLastCurrencyToBeDisabled(currency), onClick: (e) => {
|
|
55
|
+
onClickCurrency(e, currency);
|
|
56
|
+
}, sx: { maxHeight: 35, minHeight: 35 } }, { children: [_jsx(CountryFlag, { countryCode: SUPPORTED_CURRENCY_DETAILS[currency].country }), ' ', _jsx(Text, Object.assign({ sx: { fontSize: '11px !important', fontWeight: '500 !important' } }, { children: currency }))] }), `key-${currency}-${index}`));
|
|
57
|
+
}) }))] })));
|
|
58
|
+
}
|
|
59
|
+
export default memo(CurrenciesItem);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './CurrenciesItem';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './CurrenciesItem';
|
package/build/components/FilterDropdown/components/FlatMerchantsListMenu/FlatMerchantsListMenu.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BrandProps } from '../../type';
|
|
2
|
+
type FlatMerchantsListMenuProps = {
|
|
3
|
+
brand: BrandProps;
|
|
4
|
+
merchantsIds: string[];
|
|
5
|
+
onChangeMerchant?: (value: string[]) => void;
|
|
6
|
+
atLeastOneMerchantSelected: boolean;
|
|
7
|
+
showSearchInput?: boolean;
|
|
8
|
+
anchorEl: HTMLElement | null;
|
|
9
|
+
};
|
|
10
|
+
export default function FlatMerchantsListMenu({ brand, merchantsIds, onChangeMerchant, atLeastOneMerchantSelected, showSearchInput, anchorEl, }: Readonly<FlatMerchantsListMenuProps>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
package/build/components/FilterDropdown/components/FlatMerchantsListMenu/FlatMerchantsListMenu.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useMemo, useCallback } from 'react';
|
|
3
|
+
import { Menu, SearchListInput } from '../../../index.js';
|
|
4
|
+
import { MerchantMenuItemStyled, MerchantWrapper, MerchantID, MerchantName } from './style';
|
|
5
|
+
export default function FlatMerchantsListMenu({ brand, merchantsIds, onChangeMerchant, atLeastOneMerchantSelected = false, showSearchInput = false, anchorEl, }) {
|
|
6
|
+
const [searchInputValue, setSearchInputValue] = useState('');
|
|
7
|
+
const open = Boolean(anchorEl);
|
|
8
|
+
const isMerchantSelected = useCallback((merchantId) => merchantsIds.includes(merchantId), [merchantsIds]);
|
|
9
|
+
const onClickMerchant = (e, merchantId) => {
|
|
10
|
+
e.stopPropagation();
|
|
11
|
+
if (isMerchantSelected(merchantId)) {
|
|
12
|
+
onChangeMerchant === null || onChangeMerchant === void 0 ? void 0 : onChangeMerchant(merchantsIds.filter((merchant) => merchant !== merchantId));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const uniqueMids = [...new Set([...merchantsIds, merchantId])];
|
|
16
|
+
onChangeMerchant === null || onChangeMerchant === void 0 ? void 0 : onChangeMerchant(uniqueMids);
|
|
17
|
+
};
|
|
18
|
+
const isLastMidToBeDisabled = (currMid) => {
|
|
19
|
+
return merchantsIds.length === 1 && merchantsIds[0] === currMid && atLeastOneMerchantSelected;
|
|
20
|
+
};
|
|
21
|
+
const handleSearchInputChange = (value) => {
|
|
22
|
+
setSearchInputValue(value);
|
|
23
|
+
};
|
|
24
|
+
const handleSearchInputReset = () => {
|
|
25
|
+
setSearchInputValue('');
|
|
26
|
+
};
|
|
27
|
+
const merchants = useMemo(() => { var _a; return (_a = brand.merchants) !== null && _a !== void 0 ? _a : []; }, [brand.merchants]);
|
|
28
|
+
const filteredMerchants = useMemo(() => {
|
|
29
|
+
if (!(searchInputValue === null || searchInputValue === void 0 ? void 0 : searchInputValue.trim()))
|
|
30
|
+
return merchants;
|
|
31
|
+
return merchants === null || merchants === void 0 ? void 0 : merchants.filter((merchant) => { var _a; return ((_a = merchant === null || merchant === void 0 ? void 0 : merchant.display_name) !== null && _a !== void 0 ? _a : '').toLowerCase().includes(searchInputValue.trim().toLowerCase()); });
|
|
32
|
+
}, [searchInputValue, merchants]);
|
|
33
|
+
const displayedMerchants = useMemo(() => (showSearchInput ? filteredMerchants : merchants), [filteredMerchants, merchants, showSearchInput]);
|
|
34
|
+
return (_jsxs(Menu, Object.assign({ open: open, anchorEl: anchorEl, placement: "right-start" }, { children: [showSearchInput && (_jsx(SearchListInput, { placeholder: "Merchants", name: "merchants", value: searchInputValue, onSearchChange: handleSearchInputChange, onSearchReset: handleSearchInputReset, sx: { px: '8px' } })), displayedMerchants === null || displayedMerchants === void 0 ? void 0 : displayedMerchants.map((merchant) => (_jsx(MerchantMenuItemStyled, Object.assign({ isDisabled: isLastMidToBeDisabled(merchant.legacy_id), isSelected: isMerchantSelected(merchant.legacy_id), onClick: (e) => {
|
|
35
|
+
if (isLastMidToBeDisabled(merchant.legacy_id))
|
|
36
|
+
return;
|
|
37
|
+
onClickMerchant(e, merchant.legacy_id);
|
|
38
|
+
}, sx: { maxHeight: 36, minHeight: 36 } }, { children: _jsxs(MerchantWrapper, { children: [_jsx(MerchantName, Object.assign({ component: "span" }, { children: merchant.display_name })), _jsx(MerchantID, Object.assign({ component: "span" }, { children: merchant.legacy_id }))] }) }), merchant === null || merchant === void 0 ? void 0 : merchant.legacy_id)))] })));
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MenuItemProps } from '../../../MenuItem/MenuItem';
|
|
3
|
+
export declare const MerchantMenuItemStyled: import("@emotion/styled").StyledComponent<MenuItemProps & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
4
|
+
export declare const MerchantWrapper: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
5
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
6
|
+
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
7
|
+
export declare const MerchantID: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
8
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
9
|
+
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
10
|
+
export declare const MerchantName: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
11
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
12
|
+
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Box from '@mui/material/Box';
|
|
2
|
+
import { styled, alpha } from '@mui/material/styles';
|
|
3
|
+
import { MenuItem } from '../../../index.js';
|
|
4
|
+
export const MerchantMenuItemStyled = styled(MenuItem)(() => ({
|
|
5
|
+
padding: '12px 16px',
|
|
6
|
+
border: 'none !important',
|
|
7
|
+
'&:hover': { boxShadow: '0px 0px 16px 0px #00000021' },
|
|
8
|
+
}));
|
|
9
|
+
export const MerchantWrapper = styled(Box)(() => ({
|
|
10
|
+
display: 'flex',
|
|
11
|
+
flexDirection: 'column',
|
|
12
|
+
gap: '2px',
|
|
13
|
+
}));
|
|
14
|
+
export const MerchantID = styled(Box)(({ theme }) => ({
|
|
15
|
+
color: alpha(theme.palette.text.primary, 0.5),
|
|
16
|
+
fontSize: '9px',
|
|
17
|
+
}));
|
|
18
|
+
export const MerchantName = styled(Box)(() => ({
|
|
19
|
+
whiteSpace: 'nowrap',
|
|
20
|
+
overflow: 'hidden',
|
|
21
|
+
textOverflow: 'ellipsis',
|
|
22
|
+
maxWidth: '178px',
|
|
23
|
+
}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { BrandProps } from '../../type';
|
|
3
|
+
export interface MerchantItemProps {
|
|
4
|
+
brands: BrandProps[];
|
|
5
|
+
isLoading: boolean;
|
|
6
|
+
merchantsIds: string[];
|
|
7
|
+
atLeastOneMerchantSelected?: boolean;
|
|
8
|
+
showSearchInput?: boolean;
|
|
9
|
+
hideCheckbox?: boolean;
|
|
10
|
+
onFilterChange?: (value: string[]) => void;
|
|
11
|
+
renderBrandLogo: (logo: string) => React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export default function MerchantItem({ brands, isLoading, onFilterChange, merchantsIds, atLeastOneMerchantSelected, showSearchInput, hideCheckbox, renderBrandLogo, }: Readonly<MerchantItemProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useMemo } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { Menu, MenuItem, Text } from '../../../index.js';
|
|
5
|
+
import { rightArrow } from '../../../../constants/index.js';
|
|
6
|
+
import BrandItem from '../BrandItem';
|
|
7
|
+
import FlatMerchantsListMenu from '../FlatMerchantsListMenu';
|
|
8
|
+
export default function MerchantItem({ brands, isLoading, onFilterChange, merchantsIds = [], atLeastOneMerchantSelected = false, showSearchInput = false, hideCheckbox = false, renderBrandLogo, }) {
|
|
9
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
10
|
+
const open = Boolean(anchorEl);
|
|
11
|
+
const { t } = useTranslation();
|
|
12
|
+
const onOpen = (e) => {
|
|
13
|
+
setAnchorEl(e.currentTarget);
|
|
14
|
+
};
|
|
15
|
+
const onClose = () => {
|
|
16
|
+
setAnchorEl(null);
|
|
17
|
+
};
|
|
18
|
+
const isAllSelected = useMemo(() => {
|
|
19
|
+
if (!brands.length)
|
|
20
|
+
return false;
|
|
21
|
+
return brands.every((brand) => brand.merchants.every(({ legacy_id }) => merchantsIds.includes(legacy_id)));
|
|
22
|
+
}, [merchantsIds, brands, hideCheckbox]);
|
|
23
|
+
const isSomeSelected = useMemo(() => !isAllSelected && merchantsIds.length > 0, [merchantsIds, isAllSelected]);
|
|
24
|
+
// Count the number of brands that have selected merchants
|
|
25
|
+
const brandsWithSelectedMerchants = useMemo(() => {
|
|
26
|
+
return brands.filter((brand) => brand.merchants.some((merchant) => merchantsIds === null || merchantsIds === void 0 ? void 0 : merchantsIds.includes(merchant.legacy_id))).length;
|
|
27
|
+
}, [brands, merchantsIds]);
|
|
28
|
+
const onClick = () => {
|
|
29
|
+
if (atLeastOneMerchantSelected)
|
|
30
|
+
return;
|
|
31
|
+
if (isAllSelected) {
|
|
32
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange([]);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const allMerchants = brands.flatMap((brand) => brand.merchants.map(({ legacy_id }) => legacy_id));
|
|
36
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(allMerchants);
|
|
37
|
+
};
|
|
38
|
+
return (_jsxs(MenuItem, Object.assign({ isDisabled: atLeastOneMerchantSelected, isSelected: isAllSelected, hideCheckbox: hideCheckbox, isIndeterminate: isSomeSelected, sx: Object.assign(Object.assign({ maxHeight: 36, minHeight: 36, padding: '12px 8px 12px 16px' }, (open && { boxShadow: '0px 0px 16px 0px #00000021' })), ((isLoading || brands.length <= 0) && {
|
|
39
|
+
pointerEvents: 'none',
|
|
40
|
+
opacity: 0.5,
|
|
41
|
+
cursor: 'default',
|
|
42
|
+
})), onMouseEnter: onOpen, onMouseLeave: onClose, onClick: onClick }, { children: [_jsx(Text, Object.assign({ sx: { fontSize: '11px', flex: 1 } }, { children: t('merchant') })), brands.length > 0 && _jsx("img", { src: rightArrow, alt: "arrow", style: { height: 12 } }), (brands === null || brands === void 0 ? void 0 : brands.length) === 1 ? (_jsx(FlatMerchantsListMenu, { anchorEl: anchorEl, brand: brands[0], merchantsIds: merchantsIds, onChangeMerchant: onFilterChange, atLeastOneMerchantSelected: atLeastOneMerchantSelected, showSearchInput: showSearchInput })) : (_jsx(Menu, Object.assign({ open: open, anchorEl: anchorEl, placement: "right-start" }, { children: brands === null || brands === void 0 ? void 0 : brands.map((brand) => (_jsx(BrandItem, { isDisabled: brandsWithSelectedMerchants === 1 && atLeastOneMerchantSelected, brand: brand, merchantsIds: merchantsIds, onChangeMerchant: onFilterChange, atLeastOneMerchantSelected: atLeastOneMerchantSelected, showSearchInput: showSearchInput, renderBrandLogo: renderBrandLogo }, brand.id))) })))] })));
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { RetailersDestination } from 'src/types';
|
|
3
|
+
interface RetailersItemProps {
|
|
4
|
+
retailers: RetailersDestination[];
|
|
5
|
+
isLoading?: boolean;
|
|
6
|
+
retailersIds: string[];
|
|
7
|
+
onFilterChange?: (value: string[]) => void;
|
|
8
|
+
atLeastOneRetailerSelected?: boolean;
|
|
9
|
+
showSearchInput?: boolean;
|
|
10
|
+
hideCheckbox?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare function RetailersItem({ retailersIds, isLoading, retailers, onFilterChange, atLeastOneRetailerSelected, showSearchInput, hideCheckbox, }: Readonly<RetailersItemProps>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
declare const _default: import("react").MemoExoticComponent<typeof RetailersItem>;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Menu, MenuItem, Text, SearchListInput } from '../../../index.js';
|
|
3
|
+
import { rightArrow } from '../../../../constants/index.js';
|
|
4
|
+
import { memo, useCallback, useMemo, useState } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { RetailerName } from './style';
|
|
7
|
+
function RetailersItem({ retailersIds = [], isLoading, retailers = [], onFilterChange, atLeastOneRetailerSelected = false, showSearchInput = false, hideCheckbox = false, }) {
|
|
8
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
9
|
+
const open = Boolean(anchorEl);
|
|
10
|
+
const { t, i18n } = useTranslation();
|
|
11
|
+
const [searchInputValue, setSearchInputValue] = useState('');
|
|
12
|
+
const onOpen = (e) => {
|
|
13
|
+
setAnchorEl(e.currentTarget);
|
|
14
|
+
};
|
|
15
|
+
const onClose = () => {
|
|
16
|
+
setAnchorEl(null);
|
|
17
|
+
};
|
|
18
|
+
const isRetailerSelected = useCallback((retailerId) => retailersIds === null || retailersIds === void 0 ? void 0 : retailersIds.includes(retailerId), [retailersIds]);
|
|
19
|
+
const isAllSelected = useMemo(() => {
|
|
20
|
+
if (!retailers.length)
|
|
21
|
+
return false;
|
|
22
|
+
return retailers.every((retailer) => isRetailerSelected(retailer.id));
|
|
23
|
+
}, [retailers, isRetailerSelected, hideCheckbox]);
|
|
24
|
+
const isSomeSelected = useMemo(() => !isAllSelected && retailersIds.length > 0, [retailersIds, isAllSelected]);
|
|
25
|
+
const onClick = () => {
|
|
26
|
+
if (atLeastOneRetailerSelected)
|
|
27
|
+
return;
|
|
28
|
+
if (isAllSelected) {
|
|
29
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange([]);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(retailers.map((brand) => brand.id));
|
|
33
|
+
};
|
|
34
|
+
const isLastRetailerToBeDisabled = (currMid) => {
|
|
35
|
+
return retailersIds.length === 1 && retailersIds[0] === currMid && atLeastOneRetailerSelected;
|
|
36
|
+
};
|
|
37
|
+
const onClickRetailer = (e, retailerId) => {
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
if (isLastRetailerToBeDisabled(retailerId))
|
|
40
|
+
return;
|
|
41
|
+
if (isRetailerSelected(retailerId)) {
|
|
42
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(retailersIds.filter((retailer) => retailer !== retailerId));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const uniqueMids = [...new Set([...retailersIds, retailerId])];
|
|
46
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(uniqueMids);
|
|
47
|
+
};
|
|
48
|
+
const isDisabled = isLoading || (retailers === null || retailers === void 0 ? void 0 : retailers.length) <= 0 || atLeastOneRetailerSelected;
|
|
49
|
+
const handleSearchInputChange = (value) => {
|
|
50
|
+
setSearchInputValue(value);
|
|
51
|
+
};
|
|
52
|
+
const handleSearchInputReset = () => {
|
|
53
|
+
setSearchInputValue('');
|
|
54
|
+
};
|
|
55
|
+
const filteredRetailers = useMemo(() => {
|
|
56
|
+
if (!(searchInputValue === null || searchInputValue === void 0 ? void 0 : searchInputValue.trim()))
|
|
57
|
+
return retailers;
|
|
58
|
+
return retailers === null || retailers === void 0 ? void 0 : retailers.filter((retailer) => { var _a, _b, _c, _d, _e, _f; return ((_f = (_c = (_b = (_a = retailer === null || retailer === void 0 ? void 0 : retailer.brand) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b[i18n.language]) !== null && _c !== void 0 ? _c : (_e = (_d = retailer === null || retailer === void 0 ? void 0 : retailer.brand) === null || _d === void 0 ? void 0 : _d.name) === null || _e === void 0 ? void 0 : _e.en) !== null && _f !== void 0 ? _f : '').toLowerCase().includes(searchInputValue.trim().toLowerCase()); });
|
|
59
|
+
}, [searchInputValue, retailers, i18n.language]);
|
|
60
|
+
const displayedRetailers = useMemo(() => (showSearchInput ? filteredRetailers : retailers), [filteredRetailers, retailers, showSearchInput]);
|
|
61
|
+
return (_jsxs(MenuItem, Object.assign({ isDisabled: isDisabled,
|
|
62
|
+
// TODO: the checkbox ui should be controlled using a state not through the isAllSelected variable
|
|
63
|
+
isSelected: isAllSelected, hideCheckbox: hideCheckbox, isIndeterminate: isSomeSelected, sx: Object.assign(Object.assign({ maxHeight: 35, minHeight: 35, padding: '12px 8px 12px 16px' }, (open && { boxShadow: '0px 0px 16px 0px #00000021' })), (!(retailers === null || retailers === void 0 ? void 0 : retailers.length) && { opacity: 0.5, pointerEvents: 'none' })), onMouseEnter: onOpen, onMouseLeave: onClose, onClick: onClick }, { children: [_jsx(Text, Object.assign({ sx: { fontSize: '11px', flex: 1 } }, { children: t('retailers') })), (retailers === null || retailers === void 0 ? void 0 : retailers.length) > 0 && _jsx("img", { src: rightArrow, alt: "arrow", style: { height: 12 } }), _jsxs(Menu, Object.assign({ open: open, anchorEl: anchorEl, placement: "right-start", sx: { height: 300, width: 200, overflow: 'auto' } }, { children: [showSearchInput && (_jsx(SearchListInput, { placeholder: "Retailers", name: "retailers", value: searchInputValue, onSearchChange: handleSearchInputChange, onSearchReset: handleSearchInputReset, sx: { px: '8px' } })), displayedRetailers === null || displayedRetailers === void 0 ? void 0 : displayedRetailers.map((retailer, index) => {
|
|
64
|
+
var _a, _b, _c, _d, _e;
|
|
65
|
+
return (_jsx(MenuItem, Object.assign({ isSelected: isRetailerSelected(retailer.id), isDisabled: isLoading || isLastRetailerToBeDisabled(retailer.id), onClick: (e) => {
|
|
66
|
+
onClickRetailer(e, retailer.id);
|
|
67
|
+
}, sx: { maxHeight: 35, minHeight: 35 } }, { children: _jsx(RetailerName, { children: (_c = (_b = (_a = retailer === null || retailer === void 0 ? void 0 : retailer.brand) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b[i18n.language]) !== null && _c !== void 0 ? _c : (_e = (_d = retailer === null || retailer === void 0 ? void 0 : retailer.brand) === null || _d === void 0 ? void 0 : _d.name) === null || _e === void 0 ? void 0 : _e.en }) }), `key-${retailer === null || retailer === void 0 ? void 0 : retailer.id}-${index}`));
|
|
68
|
+
})] }))] })));
|
|
69
|
+
}
|
|
70
|
+
export default memo(RetailersItem);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './RetailersItem';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './RetailersItem';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const RetailerName: 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>, {}, {}>;
|