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

@@ -13,6 +13,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 JobsExportAllButton({
Object.keys(groupedData).map(async (key) => {
//Check to see if any of them failed. If they didn't don't execute the update.
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.forEach((ft) => {
@@ -159,7 +162,20 @@ export function JobsExportAllButton({
fields: {
jobs(existingJobs = []) {
return existingJobs.filter(
(jobRef) => jobRef.__ref.includes([key]) === false
(jobRef) =>
jobRef.__ref.includes([
...new Set(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig &&
bodyshop.accountingconfig.qbo
? "jobid"
: "id"
]
)
),
]) === false
);
},
},
@@ -187,6 +203,27 @@ export function JobsExportAllButton({
key: "jobsuccessexport",
message: t("jobs.successes.exported"),
});
client.cache.modify({
id: "ROOT_QUERY",
fields: {
jobs(existingJobs = []) {
return existingJobs.filter(
(jobRef) =>
jobRef.__ref.includes(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig &&
bodyshop.accountingconfig.qbo
? "jobid"
: "id"
]
)
) === false
);
},
},
});
}
}
})
@@ -194,7 +231,6 @@ export function JobsExportAllButton({
if (!!completedCallback) completedCallback([]);
if (!!loadingCallback) loadingCallback(false);
// if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
setLoading(false);
};