IO-897 Save and New for payment modal

This commit is contained in:
Patrick Fic
2021-04-13 10:36:41 -07:00
parent 12609d54ca
commit 70a6ffc7db
6 changed files with 76 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
<babeledit_project be_version="2.7.1" version="1.2">
<babeledit_project version="1.2" be_version="2.7.1">
<!--
BabelEdit project file
@@ -12480,6 +12480,27 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>none</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>out</name>
<definition_loaded>false</definition_loaded>

View File

@@ -140,9 +140,10 @@ export function PaymentFormComponent({
<Form.Item
label={t("general.labels.sendby")}
name="sendby"
initialValue="email"
initialValue="none"
>
<Radio.Group disabled={disabled}>
<Radio value="none">{t("general.labels.none")}</Radio>
<Radio value="email">{t("general.labels.email")}</Radio>
<Radio value="print">{t("general.labels.print")}</Radio>
</Radio.Group>

View File

@@ -1,6 +1,6 @@
import { useMutation } from "@apollo/client";
import { CardElement, useElements, useStripe } from "@stripe/react-stripe-js";
import { Form, Modal, notification } from "antd";
import { Button, Form, Modal, notification } from "antd";
import axios from "axios";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
@@ -41,6 +41,7 @@ function BillEnterModalContainer({
setEmailOptions,
}) {
const [form] = Form.useForm();
const [enterAgain, setEnterAgain] = useState(false);
const [insertPayment] = useMutation(INSERT_NEW_PAYMENT);
const [updatePayment] = useMutation(UPDATE_PAYMENT);
const stripe = useStripe();
@@ -119,20 +120,22 @@ function BillEnterModalContainer({
notification["error"]({ message: t("payments.errors.payment") });
}
const Templates = TemplateList("payment");
GenerateDocument(
{
name: Templates.payment_receipt.key,
variables: {
id: newPayment.data.insert_payments.returning[0].id,
if (sendby !== "none") {
GenerateDocument(
{
name: Templates.payment_receipt.key,
variables: {
id: newPayment.data.insert_payments.returning[0].id,
},
},
},
{
// to: [appData.email],
replyTo: bodyshop.email,
subject: Templates.payment_receipt.subject,
},
sendby === "email" ? "e" : "p"
);
{
// to: [appData.email],
replyTo: bodyshop.email,
subject: Templates.payment_receipt.subject,
},
sendby === "email" ? "e" : "p"
);
}
} else {
const updatedPayment = await updatePayment({
variables: {
@@ -149,10 +152,17 @@ function BillEnterModalContainer({
}
if (actions.refetch) actions.refetch();
toggleModalVisible();
if (enterAgain) {
form.resetFields();
form.setFieldsValue({ billlines: [] });
} else {
toggleModalVisible();
}
setEnterAgain(false);
} catch (error) {
console.log("error", error);
} finally {
setEnterAgain(false);
setLoading(false);
}
};
@@ -165,6 +175,10 @@ function BillEnterModalContainer({
if (visible) form.resetFields();
}, [visible, form, context]);
useEffect(() => {
if (enterAgain) form.submit();
}, [enterAgain, form]);
return (
<Modal
title={
@@ -179,6 +193,26 @@ function BillEnterModalContainer({
okButtonProps={{
loading: loading,
}}
afterClose={() => form.resetFields()}
footer={
<span>
<Button onClick={handleCancel}>{t("general.actions.cancel")}</Button>
<Button loading={loading} onClick={() => form.submit()}>
{t("general.actions.save")}
</Button>
{paymentModal.context && paymentModal.context.id ? null : (
<Button
type="primary"
loading={loading}
onClick={() => {
setEnterAgain(true);
}}
>
{t("general.actions.saveandnew")}
</Button>
)}
</span>
}
>
<Form
onFinish={handleFinish}

View File

@@ -796,6 +796,7 @@
"monday": "Monday",
"na": "N/A",
"no": "No",
"none": "None",
"out": "Out",
"password": "Password",
"passwordresetsuccess": "A password reset link has been sent to you.",

View File

@@ -796,6 +796,7 @@
"monday": "",
"na": "N / A",
"no": "",
"none": "",
"out": "Afuera",
"password": "",
"passwordresetsuccess": "",

View File

@@ -796,6 +796,7 @@
"monday": "",
"na": "N / A",
"no": "",
"none": "",
"out": "En dehors",
"password": "",
"passwordresetsuccess": "",