Skip to content

🔥 The free & Open Source DocuSign alternative

fix: handle invalid email validation in quick send

prafull-opensignlabse0954950810a
diff --git a/apps/OpenSign/src/components/BulkSendUi.js b/apps/OpenSign/src/components/BulkSendUi.js
index f295a6b2a..cd0596d41 100644
--- a/apps/OpenSign/src/components/BulkSendUi.js
+++ b/apps/OpenSign/src/components/BulkSendUi.js
@@ -5,7 +5,7 @@ import Loader from "../primitives/Loader";
import { useTranslation } from "react-i18next";
import Parse from "parse";
import ModalUi from "../primitives/ModalUi";
-import { isEnableSubscription } from "../constant/const";
+import { emailRegex, isEnableSubscription } from "../constant/const";
import { fetchSubscription } from "../constant/Utils";
import { useNavigate } from "react-router-dom";
const BulkSendUi = (props) => {
@@ -202,70 +202,86 @@ const BulkSendUi = (props) => {
const updatedForms = forms.filter((_, i) => i !== index);
setForms(updatedForms);
};
+
+ function validateEmails(data) {
+ for (const item of data) {
+ for (const field of item.fields) {
+ if (!emailRegex.test(field.email)) {
+ alert(`Invalid email found: ${field.email}`);
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
const handleSubmit = async (e) => {
e.preventDefault();
e.stopPropagation();
setIsSubmit(true);
-
- // Create a copy of Placeholders array from props.item
- let Placeholders = [...props.Placeholders];
- // Initialize an empty array to store updated documents
- let Documents = [];
- // Loop through each form
- forms.forEach((form) => {
- //checking if user enter email which already exist as a signer then add user in a signers array
- let existSigner = [];
- form.fields.map((data) => {
- if (data.signer) {
- existSigner.push(data.signer);
- }
- });
- // Map through the copied Placeholders array to update email values
- const updatedPlaceholders = Placeholders.map((placeholder) => {
- // Find the field in the current form that matches the placeholder Id
- const field = form.fields.find(
- (element) => parseInt(element.fieldId) === placeholder.Id
- );
- // If a matching field is found, update the email value in the placeholder
- const signer = field?.signer?.objectId ? field.signer : "";
- if (field) {
- if (signer) {
- return {
- ...placeholder,
- signerObjId: field?.signer?.objectId || "",
- signerPtr: signer
- };
- } else {
- return {
- ...placeholder,
- email: field.email,
- signerObjId: field?.signer?.objectId || "",
- signerPtr: signer
- };
+ if (validateEmails(forms)) {
+ // Create a copy of Placeholders array from props.item
+ let Placeholders = [...props.Placeholders];
+ // Initialize an empty array to store updated documents
+ let Documents = [];
+ // Loop through each form
+ forms.forEach((form) => {
+ //checking if user enter email which already exist as a signer then add user in a signers array
+ let existSigner = [];
+ form.fields.map((data) => {
+ if (data.signer) {
+ existSigner.push(data.signer);
}
- }
- // If no matching field is found, keep the placeholder as is
- return placeholder;
- });
-
- // Push a new document object with updated Placeholders into the Documents array
- if (existSigner?.length > 0) {
- Documents.push({
- ...props.item,
- Placeholders: updatedPlaceholders,
- Signers: props.item.Signers
- ? [...props.item.Signers, ...existSigner]
- : [...existSigner]
});
- } else {
- Documents.push({
- ...props.item,
- Placeholders: updatedPlaceholders,
- SignatureType: props.signatureType
+ // Map through the copied Placeholders array to update email values
+ const updatedPlaceholders = Placeholders.map((placeholder) => {
+ // Find the field in the current form that matches the placeholder Id
+ const field = form.fields.find(
+ (element) => parseInt(element.fieldId) === placeholder.Id
+ );
+ // If a matching field is found, update the email value in the placeholder
+ const signer = field?.signer?.objectId ? field.signer : "";
+ if (field) {
+ if (signer) {
+ return {
+ ...placeholder,
+ signerObjId: field?.signer?.objectId || "",
+ signerPtr: signer
+ };
+ } else {
+ return {
+ ...placeholder,
+ email: field.email,
+ signerObjId: field?.signer?.objectId || "",
+ signerPtr: signer
+ };
+ }
+ }
+ // If no matching field is found, keep the placeholder as is
+ return placeholder;
});
- }
- });
- await batchQuery(Documents);
+
+ // Push a new document object with updated Placeholders into the Documents array
+ if (existSigner?.length > 0) {
+ Documents.push({
+ ...props.item,
+ Placeholders: updatedPlaceholders,
+ Signers: props.item.Signers
+ ? [...props.item.Signers, ...existSigner]
+ : [...existSigner]
+ });
+ } else {
+ Documents.push({
+ ...props.item,
+ Placeholders: updatedPlaceholders,
+ SignatureType: props.signatureType
+ });
+ }
+ });
+ await batchQuery(Documents);
+ } else {
+ setIsSubmit(false);
+ }
};
const batchQuery = async (Documents) => {