From 8700ebcbe10dec3e370b1c0e477e61b134816e64 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 29 May 2025 16:10:08 +0100 Subject: [PATCH] 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,