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 updatePaymentCache(items) {
client.cache.modify({
id: "ROOT_QUERY",
fields: {
payments(existingJobs = []) {
return existingJobs.filter(
(paymentRef) => paymentRef.__ref.includes(items) === false
);
},
},
});
}
export function PaymentExportButton({
bodyshop,
currentUser,
@@ -151,31 +164,6 @@ export function PaymentExportButton({
exportedat: new Date(),
},
},
update(cache) {
cache.modify({
id: "ROOT_QUERY",
fields: {
payments(existingJobs = []) {
return existingJobs.filter(
(paymentRef) =>
paymentRef.__ref.includes([
...new Set(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig &&
bodyshop.accountingconfig.qbo
? "paymentid"
: "id"
]
)
),
]) === false
);
},
},
});
},
});
if (!!!paymentUpdateResponse.errors) {
notification.open({
@@ -183,6 +171,11 @@ export function PaymentExportButton({
key: "paymentsuccessexport",
message: t("payments.successes.exported"),
});
updatePaymentCache(
paymentUpdateResponse.data.update_payments.returning.map(
(payment) => payment.id
)
);
} else {
notification["error"]({
message: t("payments.errors.exporting", {
@@ -204,29 +197,18 @@ export function PaymentExportButton({
key: "paymentsuccessexport",
message: t("payments.successes.exported"),
});
client.cache.modify({
id: "ROOT_QUERY",
fields: {
payments(existingJobs = []) {
return existingJobs.filter(
(paymentRef) =>
paymentRef.__ref.includes([
...new Set(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig &&
bodyshop.accountingconfig.qbo
? "paymentid"
: "id"
]
)
),
]) === false
);
},
},
});
updatePaymentCache([
...new Set(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig && bodyshop.accountingconfig.qbo
? "paymentid"
: "id"
]
)
),
]);
}
if (!!loadingCallback) loadingCallback(false);
setLoading(false);