View and edit payments IO-531
This commit is contained in:
@@ -214,7 +214,7 @@ function Header({
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
setPaymentContext({
|
setPaymentContext({
|
||||||
actions: {},
|
actions: {},
|
||||||
context: {},
|
context: null,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export function JobsDetailTotals({
|
|||||||
onClick={() =>
|
onClick={() =>
|
||||||
setPaymentContext({
|
setPaymentContext({
|
||||||
actions: { refetch: refetch },
|
actions: { refetch: refetch },
|
||||||
context: { jobId: job.id },
|
context: { jobid: job.id },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -13,7 +13,12 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
});
|
});
|
||||||
|
|
||||||
export function PaymentFormComponent({ form, stripeStateArr, bodyshop }) {
|
export function PaymentFormComponent({
|
||||||
|
form,
|
||||||
|
stripeStateArr,
|
||||||
|
bodyshop,
|
||||||
|
disabled,
|
||||||
|
}) {
|
||||||
const [stripeState, setStripeState] = stripeStateArr;
|
const [stripeState, setStripeState] = stripeStateArr;
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -33,7 +38,7 @@ export function PaymentFormComponent({ form, stripeStateArr, bodyshop }) {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<JobSearchSelect />
|
<JobSearchSelect disabled={disabled} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("payments.fields.amount")}
|
label={t("payments.fields.amount")}
|
||||||
@@ -45,18 +50,18 @@ export function PaymentFormComponent({ form, stripeStateArr, bodyshop }) {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<CurrencyInput />
|
<CurrencyInput disabled={disabled} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("payments.fields.transactionid")}
|
label={t("payments.fields.transactionid")}
|
||||||
name="transactionid"
|
name="transactionid"
|
||||||
>
|
>
|
||||||
<Input />
|
<Input disabled={disabled} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item label={t("payments.fields.memo")} name="memo">
|
<Form.Item label={t("payments.fields.memo")} name="memo">
|
||||||
<Input />
|
<Input disabled={disabled} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
@@ -69,7 +74,7 @@ export function PaymentFormComponent({ form, stripeStateArr, bodyshop }) {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Select>
|
<Select disabled={disabled}>
|
||||||
<Select.Option value={t("payments.labels.customer")}>
|
<Select.Option value={t("payments.labels.customer")}>
|
||||||
{t("payments.labels.customer")}
|
{t("payments.labels.customer")}
|
||||||
</Select.Option>
|
</Select.Option>
|
||||||
@@ -89,7 +94,7 @@ export function PaymentFormComponent({ form, stripeStateArr, bodyshop }) {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Select>
|
<Select disabled={disabled}>
|
||||||
<Select.Option value="Visa">Visa</Select.Option>
|
<Select.Option value="Visa">Visa</Select.Option>
|
||||||
<Select.Option value="Mastercard">Mastercard</Select.Option>
|
<Select.Option value="Mastercard">Mastercard</Select.Option>
|
||||||
<Select.Option value="AMEX">AMEX</Select.Option>
|
<Select.Option value="AMEX">AMEX</Select.Option>
|
||||||
@@ -106,7 +111,7 @@ export function PaymentFormComponent({ form, stripeStateArr, bodyshop }) {
|
|||||||
>
|
>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
defaultChecked={!!bodyshop.stripe_acct_id}
|
defaultChecked={!!bodyshop.stripe_acct_id}
|
||||||
disabled={!!!bodyshop.stripe_acct_id}
|
disabled={!!!bodyshop.stripe_acct_id || disabled}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
@@ -115,7 +120,7 @@ export function PaymentFormComponent({ form, stripeStateArr, bodyshop }) {
|
|||||||
name="sendby"
|
name="sendby"
|
||||||
initialValue="email"
|
initialValue="email"
|
||||||
>
|
>
|
||||||
<Radio.Group>
|
<Radio.Group disabled={disabled}>
|
||||||
<Radio.Button value="email">{t("general.labels.email")}</Radio.Button>
|
<Radio.Button value="email">{t("general.labels.email")}</Radio.Button>
|
||||||
<Radio.Button value="print">{t("general.labels.print")}</Radio.Button>
|
<Radio.Button value="print">{t("general.labels.print")}</Radio.Button>
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import { connect } from "react-redux";
|
|
||||||
import { createStructuredSelector } from "reselect";
|
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
|
||||||
import PaymentFormComponent from "./payment-form.component";
|
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
|
||||||
bodyshop: selectBodyshop,
|
|
||||||
});
|
|
||||||
|
|
||||||
export function PaymentFormContainer({ bodyshop, form, stripeStateArr }) {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<PaymentFormComponent form={form} stripeStateArr={stripeStateArr} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
export default connect(mapStateToProps, null)(PaymentFormContainer);
|
|
||||||
@@ -1,25 +1,28 @@
|
|||||||
import { useElements, useStripe, CardElement } from "@stripe/react-stripe-js";
|
import { useMutation } from "@apollo/react-hooks";
|
||||||
|
import { CardElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
||||||
import { Form, Modal, notification } from "antd";
|
import { Form, Modal, notification } from "antd";
|
||||||
import React, { useState, useEffect } from "react";
|
import axios from "axios";
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
|
import {
|
||||||
|
INSERT_NEW_PAYMENT,
|
||||||
|
UPDATE_PAYMENT,
|
||||||
|
} from "../../graphql/payments.queries";
|
||||||
|
import { setEmailOptions } from "../../redux/email/email.actions";
|
||||||
import { toggleModalVisible } from "../../redux/modals/modals.actions";
|
import { toggleModalVisible } from "../../redux/modals/modals.actions";
|
||||||
import { selectPayment } from "../../redux/modals/modals.selectors";
|
import { selectPayment } from "../../redux/modals/modals.selectors";
|
||||||
import {
|
import {
|
||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
selectCurrentUser,
|
selectCurrentUser,
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
import PaymentForm from "../payment-form/payment-form.container";
|
|
||||||
import axios from "axios";
|
|
||||||
import { useMutation } from "@apollo/react-hooks";
|
|
||||||
import { INSERT_NEW_PAYMENT } from "../../graphql/payments.queries";
|
|
||||||
import { TemplateList } from "../../utils/TemplateConstants";
|
|
||||||
import RenderTemplate, {
|
import RenderTemplate, {
|
||||||
displayTemplateInWindow,
|
displayTemplateInWindow,
|
||||||
} from "../../utils/RenderTemplate";
|
} from "../../utils/RenderTemplate";
|
||||||
import { setEmailOptions } from "../../redux/email/email.actions";
|
import { TemplateList } from "../../utils/TemplateConstants";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import PaymentForm from "../payment-form/payment-form.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
paymentModal: selectPayment,
|
paymentModal: selectPayment,
|
||||||
@@ -41,6 +44,7 @@ function BillEnterModalContainer({
|
|||||||
}) {
|
}) {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [insertPayment] = useMutation(INSERT_NEW_PAYMENT);
|
const [insertPayment] = useMutation(INSERT_NEW_PAYMENT);
|
||||||
|
const [updatePayment] = useMutation(UPDATE_PAYMENT);
|
||||||
const stripe = useStripe();
|
const stripe = useStripe();
|
||||||
const elements = useElements();
|
const elements = useElements();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -98,49 +102,64 @@ function BillEnterModalContainer({
|
|||||||
}
|
}
|
||||||
logImEXEvent("payment_insert");
|
logImEXEvent("payment_insert");
|
||||||
|
|
||||||
const newPayment = await insertPayment({
|
if (!context || (context && !context.id)) {
|
||||||
variables: {
|
const newPayment = await insertPayment({
|
||||||
paymentInput: {
|
variables: {
|
||||||
...paymentObj,
|
paymentInput: {
|
||||||
stripeid:
|
...paymentObj,
|
||||||
stripePayment &&
|
stripeid:
|
||||||
stripePayment.paymentIntent &&
|
stripePayment &&
|
||||||
stripePayment.paymentIntent.id,
|
stripePayment.paymentIntent &&
|
||||||
},
|
stripePayment.paymentIntent.id,
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!!!newPayment.errors) {
|
|
||||||
notification["success"]({ message: t("payments.successes.payment") });
|
|
||||||
} else {
|
|
||||||
notification["error"]({ message: t("payments.errors.payment") });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sendby === "email") {
|
|
||||||
setEmailOptions({
|
|
||||||
messageOptions: {
|
|
||||||
// to: [appData.email],
|
|
||||||
replyTo: bodyshop.email,
|
|
||||||
},
|
|
||||||
template: {
|
|
||||||
name: TemplateList().payment_receipt.key,
|
|
||||||
variables: {
|
|
||||||
id: newPayment.data.insert_payments.returning[0].id,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
displayTemplateInWindow(
|
if (!!!newPayment.errors) {
|
||||||
await RenderTemplate(
|
notification["success"]({ message: t("payments.successes.payment") });
|
||||||
{
|
} else {
|
||||||
|
notification["error"]({ message: t("payments.errors.payment") });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendby === "email") {
|
||||||
|
setEmailOptions({
|
||||||
|
messageOptions: {
|
||||||
|
// to: [appData.email],
|
||||||
|
replyTo: bodyshop.email,
|
||||||
|
},
|
||||||
|
template: {
|
||||||
name: TemplateList().payment_receipt.key,
|
name: TemplateList().payment_receipt.key,
|
||||||
variables: {
|
variables: {
|
||||||
id: newPayment.data.insert_payments.returning[0].id,
|
id: newPayment.data.insert_payments.returning[0].id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
bodyshop
|
});
|
||||||
)
|
} else {
|
||||||
);
|
displayTemplateInWindow(
|
||||||
|
await RenderTemplate(
|
||||||
|
{
|
||||||
|
name: TemplateList().payment_receipt.key,
|
||||||
|
variables: {
|
||||||
|
id: newPayment.data.insert_payments.returning[0].id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bodyshop
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const updatedPayment = await updatePayment({
|
||||||
|
variables: {
|
||||||
|
paymentId: context.id,
|
||||||
|
payment: paymentObj,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!!!updatedPayment.errors) {
|
||||||
|
notification["success"]({ message: t("payments.successes.payment") });
|
||||||
|
} else {
|
||||||
|
notification["error"]({ message: t("payments.errors.payment") });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actions.refetch) actions.refetch();
|
if (actions.refetch) actions.refetch();
|
||||||
@@ -158,7 +177,7 @@ function BillEnterModalContainer({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible) form.resetFields();
|
if (visible) form.resetFields();
|
||||||
}, [visible, form]);
|
}, [visible, form, context]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
@@ -167,20 +186,23 @@ function BillEnterModalContainer({
|
|||||||
okText={t("general.actions.save")}
|
okText={t("general.actions.save")}
|
||||||
onOk={() => form.submit()}
|
onOk={() => form.submit()}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
afterClose={() => form.resetFields()}
|
|
||||||
okButtonProps={{
|
okButtonProps={{
|
||||||
loading: loading,
|
loading: loading,
|
||||||
}}
|
}}
|
||||||
destroyOnClose
|
|
||||||
>
|
>
|
||||||
|
<button onClick={() => form.resetFields()}>reste</button>
|
||||||
<Form
|
<Form
|
||||||
onFinish={handleFinish}
|
onFinish={handleFinish}
|
||||||
autoComplete={"off"}
|
autoComplete={"off"}
|
||||||
form={form}
|
form={form}
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
initialValues={context}
|
initialValues={context || {}}
|
||||||
>
|
>
|
||||||
<PaymentForm form={form} stripeStateArr={stripeStateArr} />
|
<PaymentForm
|
||||||
|
form={form}
|
||||||
|
stripeStateArr={stripeStateArr}
|
||||||
|
disabled={context && context.stripeid}
|
||||||
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export function PaymentsListPaginated({
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
setPaymentContext({
|
setPaymentContext({
|
||||||
actions: { refetch: refetch },
|
actions: { refetch: refetch },
|
||||||
context: { record },
|
context: record ,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -55,7 +55,14 @@ export const UPDATE_PAYMENT = gql`
|
|||||||
update_payments(where: { id: { _eq: $paymentId } }, _set: $payment) {
|
update_payments(where: { id: { _eq: $paymentId } }, _set: $payment) {
|
||||||
returning {
|
returning {
|
||||||
id
|
id
|
||||||
exported_at
|
transactionid
|
||||||
|
memo
|
||||||
|
type
|
||||||
|
amount
|
||||||
|
stripeid
|
||||||
|
exportedat
|
||||||
|
stripeid
|
||||||
|
payer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user