(e)
| 60 | }; |
| 61 | // Define a function to handle form submission |
| 62 | const handleSubmit = async (e) => { |
| 63 | e.preventDefault(); |
| 64 | e.stopPropagation(); |
| 65 | if (!emailRegex.test(email)) { |
| 66 | alert(t("valid-email-alert")); |
| 67 | } else { |
| 68 | setIsLoader(true); |
| 69 | const user = JSON.parse( |
| 70 | localStorage.getItem( |
| 71 | `Parse/${localStorage.getItem("parseAppId")}/currentUser` |
| 72 | ) |
| 73 | ); |
| 74 | const userId = user?.objectId || ""; |
| 75 | const tenantDetails = await getTenantDetails( |
| 76 | userId, |
| 77 | ); |
| 78 | const tenantId = tenantDetails?.objectId || ""; |
| 79 | if (tenantId) { |
| 80 | try { |
| 81 | const baseURL = localStorage.getItem("baseUrl"); |
| 82 | const url = `${baseURL}functions/savecontact`; |
| 83 | const token = |
| 84 | { |
| 85 | "X-Parse-Session-Token": localStorage.getItem("accesstoken") |
| 86 | }; |
| 87 | const data = { name, email, phone, tenantId, jobTitle, company }; |
| 88 | const headers = { |
| 89 | "Content-Type": "application/json", |
| 90 | "X-Parse-Application-Id": localStorage.getItem("parseAppId"), |
| 91 | ...token |
| 92 | }; |
| 93 | const axiosRes = await axios.post(url, data, { headers }); |
| 94 | const contactRes = axiosRes?.data?.result || {}; |
| 95 | if (contactRes?.objectId) { |
| 96 | props.details(contactRes, props?.newContactId); |
| 97 | if (props.closePopup) { |
| 98 | props.closePopup(); |
| 99 | setIsLoader(false); |
| 100 | // Reset the form fields |
| 101 | handleReset(); |
| 102 | } |
| 103 | } |
| 104 | } catch (err) { |
| 105 | console.log("Err", err); |
| 106 | setIsLoader(false); |
| 107 | if (err?.response?.data?.error?.includes("already exists")) { |
| 108 | alert(t("add-signer-alert")); |
| 109 | } else { |
| 110 | alert(t("something-went-wrong-mssg")); |
| 111 | } |
| 112 | } |
| 113 | } else { |
| 114 | setIsLoader(false); |
| 115 | dispatch(sessionStatus(false)); |
| 116 | alert(t("something-went-wrong-mssg")); |
| 117 | } |
| 118 | } |
| 119 | }; |
nothing calls this directly
no test coverage detected