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,
@@ -100,6 +101,9 @@ export function JobsCloseExportButton({
//Check to see if any of them failed. If they didn't don't execute the update.
const failedTransactions = PartnerResponse.data.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) => {
@@ -162,7 +166,20 @@ export function JobsCloseExportButton({
fields: {
jobs(existingJobs = []) {
return existingJobs.filter(
(jobRef) => jobRef.__ref.includes(jobId) === false
(jobRef) =>
jobRef.__ref.includes([
...new Set(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig &&
bodyshop.accountingconfig.qbo
? "jobid"
: "id"
]
)
),
]) === false
);
},
},
@@ -190,6 +207,29 @@ export function JobsCloseExportButton({
key: "jobsuccessexport",
message: t("jobs.successes.exported"),
});
client.cache.modify({
id: "ROOT_QUERY",
fields: {
jobs(existingJobs = []) {
return existingJobs.filter(
(jobRef) =>
jobRef.__ref.includes([
...new Set(
successfulTransactions.map(
(st) =>
st[
bodyshop.accountingconfig &&
bodyshop.accountingconfig.qbo
? "jobid"
: "id"
]
)
),
]) === false
);
},
},
});
}
if (setSelectedJobs) {
setSelectedJobs((selectedJobs) => {
@@ -197,7 +237,6 @@ export function JobsCloseExportButton({
});
}
}
//if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
setLoading(false);
};