diff --git a/client/src/components/payment-mark-export-button/payment-mark-export-button-component.jsx b/client/src/components/payment-mark-export-button/payment-mark-export-button-component.jsx new file mode 100644 index 000000000..a5e77d1d3 --- /dev/null +++ b/client/src/components/payment-mark-export-button/payment-mark-export-button-component.jsx @@ -0,0 +1,100 @@ +import React from "react"; +import { Button, notification } from "antd"; +import { useMutation } from "@apollo/client"; +import { useTranslation } from "react-i18next"; +import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries"; +import { setModalContext } from "../../redux/modals/modals.actions"; +import { connect } from "react-redux"; +import { UPDATE_PAYMENT } from "../../graphql/payments.queries"; +import { selectCurrentUser } from "../../redux/user/user.selectors"; +import { createStructuredSelector } from "reselect"; + +const mapStateToProps = createStructuredSelector({ + currentUser: selectCurrentUser, +}); + +const mapDispatchToProps = (dispatch) => ({ + setPaymentContext: (context) => + dispatch(setModalContext({ context: context, modal: "payment" })), +}); + +const PaymentMarkForExportButton = ({ + bodyshop, + payment, + refetch, + setPaymentContext, + currentUser, +}) => { + const { t } = useTranslation(); + const [insertExportLog, { loading: exportLogLoading }] = + useMutation(INSERT_EXPORT_LOG); + const [updatePayment, { loading: updatePaymentLoading }] = + useMutation(UPDATE_PAYMENT); + + const handleClick = async () => { + const today = new Date(); + + await insertExportLog({ + variables: { + logs: [ + { + bodyshopid: bodyshop.id, + paymentid: payment.id, + successful: true, + useremail: currentUser.email, + }, + ], + }, + }); + + const paymentUpdateResponse = await updatePayment({ + variables: { + paymentId: payment.id, + payment: { + exportedat: today, + }, + }, + }); + + if (!!!paymentUpdateResponse.errors) { + notification.open({ + type: "success", + key: "paymentsuccessmarkforexport", + message: t("payments.successes.markexported"), + }); + + if (refetch) refetch(); + + setPaymentContext({ + actions: { + refetch, + }, + context: { + ...payment, + exportedat: today, + }, + }); + } else { + notification["error"]({ + message: t("payments.errors.exporting", { + error: JSON.stringify(paymentUpdateResponse.error), + }), + }); + } + }; + + return ( + + ); +}; + +export default connect( + mapStateToProps, + mapDispatchToProps +)(PaymentMarkForExportButton); diff --git a/client/src/components/payment-modal/payment-modal.container.jsx b/client/src/components/payment-modal/payment-modal.container.jsx index 28c47c30c..c72bd224a 100644 --- a/client/src/components/payment-modal/payment-modal.container.jsx +++ b/client/src/components/payment-modal/payment-modal.container.jsx @@ -19,8 +19,8 @@ import { import { GenerateDocument } from "../../utils/RenderTemplate"; import { TemplateList } from "../../utils/TemplateConstants"; import PaymentForm from "../payment-form/payment-form.component"; -import PaymentExportButton from "../payment-export-button/payment-export-button.component"; import PaymentReexportButton from "../payment-reexport-button/payment-reexport-button.component"; +import PaymentMarkForExportButton from "../payment-mark-export-button/payment-mark-export-button-component"; const mapStateToProps = createStructuredSelector({ paymentModal: selectPayment, @@ -180,10 +180,9 @@ function PaymentModalContainer({ > - diff --git a/client/src/components/payment-reexport-button/payment-reexport-button.component.jsx b/client/src/components/payment-reexport-button/payment-reexport-button.component.jsx index c24d2eab1..a3adb5422 100644 --- a/client/src/components/payment-reexport-button/payment-reexport-button.component.jsx +++ b/client/src/components/payment-reexport-button/payment-reexport-button.component.jsx @@ -29,7 +29,7 @@ const PaymentReexportButton = ({ payment, refetch, setPaymentContext }) => { notification.open({ type: "success", key: "paymentsuccessexport", - message: t("payments.successes.reexported"), + message: t("payments.successes.markreexported"), }); if (refetch) refetch(); @@ -58,7 +58,7 @@ const PaymentReexportButton = ({ payment, refetch, setPaymentContext }) => { loading={loading} disabled={!payment.exportedat} > - {t("bills.labels.markforreexport")} + {t("payments.labels.markforreexport")} ); }; diff --git a/client/src/components/schedule-calendar/schedule-calendar.component.jsx b/client/src/components/schedule-calendar/schedule-calendar.component.jsx index 144ef5392..743e0d83a 100644 --- a/client/src/components/schedule-calendar/schedule-calendar.component.jsx +++ b/client/src/components/schedule-calendar/schedule-calendar.component.jsx @@ -53,29 +53,29 @@ export function ScheduleCalendarComponent({ data, refetch, bodyshop }) { ); const filteredData = useMemo(() => { - return data - .filter((d) => { - if (d.__typename === "appointments") { - if (estimatorsFilter.length === 0) return true; + return data.filter((d) => { + const estFilter = + d.__typename === "appointments" + ? estimatorsFilter.length === 0 + ? true + : !!estimatorsFilter.find( + (e) => e === `${d.job.est_ct_fn} ${d.job.est_ct_ln}` + ) + : true; - return !!estimatorsFilter.find( - (e) => e !== `${d.job.est_ct_fn} ${d.job.est_ct_ln}` - ); - } - return true; - }) - .filter( - (d) => - (d.block || - (filter.intake && d.isintake) || - (filter.manual && !d.isintake && d.block === false) || - (d.__typename === "employee_vacation" && - filter.employeevacation && - !!d.employee)) && - (filter.ins_co_nm && filter.ins_co_nm.length > 0 - ? filter.ins_co_nm.includes(d.job?.ins_co_nm) - : true) + return ( + (d.block || + (filter.intake && d.isintake) || + (filter.manual && !d.isintake && d.block === false) || + (d.__typename === "employee_vacation" && + filter.employeevacation && + !!d.employee)) && + (filter.ins_co_nm && filter.ins_co_nm.length > 0 + ? filter.ins_co_nm.includes(d.job?.ins_co_nm) + : true) && + estFilter ); + }); }, [data, filter, estimatorsFilter]); return ( diff --git a/client/src/graphql/conversations.queries.js b/client/src/graphql/conversations.queries.js index 53de38b62..f9feb3f2f 100644 --- a/client/src/graphql/conversations.queries.js +++ b/client/src/graphql/conversations.queries.js @@ -60,7 +60,7 @@ export const CONVERSATION_LIST_QUERY = gql` query CONVERSATION_LIST_QUERY($offset: Int!) { conversations( order_by: { updated_at: desc } - limit: 20 + limit: 50 offset: $offset where: { archived: { _eq: false } } ) { diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 0949023db..d11936f83 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -2219,11 +2219,11 @@ "title": "Payments", "totalpayments": "Total Payments", "markforexport": "Mark for Export", - "markforreexport": "Mark for Reexport" + "markforreexport": "Mark for Re-export" }, "successes": { "exported": "Payment(s) exported successfully.", - "reexported": "Payment Re-exported successfully", + "markreexported": "Payment marked for re-export successfully", "markexported": "Payment(s) marked exported.", "payment": "Payment created successfully. ", "stripe": "Credit card transaction charged successfully."