fix: reload table when customer added

This commit is contained in:
Rafael Taranto 2025-05-29 16:10:08 +01:00
parent e8deff7a88
commit 8700ebcbe1
2 changed files with 6 additions and 13 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: customerLoading } =
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)]),

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,