IO-2368 Move Cache update to function and just pass in keys array
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user