import { CopyFilled } from "@ant-design/icons"; import { Button, Form, message, Popover, Space } from "antd"; import axios from "axios"; import Dinero from "dinero.js"; import { parsePhoneNumber } from "libphonenumber-js"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; import { openChatByPhone, setMessage } from "../../redux/messaging/messaging.actions"; import { selectBodyshop } from "../../redux/user/user.selectors"; import CurrencyFormItemComponent from "../form-items-formatted/currency-form-item.component"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop }); const mapDispatchToProps = (dispatch) => ({ openChatByPhone: (phone) => dispatch(openChatByPhone(phone)), setMessage: (text) => dispatch(setMessage(text)) }); export default connect(mapStateToProps, mapDispatchToProps)(PaymentsGenerateLink); export function PaymentsGenerateLink({ bodyshop, callback, job, openChatByPhone, setMessage }) { const { t } = useTranslation(); const [form] = Form.useForm(); const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); const [paymentLink, setPaymentLink] = useState(null); const handleFinish = async ({ amount }) => { setLoading(true); const p = parsePhoneNumber(job.ownr_ph1, "CA"); setLoading(true); const response = await axios.post("/intellipay/generate_payment_url", { bodyshop, amount: amount, account: job.ro_number, invoice: job.id }); setLoading(false); setPaymentLink(response.data.shorUrl); openChatByPhone({ phone_num: p.formatInternational(), jobid: job.id }); setMessage( t("payments.labels.smspaymentreminder", { shopname: bodyshop.shopname, amount: amount, payment_link: response.data.shorUrl }) ); //Add in confirmation & errors. if (callback) callback(); // setOpen(false); setLoading(false); }; const popContent = (