@sheerid/jslib-nightly
Version:
SheerID JavaScript Library
292 lines (290 loc) • 9.61 kB
JavaScript
/**
* WARNING: This file is intended to be used within MySheerID.
* This file is not intended for use in other contexts and there are no guarantees about its behavior outside of MySheerID.
*/
/**
* VERSION: 2.130.0-alpha.4
* BUILD_TIMESTAMP: 1759000347595
* BUILD_DATE: Sat Sep 27 2025 19:12:27 GMT+0000 (Coordinated Universal Time)
* BUILD_COMMIT: be6ef87ab40e8747994d32363389cf39e36a4326
*/
import { t as l, j as i, b as d, ao as R, ap as L, l as E, aq as B, ar as H, aj as q, as as I, at as G, au as J, av as K, a as Y, aw as z, ax as W } from "../_mysheerid-preview.js";
const V = ({
title: t,
message: s,
closing: a,
helpRequestResponse: c = "blue",
onResendClick: o
}) => {
const [e, m] = l.useState(!1), f = async () => {
o && (await o(), m(!0));
};
return /* @__PURE__ */ i.jsxs(
"div",
{
className: c === "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__ */ i.jsx("div", { className: "sid-email-msg-container__title", children: t }),
/* @__PURE__ */ i.jsx("div", { className: "sid-email-msg-container__content", children: s }),
/* @__PURE__ */ i.jsx("div", { className: "sid-email-msg-container__content sid-email-msg-container__closing", children: a }),
/* @__PURE__ */ i.jsx("div", { className: "sid-email-resend-area", children: /* @__PURE__ */ i.jsx(
"button",
{
type: "button",
className: e ? "sid-email-resend-area__button sid-email-resend-area__button__sent" : "sid-email-resend-area__button",
onClick: f,
disabled: e,
children: /* @__PURE__ */ i.jsx(
d,
{
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 $ = ({
emailLookupResponse: t,
onResendClick: s = async () => {
},
onHandleClickLink: a = async () => {
}
}) => t.status === n.FOUND && t.message === "success" ? /* @__PURE__ */ i.jsx(
V,
{
title: /* @__PURE__ */ i.jsx(
d,
{
id: "step.personalInfo.emailFirstCollectInfo.existingVerificationFound.title",
defaultMessage: "You've been here before!"
}
),
message: /* @__PURE__ */ i.jsx(
d,
{
id: "step.personalInfo.emailFirstCollectInfo.existingVerificationFound.message",
defaultMessage: "Verify@sheerid.com re-sent your confirmation email with details on redeeming your verified offer."
}
),
closing: /* @__PURE__ */ i.jsx(
d,
{
id: "step.personalInfo.emailFirstCollectInfo.existingVerificationFound.closing",
defaultMessage: "Enjoy!"
}
),
helpRequestResponse: "green",
onResendClick: s
}
) : t.status === n.FOUND && t.message !== "success" ? /* @__PURE__ */ i.jsxs(i.Fragment, { children: [
/* @__PURE__ */ i.jsx(
V,
{
title: /* @__PURE__ */ i.jsx(
d,
{
id: "step.personalInfo.emailFirstCollectInfo.pendingVerification.title",
defaultMessage: "Looks like you started."
}
),
message: /* @__PURE__ */ i.jsx(
d,
{
id: "step.personalInfo.emailFirstCollectInfo.pendingVerification.message",
defaultMessage: "This email is associated with a verification in the works."
}
),
closing: /* @__PURE__ */ i.jsx(
d,
{
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__ */ i.jsxs("div", { className: "sid-email-first__need-changes sid-h-small-text", children: [
/* @__PURE__ */ i.jsx(
d,
{
id: "step.personalInfo.emailFirstCollectInfo.needChanges",
defaultMessage: "Need to make changes?"
}
),
/* @__PURE__ */ i.jsx(
"button",
{
type: "submit",
className: "sid-email-first__need-changes-link sid-link",
onClick: a,
children: /* @__PURE__ */ i.jsx(
d,
{
id: "step.personalInfo.emailFirstCollectInfo.proceedHere",
defaultMessage: "Proceed here"
}
)
}
)
] })
] }) : null, Q = {
Accept: "application/json",
"Content-Type": "application/json"
}, X = async (t, s = void 0, a = {}) => {
const c = B(), o = {
emailAddress: s,
programId: t
};
try {
const e = await H(c, {
headers: { ...Q, ...a },
method: "POST",
body: JSON.stringify(o)
});
return { ...await e.json(), status: e.status };
} catch (e) {
return E.error("Error in submitVerificationHelpRequest:", e), {
systemErrorMessage: "An error occurred during the request.",
status: 500
};
}
};
async function b(t, s) {
try {
const a = await X(
t,
s
);
let c = n.PENDING, o = null;
return a.status === 500 ? (c = n.NOT_FOUND, o = "Error during lookup.") : a.status === 404 || a.status === 429 ? c = n.NOT_FOUND : a.status === 400 ? c = n.ALREADY_INITIATED : a.status === 200 && (a.currentStep === "error" || a.currentStep === "docReviewLimitExceeded" ? (c = n.NOT_FOUND, o = "An error occurred during verification.") : a.currentStep === "pending" || a.currentStep === "consolation" || a.currentStep === "loading" ? (c = n.PENDING, o = "pending") : a.currentStep.toLowerCase().startsWith("collect") ? o = "Unexpected API response." : (c = n.FOUND, o = a.currentStep)), R({ eventName: L.VERIFICATION_HELP, params: { status: c, programId: t } }), { status: c, message: o };
} catch (a) {
return E.error("Error submitting verification help request:", a), {
status: n.PENDING,
message: "Error during lookup."
};
}
}
function ee(t, s, a) {
const [c, o] = l.useState(!1), [e, m] = l.useState(null), f = q("collect-info-step-email-first"), g = f === "no-message-dimmed-fields", [y, O] = l.useState(!1), [_, j] = l.useState(!1), [x, T] = l.useState(!1), [u, S] = l.useState({
emailLookupResponse: null,
hasBlurred: !1,
hasKeyPressed: !1,
isValidEmail: !I(s)
}), { userDidConvert: M } = G(a), C = l.useCallback((r) => {
const p = !I(r);
S((h) => ({
...h,
emailLookupResponse: r !== "" && p ? null : h.emailLookupResponse,
hasBlurred: !1,
hasKeyPressed: !1,
isValidEmail: p
}));
}, []);
l.useEffect(() => {
C(s);
}, [s, C]);
const w = l.useMemo(
() => s !== "" && u.isValidEmail && (!g || (e == null ? void 0 : e.status) === n.NOT_FOUND),
[s, u.isValidEmail, g, e]
), U = l.useMemo(
() => (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]
), N = l.useCallback(async () => {
if (!(!u.isValidEmail || y || x)) {
j(!0), O(!1), o(!0);
try {
const r = await b(t, s);
r.status === n.FOUND && M(J, K), m(r);
} catch (r) {
E.error("Error during email lookup:", r);
} finally {
o(!1);
}
}
}, [t, s, y, x, u.isValidEmail]), v = l.useCallback(
(r) => {
_ || r.key === "Enter" && (T(!0), N());
},
[N, _]
), k = l.useCallback(async () => {
o(!0);
try {
const r = await b(
t,
s
);
m(r);
} catch (r) {
E.error("Error resending email:", r);
} finally {
o(!1);
}
}, [t, s, a]), A = l.useCallback(async () => {
u.isValidEmail && (O(!0), m({
status: n.NOT_FOUND,
message: "makeChanges"
}));
}, [u.isValidEmail]), P = l.useCallback(
async (r) => {
if (!r) return;
const p = Y(
r.viewModel,
r.programTheme
), h = z(s), D = new URL(p);
D.searchParams.set("domain", h);
const F = await W(D.toString());
return F && F.length === 1 ? F[0] : void 0;
},
[s]
);
return g ? {
isEmailUpTop: g,
isEmailValidationLoading: c,
emailLookupResponse: e,
showEmailLookupResponseMessages: !!e,
showFormFields: U,
emailOnBlur: N,
emailOnKeyDown: v,
handleResendClick: k,
emailFirstCollectInfoStep: f,
isValidEmail: u.isValidEmail,
getOrgByDomain: P,
enableFormFields: w,
handleOnClickProceedHere: A
} : {
isEmailUpTop: g,
isEmailValidationLoading: !1,
showOtherFields: !0,
disableOtherFields: !1,
emailLookupResponse: null,
showEmailLookupResponseMessages: !1,
showFormFields: !0,
emailOnBlur: () => {
},
emailOnKeyDown: () => {
},
handleResendClick: () => Promise.resolve(),
emailFirstCollectInfoStep: f,
isValidEmail: !I(s),
getOrgByDomain: async () => {
},
enableFormFields: !0
};
}
export {
$ as E,
n as a,
ee as u
};