@tap-payments/auth-jsconnect 2.1.34-test → 2.1.35-test

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.
@@ -31,15 +31,16 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
31
31
  };
32
32
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
33
33
  import * as React from 'react';
34
+ import { useTranslation } from 'react-i18next';
35
+ import { useController, useFormContext } from 'react-hook-form';
34
36
  import Box from '@mui/material/Box';
35
37
  import { alpha, styled } from '@mui/material/styles';
36
38
  import InfoIcon from '@mui/icons-material/Info';
37
39
  import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
40
+ import { sortActivitiesByName } from '../../../../utils';
38
41
  import Text from '../../../../components/Text';
39
42
  import Input from '../../../../components/Input';
40
43
  import Tooltip from '../../../../components/Tooltip';
41
- import { useTranslation } from 'react-i18next';
42
- import { useController, useFormContext } from 'react-hook-form';
43
44
  import { useLanguage, useAppSelector } from '../../../../hooks';
44
45
  import { BusinessType } from '../../../../@types';
45
46
  import Collapse from '../../../../components/Collapse';
@@ -49,7 +50,6 @@ import { ScreenContainer } from '../../../shared/Containers';
49
50
  import { businessSelector } from '../../../app/business/businessStore';
50
51
  import CheckIcon from '@mui/icons-material/Check';
51
52
  import { MandatoryStyled } from './OperationStartDate';
52
- import Search from '../../../../features/shared/Search';
53
53
  export var InputLabelStyled = styled(Text)(function (_a) {
54
54
  var theme = _a.theme;
55
55
  return (__assign({ color: alpha(theme.palette.text.primary, 0.4) }, theme.typography.caption));
@@ -120,7 +120,9 @@ var ActivitiesList = function (_a) {
120
120
  var isCR = businessType === BusinessType.CR;
121
121
  React.useEffect(function () {
122
122
  if ((activities === null || activities === void 0 ? void 0 : activities.length) > 0) {
123
- setActivitiesMenuList(activities);
123
+ var list = __spreadArray([], activities, true);
124
+ var sortedList = sortActivitiesByName(list, isAr ? 'name.ar' : 'name.en');
125
+ setActivitiesMenuList(sortedList);
124
126
  }
125
127
  }, [activities]);
126
128
  var onOpenList = function (event) {
@@ -154,17 +156,9 @@ var ActivitiesList = function (_a) {
154
156
  var getSelectedActivityFlag = function (item) {
155
157
  return controlValue === null || controlValue === void 0 ? void 0 : controlValue.find(function (activity) { return activity.id === item.id; });
156
158
  };
157
- var handleSearch = function (value) {
158
- var filteredList = activities === null || activities === void 0 ? void 0 : activities.filter(function (activity) {
159
- var _a, _b, _c, _d;
160
- return ((_b = (_a = activity === null || activity === void 0 ? void 0 : activity.name) === null || _a === void 0 ? void 0 : _a.en) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(value.toLowerCase())) ||
161
- ((_d = (_c = activity === null || activity === void 0 ? void 0 : activity.name) === null || _c === void 0 ? void 0 : _c.ar) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes(value.toLowerCase()));
162
- });
163
- setActivitiesMenuList(filteredList);
164
- };
165
- return (_jsxs(ScreenContainer, { children: [_jsxs(LabelContainerStyled, { children: [_jsxs(InputLabelStyled, { children: [t(isCR ? 'activities' : 'category'), " ", _jsx(MandatoryStyled, { children: "*" })] }), _jsx(Tooltip, __assign({ title: t('activities_name_hint'), onMouseOver: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); }, onTouchStartCapture: function () { return setIsHovered(true); } }, { children: isHovered ? _jsx(InfoIconStyled, {}) : _jsx(InfoOutlinedIconStyled, {}) }))] }), _jsxs(Box, { children: [_jsx(InputStyled, { readOnly: true, value: getSelectedActivities(), placeholder: isCR ? t('choose_activities') : t('category_name'), onClick: !!anchorEl ? function () { return onCloseList(); } : onOpenList, endAdornment: _jsx(ExpandIcon, { anchorEl: !!anchorEl }) }), _jsxs(Collapse, __assign({ in: !!anchorEl, timeout: 300 }, { children: [_jsx(Search, { onSearchValue: handleSearch }), _jsx(SimpleListStyled, { searchKeyPath: 'name', list: activitiesMenuList, onSelectItem: onSelectItem, renderItem: function (item) {
166
- var _a, _b, _c;
167
- return (_jsxs(_Fragment, { children: [_jsx(Box, __assign({ display: 'flex' }, { children: _jsx(NameContainer, __assign({ isSelected: item.id === ((_a = getSelectedActivityFlag(item)) === null || _a === void 0 ? void 0 : _a.id) }, { children: isAr ? (_b = item === null || item === void 0 ? void 0 : item.name) === null || _b === void 0 ? void 0 : _b.ar : (_c = item === null || item === void 0 ? void 0 : item.name) === null || _c === void 0 ? void 0 : _c.en })) })), getSelectedActivityFlag(item) && _jsx(CheckIconStyled, {})] }));
168
- } })] }))] })] }));
159
+ return (_jsxs(ScreenContainer, { children: [_jsxs(LabelContainerStyled, { children: [_jsxs(InputLabelStyled, { children: [t(isCR ? 'activities' : 'category'), " ", _jsx(MandatoryStyled, { children: "*" })] }), _jsx(Tooltip, __assign({ title: t('activities_name_hint'), onMouseOver: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); }, onTouchStartCapture: function () { return setIsHovered(true); } }, { children: isHovered ? _jsx(InfoIconStyled, {}) : _jsx(InfoOutlinedIconStyled, {}) }))] }), _jsxs(Box, { children: [_jsx(InputStyled, { readOnly: true, value: getSelectedActivities() || '', placeholder: isCR ? t('choose_activities') : t('category_name'), onClick: !!anchorEl ? function () { return onCloseList(); } : onOpenList, endAdornment: _jsx(ExpandIcon, { anchorEl: !!anchorEl }) }), _jsx(Collapse, __assign({ in: !!anchorEl, timeout: 300 }, { children: _jsx(SimpleListStyled, { searchKeyPath: 'name.en', searchValuePath: isAr ? 'name.er' : 'name.en', list: activitiesMenuList, onSelectItem: onSelectItem, renderItem: function (item) {
160
+ var _a, _b, _c;
161
+ return (_jsxs(_Fragment, { children: [_jsx(Box, __assign({ display: 'flex' }, { children: _jsx(NameContainer, __assign({ isSelected: item.id === ((_a = getSelectedActivityFlag(item)) === null || _a === void 0 ? void 0 : _a.id) }, { children: isAr ? (_b = item === null || item === void 0 ? void 0 : item.name) === null || _b === void 0 ? void 0 : _b.ar : (_c = item === null || item === void 0 ? void 0 : item.name) === null || _c === void 0 ? void 0 : _c.en })) })), getSelectedActivityFlag(item) && _jsx(CheckIconStyled, {})] }));
162
+ } }) }))] })] }));
169
163
  };
170
164
  export default ActivitiesList;
@@ -40,6 +40,7 @@ import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
40
40
  import CheckIcon from '@mui/icons-material/Check';
41
41
  import { useLanguage, useAppSelector } from '../../../../hooks';
42
42
  import { BusinessType, FieldType } from '../../../../@types';
43
+ import { sortActivitiesByName } from '../../../../utils';
43
44
  import Text from '../../../../components/Text';
44
45
  import Input from '../../../../components/Input';
45
46
  import Tooltip from '../../../../components/Tooltip';
@@ -48,7 +49,6 @@ import SimpleList from '../../../../components/SimpleList';
48
49
  import ExpandIcon from '../../../../components/ExpandIcon';
49
50
  import { ScreenContainer } from '../../../shared/Containers';
50
51
  import { entitySelector } from '../../../app/entity/entityStore';
51
- import Search from '../../../shared/Search';
52
52
  export var InputLabelStyled = styled(Text)(function (_a) {
53
53
  var theme = _a.theme;
54
54
  return (__assign({ color: alpha(theme.palette.text.primary, 0.4) }, theme.typography.caption));
@@ -121,19 +121,21 @@ var ActivitiesList = function (_a) {
121
121
  var disabled = ((_c = entity === null || entity === void 0 ? void 0 : entity.data_status) === null || _c === void 0 ? void 0 : _c.activities) === FieldType.NON_EDITABLE;
122
122
  React.useEffect(function () {
123
123
  if ((activityList === null || activityList === void 0 ? void 0 : activityList.length) > 0) {
124
- var sortedList = (activityList || [])
125
- .map(function (activity) { return activity; })
126
- .sort(function (a, b) { var _a, _b, _c, _d, _e; return (_c = (_b = (_a = a === null || a === void 0 ? void 0 : a.name) === null || _a === void 0 ? void 0 : _a.en) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === null || _c === void 0 ? void 0 : _c.localeCompare((_e = (_d = b === null || b === void 0 ? void 0 : b.name) === null || _d === void 0 ? void 0 : _d.en) === null || _e === void 0 ? void 0 : _e.toLowerCase()); });
127
- setActivitiesMenuList(sortedList);
124
+ var list = __spreadArray([], activityList, true);
125
+ var sortedList = sortActivitiesByName(list, isAr ? 'name.ar' : 'name.en');
126
+ var mapSelectedListFirst = __spreadArray(__spreadArray([], sortedList.filter(function (a) { return (controlValue || []).some(function (c) { return a.id === c.id; }); }), true), sortedList.filter(function (a) { return !(controlValue || []).some(function (c) { return a.id === c.id; }); }), true);
127
+ setActivitiesMenuList(mapSelectedListFirst);
128
128
  }
129
129
  }, [activityList]);
130
130
  var onOpenList = function (event) {
131
- var _a;
132
- setAnchorEl(event.currentTarget);
133
- (_a = rest.onListOpen) === null || _a === void 0 ? void 0 : _a.call(rest);
134
- if ((activitiesMenuList === null || activitiesMenuList === void 0 ? void 0 : activitiesMenuList.length) !== (activityList === null || activityList === void 0 ? void 0 : activityList.length)) {
135
- handleSearch('');
131
+ var _a, _b;
132
+ if ((controlValue === null || controlValue === void 0 ? void 0 : controlValue.length) > ((_a = entity === null || entity === void 0 ? void 0 : entity.activities) === null || _a === void 0 ? void 0 : _a.length)) {
133
+ var list = __spreadArray([], activitiesMenuList, true);
134
+ var mapSelectedListFirst = __spreadArray(__spreadArray([], list.filter(function (a) { return (controlValue || []).some(function (c) { return a.id === c.id; }); }), true), list.filter(function (a) { return !(controlValue || []).some(function (c) { return a.id === c.id; }); }), true);
135
+ setActivitiesMenuList(mapSelectedListFirst);
136
136
  }
137
+ setAnchorEl(event.currentTarget);
138
+ (_b = rest.onListOpen) === null || _b === void 0 ? void 0 : _b.call(rest);
137
139
  };
138
140
  var onCloseList = function () {
139
141
  var _a;
@@ -165,17 +167,9 @@ var ActivitiesList = function (_a) {
165
167
  var getSelectedActivityFlag = function (item) {
166
168
  return controlValue === null || controlValue === void 0 ? void 0 : controlValue.find(function (activity) { return activity.id === item.id; });
167
169
  };
168
- var handleSearch = function (value) {
169
- var filteredList = activityList === null || activityList === void 0 ? void 0 : activityList.filter(function (activity) {
170
- var _a, _b, _c, _d;
171
- return ((_b = (_a = activity === null || activity === void 0 ? void 0 : activity.name) === null || _a === void 0 ? void 0 : _a.en) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(value.toLowerCase())) ||
172
- ((_d = (_c = activity === null || activity === void 0 ? void 0 : activity.name) === null || _c === void 0 ? void 0 : _c.ar) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes(value.toLowerCase()));
173
- }).sort(function (a, b) { var _a, _b, _c, _d, _e; return (_c = (_b = (_a = a === null || a === void 0 ? void 0 : a.name) === null || _a === void 0 ? void 0 : _a.en) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === null || _c === void 0 ? void 0 : _c.localeCompare((_e = (_d = b === null || b === void 0 ? void 0 : b.name) === null || _d === void 0 ? void 0 : _d.en) === null || _e === void 0 ? void 0 : _e.toLowerCase()); });
174
- setActivitiesMenuList(filteredList);
175
- };
176
- return (_jsxs(ScreenContainer, { children: [_jsxs(LabelContainerStyled, { children: [_jsx(InputLabelStyled, { children: t(isCR ? 'activities' : 'category') }), _jsx(Tooltip, __assign({ title: t('activities_name_hint'), onMouseOver: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); }, onTouchStartCapture: function () { return setIsHovered(true); } }, { children: isHovered ? _jsx(InfoIconStyled, {}) : _jsx(InfoOutlinedIconStyled, {}) }))] }), _jsxs(Box, { children: [_jsx(InputStyled, { readOnly: true, disabled: disabled, value: getSelectedActivities() || '', placeholder: isCR ? t('choose_activities') : t('category_name'), onClick: disabled ? undefined : !!anchorEl ? function () { return onCloseList(); } : onOpenList, endAdornment: disabled ? _jsx(_Fragment, {}) : _jsx(ExpandIcon, { anchorEl: !!anchorEl }) }), _jsxs(Collapse, __assign({ in: !!anchorEl, timeout: 300 }, { children: [_jsx(Search, { onSearchValue: handleSearch }), _jsx(SimpleListStyled, { searchKeyPath: 'name.en', list: activitiesMenuList, onSelectItem: onSelectItem, renderItem: function (item) {
177
- var _a, _b, _c;
178
- return (_jsxs(_Fragment, { children: [_jsx(Box, __assign({ display: 'flex' }, { children: _jsx(NameContainer, __assign({ isSelected: item.id === ((_a = getSelectedActivityFlag(item)) === null || _a === void 0 ? void 0 : _a.id) }, { children: isAr ? (_b = item === null || item === void 0 ? void 0 : item.name) === null || _b === void 0 ? void 0 : _b.ar : (_c = item === null || item === void 0 ? void 0 : item.name) === null || _c === void 0 ? void 0 : _c.en })) })), getSelectedActivityFlag(item) && _jsx(CheckIconStyled, {})] }));
179
- } })] }))] })] }));
170
+ return (_jsxs(ScreenContainer, { children: [_jsxs(LabelContainerStyled, { children: [_jsx(InputLabelStyled, { children: t(isCR ? 'activities' : 'category') }), _jsx(Tooltip, __assign({ title: t('activities_name_hint'), onMouseOver: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); }, onTouchStartCapture: function () { return setIsHovered(true); } }, { children: isHovered ? _jsx(InfoIconStyled, {}) : _jsx(InfoOutlinedIconStyled, {}) }))] }), _jsxs(Box, { children: [_jsx(InputStyled, { readOnly: true, disabled: disabled, value: getSelectedActivities() || '', placeholder: isCR ? t('choose_activities') : t('category_name'), onClick: disabled ? undefined : !!anchorEl ? function () { return onCloseList(); } : onOpenList, endAdornment: disabled ? _jsx(_Fragment, {}) : _jsx(ExpandIcon, { anchorEl: !!anchorEl }) }), _jsx(Collapse, __assign({ in: !!anchorEl, timeout: 300 }, { children: _jsx(SimpleListStyled, { searchKeyPath: 'name.en', searchValuePath: isAr ? 'name.er' : 'name.en', list: activitiesMenuList, onSelectItem: onSelectItem, renderItem: function (item) {
171
+ var _a, _b, _c;
172
+ return (_jsxs(_Fragment, { children: [_jsx(Box, __assign({ display: 'flex' }, { children: _jsx(NameContainer, __assign({ isSelected: item.id === ((_a = getSelectedActivityFlag(item)) === null || _a === void 0 ? void 0 : _a.id) }, { children: isAr ? (_b = item === null || item === void 0 ? void 0 : item.name) === null || _b === void 0 ? void 0 : _b.ar : (_c = item === null || item === void 0 ? void 0 : item.name) === null || _c === void 0 ? void 0 : _c.en })) })), getSelectedActivityFlag(item) && _jsx(CheckIconStyled, {})] }));
173
+ } }) }))] })] }));
180
174
  };
181
175
  export default ActivitiesList;
@@ -1,4 +1,4 @@
1
- import { CountryCode, SaleChannel } from '../@types';
1
+ import { Activity, CountryCode, SaleChannel } from '../@types';
2
2
  export declare const isArray: (value: any) => value is any[];
3
3
  export declare const joinArray: (items: Array<any>, joiner?: string) => string;
4
4
  export declare const replaceStringArrayItems: (items: Array<string>, include: string, withThis: string) => string[];
@@ -61,3 +61,4 @@ export declare const fixBrandList: (items: Array<{
61
61
  channel_services: any[];
62
62
  }[];
63
63
  export declare const findFirstId: (items: Array<SaleChannel>) => string;
64
+ export declare const sortActivitiesByName: (items: Array<Activity>, path: string) => Activity[];
@@ -9,6 +9,7 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ import get from 'lodash-es/get';
12
13
  export var isArray = function (value) { return Array.isArray(value); };
13
14
  export var joinArray = function (items, joiner) {
14
15
  if (joiner === void 0) { joiner = '__'; }
@@ -138,3 +139,8 @@ export var findFirstId = function (items) {
138
139
  return first.sub[0].id;
139
140
  return first.id;
140
141
  };
142
+ export var sortActivitiesByName = function (items, path) {
143
+ return (items || []).sort(function (a, b) {
144
+ return get(a, path).trim().toLowerCase().localeCompare(get(b, path).trim().toLowerCase().trim().toLowerCase());
145
+ });
146
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/auth-jsconnect",
3
- "version": "2.1.34-test",
3
+ "version": "2.1.35-test",
4
4
  "description": "connect library, auth",
5
5
  "private": false,
6
6
  "main": "build/index.js",