IO-2368 Update Cache on success

This commit is contained in:
Allan Carr
2023-09-07 17:21:21 -07:00
parent 7a1984d037
commit d1407162d9
6 changed files with 256 additions and 17 deletions

View File

@@ -14,6 +14,7 @@ import {
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
import client from "../../utils/GraphQLClient";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
@@ -96,7 +97,9 @@ export function PayableExportAll({
proms.push(
(async () => {
const failedTransactions = groupedData[key].filter((r) => !r.success);
const successfulTransactions = PartnerResponse.data.filter(
(r) => r.success
);
if (failedTransactions.length > 0) {
//Uh oh. At least one was no good.
failedTransactions.map((ft) =>
@@ -142,7 +145,15 @@ export function PayableExportAll({
const billUpdateResponse = await updateBill({
variables: {
billIdList: [key],
billIdList: successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig &&
bodyshop.accountingconfig.qbo
? "billid"
: "id"
]
),
bill: {
exported: true,
exported_at: new Date(),
@@ -154,7 +165,20 @@ export function PayableExportAll({
fields: {
bills(existingJobs = []) {
return existingJobs.filter(
(billRef) => billRef.__ref.includes([key]) === false
(billRef) =>
billRef.__ref.includes([
...new Set(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig &&
bodyshop.accountingconfig.qbo
? "billid"
: "id"
]
)
),
]) === false
);
},
},
@@ -181,6 +205,29 @@ 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
);
},
},
});
}
}
})()
@@ -190,7 +237,6 @@ export function PayableExportAll({
await Promise.all(proms);
if (!!completedCallback) completedCallback([]);
if (!!loadingCallback) loadingCallback(false);
if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
setLoading(false);
};