IO-2368 Move Cache update to function and just pass in keys array

This commit is contained in:
Allan Carr
2023-09-08 10:17:42 -07:00
parent d1407162d9
commit 87e3adf579
6 changed files with 185 additions and 291 deletions

View File

@@ -20,6 +20,19 @@ const mapStateToProps = createStructuredSelector({
currentUser: selectCurrentUser,
});
function updateBillCache(items) {
client.cache.modify({
id: "ROOT_QUERY",
fields: {
bills(existingJobs = []) {
return existingJobs.filter(
(billRef) => billRef.__ref.includes(items) === false
);
},
},
});
}
export function PayableExportButton({
bodyshop,
currentUser,
@@ -152,31 +165,6 @@ export function PayableExportButton({
exported_at: new Date(),
},
},
update(cache) {
cache.modify({
id: "ROOT_QUERY",
fields: {
bills(existingJobs = []) {
return existingJobs.filter(
(billRef) =>
billRef.__ref.includes([
...new Set(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig &&
bodyshop.accountingconfig.qbo
? "billid"
: "id"
]
)
),
]) === false
);
},
},
});
},
});
if (!!!billUpdateResponse.errors) {
notification.open({
@@ -184,6 +172,11 @@ export function PayableExportButton({
key: "billsuccessexport",
message: t("bills.successes.exported"),
});
updateBillCache(
billUpdateResponse.data.update_bills.returning.map(
(bill) => bill.id
)
);
} else {
notification["error"]({
message: t("bills.errors.exporting", {
@@ -198,29 +191,18 @@ export function PayableExportButton({
key: "billsuccessexport",
message: t("bills.successes.exported"),
});
client.cache.modify({
id: "ROOT_QUERY",
fields: {
bills(existingJobs = []) {
return existingJobs.filter(
(billRef) =>
billRef.__ref.includes([
...new Set(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig &&
bodyshop.accountingconfig.qbo
? "billid"
: "id"
]
)
),
]) === false
);
},
},
});
updateBillCache([
...new Set(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig && bodyshop.accountingconfig.qbo
? "billid"
: "id"
]
)
),
]);
}
if (setSelectedBills) {