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

@@ -21,6 +21,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 PayableExportAll({
bodyshop,
currentUser,
@@ -97,7 +110,7 @@ export function PayableExportAll({
proms.push(
(async () => {
const failedTransactions = groupedData[key].filter((r) => !r.success);
const successfulTransactions = PartnerResponse.data.filter(
const successfulTransactions = groupedData[key].filter(
(r) => r.success
);
if (failedTransactions.length > 0) {
@@ -159,31 +172,6 @@ export function PayableExportAll({
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({
@@ -191,6 +179,11 @@ export function PayableExportAll({
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", {
@@ -205,29 +198,19 @@ export function PayableExportAll({
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"
]
)
),
]);
}
}
})()