@sheerid/jslib-nightly
Version:
SheerID JavaScript Library
290 lines (288 loc) • 9.37 kB
JavaScript
/**
* VERSION: 2.130.0-alpha.4
* BUILD_TIMESTAMP: 1759000374473
* BUILD_DATE: Sat Sep 27 2025 19:12:54 GMT+0000 (Coordinated Universal Time)
* BUILD_COMMIT: be6ef87ab40e8747994d32363389cf39e36a4326
*/
import { j as a, az as L, aA as k, l as N, aB as q, aC as G, au as J, aD as y, aE as K, aF as z, aG as Y, h as W, aH as Q, aI as X } from "./es6-N0LU_o1K.js";
import { FormattedHTMLMessage as c } from "react-intl";
import { useState as u, useCallback as f, useEffect as Z, useMemo as j } from "react";
const T = ({
title: t,
message: s,
closing: i,
helpRequestResponse: l = "blue",
onResendClick: o
}) => {
const [e, m] = u(!1), g = async () => {
o && (await o(), m(!0));
};
return /* @__PURE__ */ a.jsxs(
"div",
{
className: l === "green" ? "sid-email-msg-container sid-l-horz-center sid-l-space-top-md sid-email-msg-container--bg-green" : "sid-email-msg-container sid-l-horz-center sid-l-space-top-md sid-email-msg-container--bg-blue",
children: [
/* @__PURE__ */ a.jsx("div", { className: "sid-email-msg-container__title", children: t }),
/* @__PURE__ */ a.jsx("div", { className: "sid-email-msg-container__content", children: s }),
/* @__PURE__ */ a.jsx("div", { className: "sid-email-msg-container__content sid-email-msg-container__closing", children: i }),
/* @__PURE__ */ a.jsx("div", { className: "sid-email-resend-area", children: /* @__PURE__ */ a.jsx(
"button",
{
type: "button",
className: e ? "sid-email-resend-area__button sid-email-resend-area__button__sent" : "sid-email-resend-area__button",
onClick: g,
disabled: e,
children: /* @__PURE__ */ a.jsx(
c,
{
id: e ? "step.personalInfo.emailFirstCollectInfo.sent" : "step.personalInfo.emailFirstCollectInfo.sendAgain",
defaultMessage: e ? "Sent!" : "Send Again"
}
)
}
) })
]
}
);
};
var n = /* @__PURE__ */ ((t) => (t.FOUND = "existingVerificationFound", t.NOT_FOUND = "existingVerificationNotFound", t.PENDING = "pendingVerification", t.REJECTED = "rejectedVerification", t.ALREADY_INITIATED = "emailResendAlreadyInitiated", t))(n || {});
const ae = ({
emailLookupResponse: t,
onResendClick: s = async () => {
},
onHandleClickLink: i = async () => {
}
}) => t.status === n.FOUND && t.message === "success" ? /* @__PURE__ */ a.jsx(
T,
{
title: /* @__PURE__ */ a.jsx(
c,
{
id: "step.personalInfo.emailFirstCollectInfo.existingVerificationFound.title",
defaultMessage: "You've been here before!"
}
),
message: /* @__PURE__ */ a.jsx(
c,
{
id: "step.personalInfo.emailFirstCollectInfo.existingVerificationFound.message",
defaultMessage: "Verify@sheerid.com re-sent your confirmation email with details on redeeming your verified offer."
}
),
closing: /* @__PURE__ */ a.jsx(
c,
{
id: "step.personalInfo.emailFirstCollectInfo.existingVerificationFound.closing",
defaultMessage: "Enjoy!"
}
),
helpRequestResponse: "green",
onResendClick: s
}
) : t.status === n.FOUND && t.message !== "success" ? /* @__PURE__ */ a.jsxs(a.Fragment, { children: [
/* @__PURE__ */ a.jsx(
T,
{
title: /* @__PURE__ */ a.jsx(
c,
{
id: "step.personalInfo.emailFirstCollectInfo.pendingVerification.title",
defaultMessage: "Looks like you started."
}
),
message: /* @__PURE__ */ a.jsx(
c,
{
id: "step.personalInfo.emailFirstCollectInfo.pendingVerification.message",
defaultMessage: "This email is associated with a verification in the works."
}
),
closing: /* @__PURE__ */ a.jsx(
c,
{
id: "step.personalInfo.emailFirstCollectInfo.pendingVerification.closing",
defaultMessage: "Verify@sheerid.com re-sent our last email to you with next steps."
}
),
helpRequestResponse: "blue",
onResendClick: s
}
),
/* @__PURE__ */ a.jsxs("div", { className: "sid-email-first__need-changes sid-h-small-text", children: [
/* @__PURE__ */ a.jsx(
c,
{
id: "step.personalInfo.emailFirstCollectInfo.needChanges",
defaultMessage: "Need to make changes?"
}
),
/* @__PURE__ */ a.jsx(
"button",
{
type: "submit",
className: "sid-email-first__need-changes-link sid-link",
onClick: i,
children: /* @__PURE__ */ a.jsx(
c,
{
id: "step.personalInfo.emailFirstCollectInfo.proceedHere",
defaultMessage: "Proceed here"
}
)
}
)
] })
] }) : null, $ = {
Accept: "application/json",
"Content-Type": "application/json"
}, ee = async (t, s = void 0, i = {}) => {
const l = q(), o = {
emailAddress: s,
programId: t
};
try {
const e = await G(l, {
headers: { ...$, ...i },
method: "POST",
body: JSON.stringify(o)
});
return { ...await e.json(), status: e.status };
} catch (e) {
return N.error("Error in submitVerificationHelpRequest:", e), {
systemErrorMessage: "An error occurred during the request.",
status: 500
};
}
};
async function b(t, s) {
try {
const i = await ee(
t,
s
);
let l = n.PENDING, o = null;
return i.status === 500 ? (l = n.NOT_FOUND, o = "Error during lookup.") : i.status === 404 || i.status === 429 ? l = n.NOT_FOUND : i.status === 400 ? l = n.ALREADY_INITIATED : i.status === 200 && (i.currentStep === "error" || i.currentStep === "docReviewLimitExceeded" ? (l = n.NOT_FOUND, o = "An error occurred during verification.") : i.currentStep === "pending" || i.currentStep === "consolation" || i.currentStep === "loading" ? (l = n.PENDING, o = "pending") : i.currentStep.toLowerCase().startsWith("collect") ? o = "Unexpected API response." : (l = n.FOUND, o = i.currentStep)), L({ eventName: k.VERIFICATION_HELP, params: { status: l, programId: t } }), { status: l, message: o };
} catch (i) {
return N.error("Error submitting verification help request:", i), {
status: n.PENDING,
message: "Error during lookup."
};
}
}
function ne(t, s, i) {
const [l, o] = u(!1), [e, m] = u(null), g = J("collect-info-step-email-first"), p = g === "no-message-dimmed-fields", [O, _] = u(!1), [D, M] = u(!1), [x, w] = u(!1), [d, U] = u({
emailLookupResponse: null,
hasBlurred: !1,
hasKeyPressed: !1,
isValidEmail: !y(s)
}), { userDidConvert: S } = K(i), V = f((r) => {
const h = !y(r);
U((E) => ({
...E,
emailLookupResponse: r !== "" && h ? null : E.emailLookupResponse,
hasBlurred: !1,
hasKeyPressed: !1,
isValidEmail: h
}));
}, []);
Z(() => {
V(s);
}, [s, V]);
const v = j(
() => s !== "" && d.isValidEmail && (!p || (e == null ? void 0 : e.status) === n.NOT_FOUND),
[s, d.isValidEmail, p, e]
), A = j(
() => (s === "" || typeof s == "string" && s.length >= 1 || (e == null ? void 0 : e.status) === null) && ((e == null ? void 0 : e.status) === n.NOT_FOUND || ![
n.ALREADY_INITIATED,
n.FOUND,
n.PENDING,
n.REJECTED
].includes(e == null ? void 0 : e.status)),
[s, e]
), F = f(async () => {
if (!(!d.isValidEmail || O || x)) {
M(!0), _(!1), o(!0);
try {
const r = await b(t, s);
r.status === n.FOUND && S(z, Y), m(r);
} catch (r) {
N.error("Error during email lookup:", r);
} finally {
o(!1);
}
}
}, [t, s, O, x, d.isValidEmail]), P = f(
(r) => {
D || r.key === "Enter" && (w(!0), F());
},
[F, D]
), R = f(async () => {
o(!0);
try {
const r = await b(
t,
s
);
m(r);
} catch (r) {
N.error("Error resending email:", r);
} finally {
o(!1);
}
}, [t, s, i]), B = f(async () => {
d.isValidEmail && (_(!0), m({
status: n.NOT_FOUND,
message: "makeChanges"
}));
}, [d.isValidEmail]), H = f(
async (r) => {
if (!r) return;
const h = W(
r.viewModel,
r.programTheme
), E = Q(s), C = new URL(h);
C.searchParams.set("domain", E);
const I = await X(C.toString());
return I && I.length === 1 ? I[0] : void 0;
},
[s]
);
return p ? {
isEmailUpTop: p,
isEmailValidationLoading: l,
emailLookupResponse: e,
showEmailLookupResponseMessages: !!e,
showFormFields: A,
emailOnBlur: F,
emailOnKeyDown: P,
handleResendClick: R,
emailFirstCollectInfoStep: g,
isValidEmail: d.isValidEmail,
getOrgByDomain: H,
enableFormFields: v,
handleOnClickProceedHere: B
} : {
isEmailUpTop: p,
isEmailValidationLoading: !1,
showOtherFields: !0,
disableOtherFields: !1,
emailLookupResponse: null,
showEmailLookupResponseMessages: !1,
showFormFields: !0,
emailOnBlur: () => {
},
emailOnKeyDown: () => {
},
handleResendClick: () => Promise.resolve(),
emailFirstCollectInfoStep: g,
isValidEmail: !y(s),
getOrgByDomain: async () => {
},
enableFormFields: !0
};
}
export {
ae as E,
n as a,
ne as u
};