IO-2368 Update Cache on success
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
|||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
selectCurrentUser,
|
selectCurrentUser,
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
|
import client from "../../utils/GraphQLClient";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
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.
|
//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 failedTransactions = PartnerResponse.data.filter((r) => !r.success);
|
||||||
|
const successfulTransactions = PartnerResponse.data.filter(
|
||||||
|
(r) => r.success
|
||||||
|
);
|
||||||
if (failedTransactions.length > 0) {
|
if (failedTransactions.length > 0) {
|
||||||
//Uh oh. At least one was no good.
|
//Uh oh. At least one was no good.
|
||||||
failedTransactions.forEach((ft) => {
|
failedTransactions.forEach((ft) => {
|
||||||
@@ -162,7 +166,20 @@ export function JobsCloseExportButton({
|
|||||||
fields: {
|
fields: {
|
||||||
jobs(existingJobs = []) {
|
jobs(existingJobs = []) {
|
||||||
return existingJobs.filter(
|
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",
|
key: "jobsuccessexport",
|
||||||
message: t("jobs.successes.exported"),
|
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) {
|
if (setSelectedJobs) {
|
||||||
setSelectedJobs((selectedJobs) => {
|
setSelectedJobs((selectedJobs) => {
|
||||||
@@ -197,7 +237,6 @@ export function JobsCloseExportButton({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
selectCurrentUser,
|
selectCurrentUser,
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
|
import client from "../../utils/GraphQLClient";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -96,7 +97,9 @@ export function JobsExportAllButton({
|
|||||||
Object.keys(groupedData).map(async (key) => {
|
Object.keys(groupedData).map(async (key) => {
|
||||||
//Check to see if any of them failed. If they didn't don't execute the update.
|
//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 failedTransactions = groupedData[key].filter((r) => !r.success);
|
||||||
|
const successfulTransactions = PartnerResponse.data.filter(
|
||||||
|
(r) => r.success
|
||||||
|
);
|
||||||
if (failedTransactions.length > 0) {
|
if (failedTransactions.length > 0) {
|
||||||
//Uh oh. At least one was no good.
|
//Uh oh. At least one was no good.
|
||||||
failedTransactions.forEach((ft) => {
|
failedTransactions.forEach((ft) => {
|
||||||
@@ -159,7 +162,20 @@ export function JobsExportAllButton({
|
|||||||
fields: {
|
fields: {
|
||||||
jobs(existingJobs = []) {
|
jobs(existingJobs = []) {
|
||||||
return existingJobs.filter(
|
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",
|
key: "jobsuccessexport",
|
||||||
message: t("jobs.successes.exported"),
|
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 (!!completedCallback) completedCallback([]);
|
||||||
if (!!loadingCallback) loadingCallback(false);
|
if (!!loadingCallback) loadingCallback(false);
|
||||||
// if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
selectCurrentUser,
|
selectCurrentUser,
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
|
import client from "../../utils/GraphQLClient";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -96,7 +97,9 @@ export function PayableExportAll({
|
|||||||
proms.push(
|
proms.push(
|
||||||
(async () => {
|
(async () => {
|
||||||
const failedTransactions = groupedData[key].filter((r) => !r.success);
|
const failedTransactions = groupedData[key].filter((r) => !r.success);
|
||||||
|
const successfulTransactions = PartnerResponse.data.filter(
|
||||||
|
(r) => r.success
|
||||||
|
);
|
||||||
if (failedTransactions.length > 0) {
|
if (failedTransactions.length > 0) {
|
||||||
//Uh oh. At least one was no good.
|
//Uh oh. At least one was no good.
|
||||||
failedTransactions.map((ft) =>
|
failedTransactions.map((ft) =>
|
||||||
@@ -142,7 +145,15 @@ export function PayableExportAll({
|
|||||||
|
|
||||||
const billUpdateResponse = await updateBill({
|
const billUpdateResponse = await updateBill({
|
||||||
variables: {
|
variables: {
|
||||||
billIdList: [key],
|
billIdList: successfulTransactions.map(
|
||||||
|
(st) =>
|
||||||
|
st[
|
||||||
|
bodyshop.accountingconfig &&
|
||||||
|
bodyshop.accountingconfig.qbo
|
||||||
|
? "billid"
|
||||||
|
: "id"
|
||||||
|
]
|
||||||
|
),
|
||||||
bill: {
|
bill: {
|
||||||
exported: true,
|
exported: true,
|
||||||
exported_at: new Date(),
|
exported_at: new Date(),
|
||||||
@@ -154,7 +165,20 @@ export function PayableExportAll({
|
|||||||
fields: {
|
fields: {
|
||||||
bills(existingJobs = []) {
|
bills(existingJobs = []) {
|
||||||
return existingJobs.filter(
|
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",
|
key: "billsuccessexport",
|
||||||
message: t("bills.successes.exported"),
|
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);
|
await Promise.all(proms);
|
||||||
if (!!completedCallback) completedCallback([]);
|
if (!!completedCallback) completedCallback([]);
|
||||||
if (!!loadingCallback) loadingCallback(false);
|
if (!!loadingCallback) loadingCallback(false);
|
||||||
if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
selectCurrentUser,
|
selectCurrentUser,
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
|
import client from "../../utils/GraphQLClient";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -157,7 +158,20 @@ export function PayableExportButton({
|
|||||||
fields: {
|
fields: {
|
||||||
bills(existingJobs = []) {
|
bills(existingJobs = []) {
|
||||||
return existingJobs.filter(
|
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",
|
key: "billsuccessexport",
|
||||||
message: t("bills.successes.exported"),
|
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) {
|
if (setSelectedBills) {
|
||||||
@@ -194,7 +231,6 @@ export function PayableExportButton({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!!loadingCallback) loadingCallback(false);
|
if (!!loadingCallback) loadingCallback(false);
|
||||||
if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
selectCurrentUser,
|
selectCurrentUser,
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
|
import client from "../../utils/GraphQLClient";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -156,7 +157,20 @@ export function PaymentExportButton({
|
|||||||
fields: {
|
fields: {
|
||||||
payments(existingJobs = []) {
|
payments(existingJobs = []) {
|
||||||
return existingJobs.filter(
|
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",
|
key: "paymentsuccessexport",
|
||||||
message: t("payments.successes.exported"),
|
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 (!!loadingCallback) loadingCallback(false);
|
||||||
if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
selectCurrentUser,
|
selectCurrentUser,
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
|
import client from "../../utils/GraphQLClient";
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
currentUser: selectCurrentUser,
|
currentUser: selectCurrentUser,
|
||||||
@@ -84,7 +85,9 @@ export function PaymentsExportAllButton({
|
|||||||
proms.push(
|
proms.push(
|
||||||
(async () => {
|
(async () => {
|
||||||
const failedTransactions = groupedData[key].filter((r) => !r.success);
|
const failedTransactions = groupedData[key].filter((r) => !r.success);
|
||||||
|
const successfulTransactions = PartnerResponse.data.filter(
|
||||||
|
(r) => r.success
|
||||||
|
);
|
||||||
if (failedTransactions.length > 0) {
|
if (failedTransactions.length > 0) {
|
||||||
//Uh oh. At least one was no good.
|
//Uh oh. At least one was no good.
|
||||||
failedTransactions.map((ft) =>
|
failedTransactions.map((ft) =>
|
||||||
@@ -130,7 +133,15 @@ export function PaymentsExportAllButton({
|
|||||||
});
|
});
|
||||||
const paymentUpdateResponse = await updatePayments({
|
const paymentUpdateResponse = await updatePayments({
|
||||||
variables: {
|
variables: {
|
||||||
paymentIdList: [key],
|
paymentIdList: successfulTransactions.map(
|
||||||
|
(st) =>
|
||||||
|
st[
|
||||||
|
bodyshop.accountingconfig &&
|
||||||
|
bodyshop.accountingconfig.qbo
|
||||||
|
? "paymentid"
|
||||||
|
: "id"
|
||||||
|
]
|
||||||
|
),
|
||||||
payment: {
|
payment: {
|
||||||
exportedat: new Date(),
|
exportedat: new Date(),
|
||||||
},
|
},
|
||||||
@@ -141,7 +152,20 @@ export function PaymentsExportAllButton({
|
|||||||
fields: {
|
fields: {
|
||||||
payments(existingJobs = []) {
|
payments(existingJobs = []) {
|
||||||
return existingJobs.filter(
|
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",
|
key: "paymentsuccessexport",
|
||||||
message: t("payments.successes.exported"),
|
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);
|
await Promise.all(proms);
|
||||||
if (!!completedCallback) completedCallback([]);
|
if (!!completedCallback) completedCallback([]);
|
||||||
if (!!loadingCallback) loadingCallback(false);
|
if (!!loadingCallback) loadingCallback(false);
|
||||||
if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user