From 8700ebcbe10dec3e370b1c0e477e61b134816e64 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 29 May 2025 16:10:08 +0100 Subject: [PATCH 1/2] fix: reload table when customer added --- .../admin-ui/src/pages/Customers/Customers.jsx | 17 +++++------------ .../src/pages/Customers/CustomersList.jsx | 2 +- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/admin-ui/src/pages/Customers/Customers.jsx b/packages/admin-ui/src/pages/Customers/Customers.jsx index a1f0e547..8f5d8446 100644 --- a/packages/admin-ui/src/pages/Customers/Customers.jsx +++ b/packages/admin-ui/src/pages/Customers/Customers.jsx @@ -86,23 +86,14 @@ const Customers = () => { const handleCustomerClicked = customer => navigate(`/compliance/customer/${customer.id}`) - const [customers, setCustomers] = useState([]) const [showCreationModal, setShowCreationModal] = useState(false) - const { data: customersResponse, loading: customerLoading } = useQuery( - GET_CUSTOMERS, - { - onCompleted: data => setCustomers(R.path(['customers'])(data)), - }, - ) + const { data: customersResponse, loading: customerLoading } = + useQuery(GET_CUSTOMERS) const [createNewCustomer] = useMutation(CREATE_CUSTOMER, { onCompleted: () => setShowCreationModal(false), - refetchQueries: () => [ - { - query: GET_CUSTOMERS, - }, - ], + refetchQueries: () => [GET_CUSTOMERS], }) const configData = R.path(['config'])(customersResponse) ?? [] @@ -120,6 +111,8 @@ const Customers = () => { const byAuthorized = c => (c.authorizedStatus.label === 'Pending' ? 0 : 1) const byLastActive = c => new Date(R.prop('lastActive', c) ?? '0') + + const customers = R.path(['customers'])(customersResponse) ?? [] const customersData = R.pipe( R.map(setAuthorizedStatus), R.sortWith([R.ascend(byAuthorized), R.descend(byLastActive)]), diff --git a/packages/admin-ui/src/pages/Customers/CustomersList.jsx b/packages/admin-ui/src/pages/Customers/CustomersList.jsx index 809db5cb..acacfd67 100644 --- a/packages/admin-ui/src/pages/Customers/CustomersList.jsx +++ b/packages/admin-ui/src/pages/Customers/CustomersList.jsx @@ -109,7 +109,7 @@ const CustomersList = ({ data, country, onClick, loading }) => { const table = useMaterialReactTable({ ...defaultMaterialTableOpts, - columns: columns, + columns, data, initialState: { ...defaultMaterialTableOpts.initialState, From d00743446bebbc477678a06a33c0325d83351467 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 5 Jun 2025 10:15:28 +0100 Subject: [PATCH 2/2] chore: small PR fixes --- packages/admin-ui/src/pages/Customers/Customers.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/admin-ui/src/pages/Customers/Customers.jsx b/packages/admin-ui/src/pages/Customers/Customers.jsx index 8f5d8446..f7528976 100644 --- a/packages/admin-ui/src/pages/Customers/Customers.jsx +++ b/packages/admin-ui/src/pages/Customers/Customers.jsx @@ -88,7 +88,7 @@ const Customers = () => { const [showCreationModal, setShowCreationModal] = useState(false) - const { data: customersResponse, loading: customerLoading } = + const { data: customersResponse, loading: customersLoading } = useQuery(GET_CUSTOMERS) const [createNewCustomer] = useMutation(CREATE_CUSTOMER, { @@ -112,7 +112,7 @@ const Customers = () => { const byAuthorized = c => (c.authorizedStatus.label === 'Pending' ? 0 : 1) const byLastActive = c => new Date(R.prop('lastActive', c) ?? '0') - const customers = R.path(['customers'])(customersResponse) ?? [] + const customers = R.path(['customers'])(customersResponse) const customersData = R.pipe( R.map(setAuthorizedStatus), R.sortWith([R.ascend(byAuthorized), R.descend(byLastActive)]), @@ -138,7 +138,7 @@ const Customers = () => { data={customersData} country={locale?.country} onClick={handleCustomerClicked} - loading={customerLoading} + loading={customersLoading} />