diff --git a/client/src/components/jobs-close-export-button/jobs-close-export-button.component.jsx b/client/src/components/jobs-close-export-button/jobs-close-export-button.component.jsx index add61d4cf..15d07e163 100644 --- a/client/src/components/jobs-close-export-button/jobs-close-export-button.component.jsx +++ b/client/src/components/jobs-close-export-button/jobs-close-export-button.component.jsx @@ -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); }; diff --git a/client/src/components/jobs-export-all-button/jobs-export-all-button.component.jsx b/client/src/components/jobs-export-all-button/jobs-export-all-button.component.jsx index 78d573d2c..b584fb3e3 100644 --- a/client/src/components/jobs-export-all-button/jobs-export-all-button.component.jsx +++ b/client/src/components/jobs-export-all-button/jobs-export-all-button.component.jsx @@ -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); }; diff --git a/client/src/components/payable-export-all-button/payable-export-all-button.component.jsx b/client/src/components/payable-export-all-button/payable-export-all-button.component.jsx index 16ba8dc39..dcd7cca4d 100644 --- a/client/src/components/payable-export-all-button/payable-export-all-button.component.jsx +++ b/client/src/components/payable-export-all-button/payable-export-all-button.component.jsx @@ -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); }; diff --git a/client/src/components/payable-export-button/payable-export-button.component.jsx b/client/src/components/payable-export-button/payable-export-button.component.jsx index d42c67eeb..554ee475b 100644 --- a/client/src/components/payable-export-button/payable-export-button.component.jsx +++ b/client/src/components/payable-export-button/payable-export-button.component.jsx @@ -13,6 +13,7 @@ import { selectBodyshop, selectCurrentUser, } from "../../redux/user/user.selectors"; +import client from "../../utils/GraphQLClient"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, @@ -157,7 +158,20 @@ export function PayableExportButton({ fields: { bills(existingJobs = []) { return existingJobs.filter( - (billRef) => billRef.__ref.includes(billId) === false + (billRef) => + billRef.__ref.includes([ + ...new Set( + successfulTransactions.map( + (st) => + st[ + bodyshop.accountingconfig && + bodyshop.accountingconfig.qbo + ? "billid" + : "id" + ] + ) + ), + ]) === false ); }, }, @@ -184,6 +198,29 @@ export function PayableExportButton({ 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 + ); + }, + }, + }); } if (setSelectedBills) { @@ -194,7 +231,6 @@ export function PayableExportButton({ } if (!!loadingCallback) loadingCallback(false); - if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch(); setLoading(false); }; diff --git a/client/src/components/payment-export-button/payment-export-button.component.jsx b/client/src/components/payment-export-button/payment-export-button.component.jsx index 534516275..6bbf5d8c7 100644 --- a/client/src/components/payment-export-button/payment-export-button.component.jsx +++ b/client/src/components/payment-export-button/payment-export-button.component.jsx @@ -13,6 +13,7 @@ import { selectBodyshop, selectCurrentUser, } from "../../redux/user/user.selectors"; +import client from "../../utils/GraphQLClient"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, @@ -156,7 +157,20 @@ export function PaymentExportButton({ fields: { payments(existingJobs = []) { return existingJobs.filter( - (paymentRef) => paymentRef.__ref.includes(paymentId) === false + (paymentRef) => + paymentRef.__ref.includes([ + ...new Set( + successfulTransactions.map( + (st) => + st[ + bodyshop.accountingconfig && + bodyshop.accountingconfig.qbo + ? "paymentid" + : "id" + ] + ) + ), + ]) === false ); }, }, @@ -190,9 +204,31 @@ 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 + ); + }, + }, + }); } if (!!loadingCallback) loadingCallback(false); - if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch(); setLoading(false); }; diff --git a/client/src/components/payments-export-all-button/payments-export-all-button.component.jsx b/client/src/components/payments-export-all-button/payments-export-all-button.component.jsx index c62965cd6..863487345 100644 --- a/client/src/components/payments-export-all-button/payments-export-all-button.component.jsx +++ b/client/src/components/payments-export-all-button/payments-export-all-button.component.jsx @@ -13,6 +13,7 @@ import { selectBodyshop, selectCurrentUser, } from "../../redux/user/user.selectors"; +import client from "../../utils/GraphQLClient"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, currentUser: selectCurrentUser, @@ -84,7 +85,9 @@ export function PaymentsExportAllButton({ 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) => @@ -130,7 +133,15 @@ export function PaymentsExportAllButton({ }); const paymentUpdateResponse = await updatePayments({ variables: { - paymentIdList: [key], + paymentIdList: successfulTransactions.map( + (st) => + st[ + bodyshop.accountingconfig && + bodyshop.accountingconfig.qbo + ? "paymentid" + : "id" + ] + ), payment: { exportedat: new Date(), }, @@ -141,7 +152,20 @@ export function PaymentsExportAllButton({ fields: { payments(existingJobs = []) { return existingJobs.filter( - (paymentRef) => paymentRef.__ref.includes([key]) === false + (paymentRef) => + paymentRef.__ref.includes([ + ...new Set( + successfulTransactions.map( + (st) => + st[ + bodyshop.accountingconfig && + bodyshop.accountingconfig.qbo + ? "paymentid" + : "id" + ] + ) + ), + ]) === false ); }, }, @@ -168,6 +192,29 @@ export function PaymentsExportAllButton({ 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 + ); + }, + }, + }); } } })() @@ -176,7 +223,6 @@ export function PaymentsExportAllButton({ await Promise.all(proms); if (!!completedCallback) completedCallback([]); if (!!loadingCallback) loadingCallback(false); - if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch(); setLoading(false); };