Merge pull request #1875 from RafaelTaranto/fix/customer-page-fixes

LAM-1442 fix: reload table when customer added
This commit is contained in:
Rafael Taranto 2025-06-05 10:16:40 +01:00 committed by GitHub
commit 305cbea6c9
2 changed files with 7 additions and 14 deletions

View file

@ -86,23 +86,14 @@ const Customers = () => {
const handleCustomerClicked = customer => const handleCustomerClicked = customer =>
navigate(`/compliance/customer/${customer.id}`) navigate(`/compliance/customer/${customer.id}`)
const [customers, setCustomers] = useState([])
const [showCreationModal, setShowCreationModal] = useState(false) const [showCreationModal, setShowCreationModal] = useState(false)
const { data: customersResponse, loading: customerLoading } = useQuery( const { data: customersResponse, loading: customersLoading } =
GET_CUSTOMERS, useQuery(GET_CUSTOMERS)
{
onCompleted: data => setCustomers(R.path(['customers'])(data)),
},
)
const [createNewCustomer] = useMutation(CREATE_CUSTOMER, { const [createNewCustomer] = useMutation(CREATE_CUSTOMER, {
onCompleted: () => setShowCreationModal(false), onCompleted: () => setShowCreationModal(false),
refetchQueries: () => [ refetchQueries: () => [GET_CUSTOMERS],
{
query: GET_CUSTOMERS,
},
],
}) })
const configData = R.path(['config'])(customersResponse) ?? [] const configData = R.path(['config'])(customersResponse) ?? []
@ -120,6 +111,8 @@ const Customers = () => {
const byAuthorized = c => (c.authorizedStatus.label === 'Pending' ? 0 : 1) const byAuthorized = c => (c.authorizedStatus.label === 'Pending' ? 0 : 1)
const byLastActive = c => new Date(R.prop('lastActive', c) ?? '0') const byLastActive = c => new Date(R.prop('lastActive', c) ?? '0')
const customers = R.path(['customers'])(customersResponse)
const customersData = R.pipe( const customersData = R.pipe(
R.map(setAuthorizedStatus), R.map(setAuthorizedStatus),
R.sortWith([R.ascend(byAuthorized), R.descend(byLastActive)]), R.sortWith([R.ascend(byAuthorized), R.descend(byLastActive)]),
@ -145,7 +138,7 @@ const Customers = () => {
data={customersData} data={customersData}
country={locale?.country} country={locale?.country}
onClick={handleCustomerClicked} onClick={handleCustomerClicked}
loading={customerLoading} loading={customersLoading}
/> />
<CreateCustomerModal <CreateCustomerModal
showModal={showCreationModal} showModal={showCreationModal}

View file

@ -109,7 +109,7 @@ const CustomersList = ({ data, country, onClick, loading }) => {
const table = useMaterialReactTable({ const table = useMaterialReactTable({
...defaultMaterialTableOpts, ...defaultMaterialTableOpts,
columns: columns, columns,
data, data,
initialState: { initialState: {
...defaultMaterialTableOpts.initialState, ...defaultMaterialTableOpts.initialState,