From 1acc8ad65b5ad2c847c426da7522e3f24ad2fc50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Fri, 23 Sep 2022 17:24:38 +0100 Subject: [PATCH 1/2] feat: sort customers by status, pending first --- .../src/pages/Customers/Customers.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/new-lamassu-admin/src/pages/Customers/Customers.js b/new-lamassu-admin/src/pages/Customers/Customers.js index a5bed041..ed8c8ae6 100644 --- a/new-lamassu-admin/src/pages/Customers/Customers.js +++ b/new-lamassu-admin/src/pages/Customers/Customers.js @@ -16,6 +16,7 @@ import { fromNamespace, namespaces } from 'src/utils/config' import CustomersList from './CustomersList' import CreateCustomerModal from './components/CreateCustomerModal' +import { getAuthorizedStatus } from './helper' const GET_CUSTOMER_FILTERS = gql` query filters { @@ -130,9 +131,20 @@ const Customers = () => { R.path(['customInfoRequests'], customersResponse) ?? [] const locale = configData && fromNamespace(namespaces.LOCALE, configData) const triggers = configData && fromNamespace(namespaces.TRIGGERS, configData) - const customersData = R.sortWith([ - R.descend(it => new Date(R.prop('lastActive', it) ?? '0')) - ])(filteredCustomers ?? []) + + const setAuthorizedStatus = c => + R.assoc( + 'authorizedStatus', + getAuthorizedStatus(c, triggers, customRequirementsData), + c + ) + + const byAuthorized = c => (c.authorizedStatus.label === 'Pending' ? 0 : 1) + const byLastActive = c => new Date(R.prop('lastActive', c) ?? '0') + const customersData = R.pipe( + R.map(setAuthorizedStatus), + R.sortWith([R.ascend(byAuthorized), R.descend(byLastActive)]) + )(filteredCustomers ?? []) const onFilterChange = filters => { const filtersObject = getFiltersObj(filters) From d5d969a5ea596577a12e0ec2744e162653b01b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Fri, 23 Sep 2022 17:25:41 +0100 Subject: [PATCH 2/2] refactor: don't recompute customer status --- new-lamassu-admin/src/pages/Customers/CustomersList.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/new-lamassu-admin/src/pages/Customers/CustomersList.js b/new-lamassu-admin/src/pages/Customers/CustomersList.js index e4d41e7a..9e01fd0a 100644 --- a/new-lamassu-admin/src/pages/Customers/CustomersList.js +++ b/new-lamassu-admin/src/pages/Customers/CustomersList.js @@ -9,7 +9,7 @@ import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in. import { ReactComponent as TxOutIcon } from 'src/styling/icons/direction/cash-out.svg' import styles from './CustomersList.styles' -import { getAuthorizedStatus, getFormattedPhone, getName } from './helper' +import { getFormattedPhone, getName } from './helper' const useStyles = makeStyles(styles) @@ -73,11 +73,7 @@ const CustomersList = ({ { header: 'Status', width: 191, - view: it => ( - - ) + view: it => } ]