79 lines
2.4 KiB
JavaScript
79 lines
2.4 KiB
JavaScript
import { EmbedUpdateDocumentV1 } from "@documenso/embed-react";
|
|
import { Modal } from "antd";
|
|
import axios from "axios";
|
|
import { useTranslation } from "react-i18next";
|
|
import { connect } from "react-redux";
|
|
import { createStructuredSelector } from "reselect";
|
|
import { toggleModalVisible } from "../../redux/modals/modals.actions";
|
|
import { selectEsignature } from "../../redux/modals/modals.selectors";
|
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
esignatureModal: selectEsignature,
|
|
bodyshop: selectBodyshop
|
|
});
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
toggleModalVisible: () => dispatch(toggleModalVisible("esignature"))
|
|
});
|
|
|
|
export function EsignatureModalContainer({ esignatureModal, toggleModalVisible, bodyshop }) {
|
|
const { t } = useTranslation();
|
|
const { open, context } = esignatureModal;
|
|
const { token, envelopeId, documentId, jobid } = context;
|
|
|
|
return (
|
|
<Modal
|
|
open={open}
|
|
title={t("jobs.labels.esignature")}
|
|
onOk={async () => {
|
|
try {
|
|
const distResult = await axios.post("/esign/distribute", {
|
|
documentId,
|
|
envelopeId,
|
|
jobid,
|
|
bodyshopid: bodyshop.id
|
|
});
|
|
console.log("Distribution result:", distResult);
|
|
toggleModalVisible();
|
|
} catch (error) {
|
|
console.error("Error distributing document:", error);
|
|
}
|
|
}}
|
|
onCancel={async () => {
|
|
try {
|
|
const cancelResult = await axios.post("/esign/delete", {
|
|
documentId,
|
|
envelopeId
|
|
});
|
|
console.log("Cancel result:", cancelResult);
|
|
toggleModalVisible();
|
|
} catch (error) {
|
|
console.error("Error cancelling document:", error);
|
|
}
|
|
}}
|
|
okButtonProps={{ title: "Distribute by Email" }}
|
|
width="90%"
|
|
destroyOnHidden
|
|
>
|
|
<div style={{ height: "600px", width: "100%" }}>
|
|
{token ? (
|
|
<EmbedUpdateDocumentV1
|
|
presignToken={token}
|
|
host="https://stg-app.documenso.com"
|
|
documentId={documentId}
|
|
className="esignature-embed"
|
|
onDocumentUpdated={(data) => {
|
|
console.log("Document updated:", data.documentId);
|
|
}}
|
|
/>
|
|
) : (
|
|
<div>No token...</div>
|
|
)}
|
|
</div>
|
|
</Modal>
|
|
);
|
|
}
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(EsignatureModalContainer);
|