Show Login and Ask an organizer sent and error states.
Connect the live modals to the drawn sent, expired, invalid-email, and send-failed screens, pin the phone footer above the keyboard, and send the light login email.
This commit is contained in:
1 parent
44010c7b73
commit
27d74e510c
29 files changed
+771
-281
No files matched your search
@@ -1,8 +1,8 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Figma: Community Rule System — Modal / Ask an Organizer (22078-587823)
|
||||
* File: agv0VBLiBlcnSAaiAORgPR, node 22078-587823
|
||||
* Figma: Overlay / Modal / Ask an Organizer (22078:587823)
|
||||
* Sent 25032:48584, send failed 25032:48642
|
||||
*/
|
||||
|
||||
import { memo, useCallback, useEffect, useMemo, useState, type FormEvent } from "react";
|
||||
@@ -11,6 +11,8 @@ import type { AskOrganizerInquiryModalProps } from "./AskOrganizerInquiryModal.t
|
||||
import { ORGANIZER_INQUIRY_HONEYPOT_FIELD } from "../../../../lib/organizerInquiryConstants";
|
||||
import { useTranslation } from "../../../contexts/MessagesContext";
|
||||
|
||||
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
|
||||
const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
({ isOpen, onClose }) => {
|
||||
const t = useTranslation("modals.askOrganizerInquiry");
|
||||
@@ -27,6 +29,8 @@ const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
closeAfterSuccess: t("closeAfterSuccess"),
|
||||
successTitle: t("successTitle"),
|
||||
successDescription: t("successDescription"),
|
||||
sendFailedTitle: t("sendFailedTitle"),
|
||||
sendFailedDescription: t("sendFailedDescription"),
|
||||
ariaDialog: t("ariaDialog"),
|
||||
honeypotLabel: t("honeypotLabel"),
|
||||
backToHome: tLogin("backToHome"),
|
||||
@@ -38,7 +42,7 @@ const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
const [honeypot, setHoneypot] = useState("");
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [success, setSuccess] = useState(false);
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
const [sendFailed, setSendFailed] = useState(false);
|
||||
const [emailError, setEmailError] = useState(false);
|
||||
const [questionError, setQuestionError] = useState(false);
|
||||
|
||||
@@ -49,7 +53,7 @@ const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
setHoneypot("");
|
||||
setSubmitting(false);
|
||||
setSuccess(false);
|
||||
setFormError(null);
|
||||
setSendFailed(false);
|
||||
setEmailError(false);
|
||||
setQuestionError(false);
|
||||
}
|
||||
@@ -58,9 +62,21 @@ const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
const onSubmit = useCallback(
|
||||
async (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setFormError(null);
|
||||
setSendFailed(false);
|
||||
setEmailError(false);
|
||||
setQuestionError(false);
|
||||
|
||||
const trimmedEmail = email.trim().toLowerCase();
|
||||
const trimmedMessage = message.trim();
|
||||
if (!EMAIL_PATTERN.test(trimmedEmail)) {
|
||||
setEmailError(true);
|
||||
return;
|
||||
}
|
||||
if (trimmedMessage.length < 10) {
|
||||
setQuestionError(true);
|
||||
return;
|
||||
}
|
||||
|
||||
setSubmitting(true);
|
||||
|
||||
try {
|
||||
@@ -68,8 +84,8 @@ const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
message,
|
||||
email: trimmedEmail,
|
||||
message: trimmedMessage,
|
||||
[ORGANIZER_INQUIRY_HONEYPOT_FIELD]: honeypot,
|
||||
}),
|
||||
});
|
||||
@@ -81,40 +97,43 @@ const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.status === 429) {
|
||||
setFormError(t("rateLimitedError"));
|
||||
if (res.status === 400) {
|
||||
let nextEmailError = false;
|
||||
let nextQuestionError = false;
|
||||
if (
|
||||
data &&
|
||||
typeof data === "object" &&
|
||||
"error" in data &&
|
||||
data.error &&
|
||||
typeof data.error === "object" &&
|
||||
"message" in data.error &&
|
||||
typeof (data.error as { message: unknown }).message === "string"
|
||||
) {
|
||||
const msg = (data.error as { message: string }).message;
|
||||
const lower = msg.toLowerCase();
|
||||
if (lower.includes("email")) {
|
||||
nextEmailError = true;
|
||||
}
|
||||
if (lower.includes("character") || lower.includes("question")) {
|
||||
nextQuestionError = true;
|
||||
}
|
||||
}
|
||||
setEmailError(nextEmailError);
|
||||
setQuestionError(nextQuestionError);
|
||||
if (!nextEmailError && !nextQuestionError) {
|
||||
setSendFailed(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
data &&
|
||||
typeof data === "object" &&
|
||||
"error" in data &&
|
||||
data.error &&
|
||||
typeof data.error === "object" &&
|
||||
"message" in data.error &&
|
||||
typeof (data.error as { message: unknown }).message === "string"
|
||||
) {
|
||||
const msg = (data.error as { message: string }).message;
|
||||
const lower = msg.toLowerCase();
|
||||
if (lower.includes("email")) {
|
||||
setEmailError(true);
|
||||
}
|
||||
if (lower.includes("character") || lower.includes("question")) {
|
||||
setQuestionError(true);
|
||||
}
|
||||
setFormError(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
setFormError(t("genericError"));
|
||||
setSendFailed(true);
|
||||
} catch {
|
||||
setFormError(t("genericError"));
|
||||
setSendFailed(true);
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
},
|
||||
[email, message, honeypot, t],
|
||||
[email, message, honeypot],
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -127,13 +146,14 @@ const AskOrganizerInquiryModalContainer = memo<AskOrganizerInquiryModalProps>(
|
||||
honeypot={honeypot}
|
||||
submitting={submitting}
|
||||
success={success}
|
||||
formError={formError}
|
||||
sendFailed={sendFailed}
|
||||
emailError={emailError}
|
||||
questionError={questionError}
|
||||
onEmailChange={setEmail}
|
||||
onMessageChange={setMessage}
|
||||
onHoneypotChange={setHoneypot}
|
||||
onSubmit={onSubmit}
|
||||
onDismissFailed={() => setSendFailed(false)}
|
||||
/>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface AskOrganizerInquiryModalCopy {
|
||||
closeAfterSuccess: string;
|
||||
successTitle: string;
|
||||
successDescription: string;
|
||||
sendFailedTitle: string;
|
||||
sendFailedDescription: string;
|
||||
ariaDialog: string;
|
||||
honeypotLabel: string;
|
||||
backToHome: string;
|
||||
@@ -27,11 +29,12 @@ export interface AskOrganizerInquiryModalViewProps
|
||||
honeypot: string;
|
||||
submitting: boolean;
|
||||
success: boolean;
|
||||
formError: string | null;
|
||||
sendFailed: boolean;
|
||||
emailError: boolean;
|
||||
questionError: boolean;
|
||||
onEmailChange: (_v: string) => void;
|
||||
onMessageChange: (_v: string) => void;
|
||||
onHoneypotChange: (_v: string) => void;
|
||||
onSubmit: (_e: import("react").FormEvent<HTMLFormElement>) => void;
|
||||
onDismissFailed: () => void;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import Create from "../Create";
|
||||
import TextInput from "../../controls/TextInput";
|
||||
import TextArea from "../../controls/TextArea";
|
||||
import Button from "../../buttons/Button";
|
||||
import Alert from "../Alert";
|
||||
import {
|
||||
ASK_ORGANIZER_INQUIRY_FORM_ID,
|
||||
ORGANIZER_INQUIRY_HONEYPOT_FIELD,
|
||||
@@ -12,7 +13,8 @@ import {
|
||||
import type { AskOrganizerInquiryModalViewProps } from "./AskOrganizerInquiryModal.types";
|
||||
|
||||
/**
|
||||
* Figma: Community Rule System — Modal / Ask an Organizer (22078-587823)
|
||||
* Figma: Overlay / Modal / Ask an Organizer (22078:587823)
|
||||
* Sent 25032:48584, send failed 25032:48642
|
||||
*/
|
||||
export function AskOrganizerInquiryModalView({
|
||||
isOpen,
|
||||
@@ -23,40 +25,58 @@ export function AskOrganizerInquiryModalView({
|
||||
honeypot,
|
||||
submitting,
|
||||
success,
|
||||
formError,
|
||||
sendFailed,
|
||||
emailError,
|
||||
questionError,
|
||||
onEmailChange,
|
||||
onMessageChange,
|
||||
onHoneypotChange,
|
||||
onSubmit,
|
||||
onDismissFailed,
|
||||
}: AskOrganizerInquiryModalViewProps) {
|
||||
const footer = success ? (
|
||||
<div className="w-full px-1">
|
||||
<Button
|
||||
type="button"
|
||||
buttonType="filled"
|
||||
palette="default"
|
||||
size="large"
|
||||
className="w-full !justify-center"
|
||||
onClick={onClose}
|
||||
>
|
||||
{copy.closeAfterSuccess}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full px-1">
|
||||
<Button
|
||||
type="submit"
|
||||
form={ASK_ORGANIZER_INQUIRY_FORM_ID}
|
||||
buttonType="filled"
|
||||
palette="default"
|
||||
size="large"
|
||||
className="w-full !justify-center"
|
||||
disabled={submitting}
|
||||
>
|
||||
{copy.submitButton}
|
||||
</Button>
|
||||
const failedToast = sendFailed ? (
|
||||
<Alert
|
||||
type="toast"
|
||||
status="danger"
|
||||
size="s"
|
||||
title={copy.sendFailedTitle}
|
||||
description={copy.sendFailedDescription}
|
||||
hasLeadingIcon
|
||||
hasBodyText
|
||||
hasTrailingIcon={false}
|
||||
onClose={onDismissFailed}
|
||||
className="w-full"
|
||||
/>
|
||||
) : null;
|
||||
|
||||
const footer = (
|
||||
<div className="flex w-full flex-col gap-4 px-1">
|
||||
<div className="md:hidden">{failedToast}</div>
|
||||
{success ? (
|
||||
<Button
|
||||
type="button"
|
||||
buttonType="filled"
|
||||
palette="default"
|
||||
size="large"
|
||||
className="w-full !justify-center"
|
||||
autoFocus
|
||||
onClick={onClose}
|
||||
>
|
||||
{copy.closeAfterSuccess}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
type="submit"
|
||||
form={ASK_ORGANIZER_INQUIRY_FORM_ID}
|
||||
buttonType="filled"
|
||||
palette="default"
|
||||
size="large"
|
||||
className="w-full !justify-center"
|
||||
disabled={submitting}
|
||||
>
|
||||
{copy.submitButton}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -64,9 +84,10 @@ export function AskOrganizerInquiryModalView({
|
||||
<Create
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
presentation="sheet"
|
||||
backdropVariant="blurredYellow"
|
||||
title={copy.title}
|
||||
description={copy.description}
|
||||
title={success ? copy.successTitle : copy.title}
|
||||
description={success ? copy.successDescription : copy.description}
|
||||
showBackButton={false}
|
||||
showNextButton={false}
|
||||
stepper={false}
|
||||
@@ -74,40 +95,27 @@ export function AskOrganizerInquiryModalView({
|
||||
footerContent={footer}
|
||||
footerClassName="!h-auto min-h-[112px] shrink-0 flex flex-col justify-end pb-8 pt-3 px-4"
|
||||
belowCard={
|
||||
<Link
|
||||
href="/"
|
||||
className="text-small-paragraph text-[var(--color-content-invert-tertiary,#2d2d2d)] text-center hover:opacity-90"
|
||||
onClick={() => onClose()}
|
||||
>
|
||||
{copy.backToHome}
|
||||
</Link>
|
||||
success ? undefined : (
|
||||
<div className="flex w-full max-w-[546px] flex-col items-center gap-6">
|
||||
<div className="hidden w-full md:block">{failedToast}</div>
|
||||
<Link
|
||||
href="/"
|
||||
className="text-small-paragraph text-[var(--color-content-invert-tertiary,#2d2d2d)] text-center hover:opacity-90"
|
||||
onClick={() => onClose()}
|
||||
>
|
||||
{copy.backToHome}
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
>
|
||||
{success ? (
|
||||
<div className="flex flex-col gap-3 py-2">
|
||||
<p className="text-large-label text-[var(--color-content-default-primary)]">
|
||||
{copy.successTitle}
|
||||
</p>
|
||||
<p className="text-small-paragraph text-[var(--color-content-default-secondary)]">
|
||||
{copy.successDescription}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
{success ? null : (
|
||||
<form
|
||||
id={ASK_ORGANIZER_INQUIRY_FORM_ID}
|
||||
className="relative flex flex-col gap-6 pb-2"
|
||||
onSubmit={onSubmit}
|
||||
noValidate
|
||||
>
|
||||
{formError ? (
|
||||
<p
|
||||
role="alert"
|
||||
className="text-small-paragraph text-[var(--color-border-default-negative-primary)]"
|
||||
>
|
||||
{formError}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<TextInput
|
||||
type="email"
|
||||
name="email"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import { memo, useRef } from "react";
|
||||
import { useVisualViewportHeight } from "../../../hooks";
|
||||
import { CreateView } from "./Create.view";
|
||||
import type { CreateProps } from "./Create.types";
|
||||
import { useCreateModalA11y } from "./useCreateModalA11y";
|
||||
@@ -43,9 +44,13 @@ const CreateContainer = memo<CreateProps>(
|
||||
kebabMenuAriaLabel,
|
||||
kebabMenuItems,
|
||||
belowCard,
|
||||
presentation = "dialog",
|
||||
}) => {
|
||||
const createRef = useRef<HTMLDivElement>(null);
|
||||
const overlayRef = useRef<HTMLDivElement>(null);
|
||||
const viewportHeight = useVisualViewportHeight(
|
||||
isOpen && presentation === "sheet",
|
||||
);
|
||||
|
||||
useCreateModalA11y(isOpen, onClose, createRef);
|
||||
|
||||
@@ -86,6 +91,8 @@ const CreateContainer = memo<CreateProps>(
|
||||
kebabMenuAriaLabel={kebabMenuAriaLabel}
|
||||
kebabMenuItems={kebabMenuItems}
|
||||
belowCard={belowCard}
|
||||
presentation={presentation}
|
||||
viewportHeight={viewportHeight}
|
||||
/>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import type { RefObject } from "react";
|
||||
import type { CreateModalBackdropVariant } from "./CreateModalFrame.view";
|
||||
import type {
|
||||
CreateModalBackdropVariant,
|
||||
CreateModalPresentationValue,
|
||||
} from "./CreateModalFrame.view";
|
||||
import type { ModalHeaderMenuItem } from "../ModalHeader/ModalHeader.types";
|
||||
|
||||
export interface CreateProps {
|
||||
@@ -51,6 +54,8 @@ export interface CreateProps {
|
||||
kebabMenuItems?: ModalHeaderMenuItem[];
|
||||
/** Rendered below the dialog card on the backdrop (e.g. “Back to home”). */
|
||||
belowCard?: React.ReactNode;
|
||||
/** `sheet` is the phone full-viewport layout used by Ask an organizer. */
|
||||
presentation?: CreateModalPresentationValue;
|
||||
}
|
||||
|
||||
export interface CreateViewProps {
|
||||
@@ -88,4 +93,6 @@ export interface CreateViewProps {
|
||||
kebabMenuAriaLabel?: string;
|
||||
kebabMenuItems?: ModalHeaderMenuItem[];
|
||||
belowCard?: React.ReactNode;
|
||||
presentation: CreateModalPresentationValue;
|
||||
viewportHeight?: number;
|
||||
}
|
||||
@@ -41,6 +41,8 @@ export function CreateView({
|
||||
kebabMenuAriaLabel,
|
||||
kebabMenuItems,
|
||||
belowCard,
|
||||
presentation,
|
||||
viewportHeight,
|
||||
}: CreateViewProps) {
|
||||
return (
|
||||
<CreateModalFrameView
|
||||
@@ -53,6 +55,8 @@ export function CreateView({
|
||||
overlayRef={overlayRef}
|
||||
dialogRef={createRef}
|
||||
belowCard={belowCard}
|
||||
presentation={presentation}
|
||||
viewportHeight={viewportHeight}
|
||||
>
|
||||
<ModalHeader
|
||||
onClose={onClose}
|
||||
|
||||
@@ -31,6 +31,8 @@ export type CreateModalFrameViewProps = {
|
||||
* from `md`. `dialog` is the centered card used by Create and Dialog.
|
||||
*/
|
||||
presentation?: CreateModalPresentationValue;
|
||||
/** Visible viewport height so a phone sheet footer rides above the keyboard. */
|
||||
viewportHeight?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -48,6 +50,7 @@ export function CreateModalFrameView({
|
||||
children,
|
||||
belowCard,
|
||||
presentation = "dialog",
|
||||
viewportHeight,
|
||||
}: CreateModalFrameViewProps) {
|
||||
if (!isOpen) return null;
|
||||
|
||||
@@ -55,14 +58,21 @@ export function CreateModalFrameView({
|
||||
const overlayLayout = isSheet
|
||||
? "flex flex-col items-stretch justify-end overflow-hidden p-0 md:items-center md:justify-center md:gap-6 md:overflow-y-auto md:px-4 md:py-8"
|
||||
: "flex flex-col items-center justify-center gap-6 overflow-y-auto px-4 py-8";
|
||||
const sheetHeight =
|
||||
viewportHeight != null ? "h-full max-h-full" : "h-dvh max-h-dvh";
|
||||
const dialogShell = isSheet
|
||||
? "flex h-dvh max-h-dvh min-h-0 w-full shrink-0 flex-col overflow-hidden rounded-none bg-[var(--color-surface-default-primary)] shadow-[0px_0px_48px_0px_rgba(0,0,0,0.1)] z-[9999] md:h-auto md:max-h-[90vh] md:w-[546px] md:max-w-[546px] md:rounded-[var(--radius-500)]"
|
||||
? `flex ${sheetHeight} min-h-0 w-full shrink-0 flex-col overflow-hidden rounded-none bg-[var(--color-surface-default-primary)] shadow-[0px_0px_48px_0px_rgba(0,0,0,0.1)] z-[9999] md:h-auto md:max-h-[90vh] md:w-[546px] md:max-w-[546px] md:rounded-[var(--radius-500)]`
|
||||
: "flex min-h-0 max-h-[90vh] w-full max-w-[560px] shrink-0 flex-col overflow-hidden rounded-[var(--radius-500)] bg-[var(--color-surface-default-primary)] shadow-[0px_0px_48px_0px_rgba(0,0,0,0.1)] z-[9999]";
|
||||
const overlayStyle =
|
||||
isSheet && viewportHeight != null
|
||||
? { height: viewportHeight, maxHeight: viewportHeight }
|
||||
: undefined;
|
||||
|
||||
const content = (
|
||||
<div
|
||||
ref={overlayRef}
|
||||
className={`${backdropOverlayClasses[backdropVariant]} ${overlayLayout}`}
|
||||
style={overlayStyle}
|
||||
onClick={onOverlayClick}
|
||||
role="presentation"
|
||||
>
|
||||
@@ -78,7 +88,10 @@ export function CreateModalFrameView({
|
||||
{children}
|
||||
</div>
|
||||
{belowCard ? (
|
||||
<div className="shrink-0" onClick={(e) => e.stopPropagation()}>
|
||||
<div
|
||||
className={`shrink-0 ${isSheet ? "hidden md:block" : ""}`}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{belowCard}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -6,6 +6,20 @@ import { useEffect, useLayoutEffect, useRef } from "react";
|
||||
const FOCUSABLE_SELECTOR =
|
||||
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
|
||||
|
||||
const FIELD_SELECTOR =
|
||||
'input:not([type="hidden"]):not([type="checkbox"]):not([disabled]):not([tabindex="-1"]), textarea:not([disabled]):not([tabindex="-1"])';
|
||||
|
||||
function initialFocus(dialog: HTMLElement): HTMLElement | undefined {
|
||||
const email = dialog.querySelector<HTMLElement>(
|
||||
'input[type="email"]:not([disabled]):not([tabindex="-1"])',
|
||||
);
|
||||
if (email) return email;
|
||||
const field = dialog.querySelector<HTMLElement>(FIELD_SELECTOR);
|
||||
if (field) return field;
|
||||
const focusable = dialog.querySelectorAll(FOCUSABLE_SELECTOR);
|
||||
return focusable[0] as HTMLElement | undefined;
|
||||
}
|
||||
|
||||
let lastInteractedFocusable: HTMLElement | null = null;
|
||||
let interactionTrackingBound = false;
|
||||
|
||||
@@ -118,10 +132,7 @@ export function useCreateModalA11y(
|
||||
document.body.style.overflow = "hidden";
|
||||
|
||||
if (dialogRef.current) {
|
||||
const focusableElements = dialogRef.current.querySelectorAll(
|
||||
FOCUSABLE_SELECTOR,
|
||||
);
|
||||
const firstElement = focusableElements[0] as HTMLElement | undefined;
|
||||
const firstElement = initialFocus(dialogRef.current);
|
||||
if (firstElement) {
|
||||
firstElement.focus();
|
||||
} else {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Figma: "Modal / Login" (see registry)
|
||||
* Figma: Overlay / Modal / Login (22078:587823)
|
||||
* Sent 25032:48263, link expired 25032:48370, invalid email 25032:48477
|
||||
*/
|
||||
|
||||
import { memo, useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import { useVisualViewportHeight } from "../../../hooks";
|
||||
import { LoginView } from "./Login.view";
|
||||
import type { LoginProps } from "./Login.types";
|
||||
|
||||
@@ -24,9 +26,7 @@ const LoginContainer = memo<LoginProps>(
|
||||
const backdropRef = useRef<HTMLDivElement>(null);
|
||||
const previousActiveElementRef = useRef<HTMLElement | null>(null);
|
||||
const [portalReady, setPortalReady] = useState(() => !usePortal);
|
||||
const [viewportHeight, setViewportHeight] = useState<number | undefined>(
|
||||
undefined,
|
||||
);
|
||||
const viewportHeight = useVisualViewportHeight(isOpen);
|
||||
|
||||
// Defer enabling the portal until after the layout commit so we don’t sync-setState
|
||||
// inside the effect (eslint react-hooks/set-state-in-effect) while still mounting
|
||||
@@ -39,24 +39,6 @@ const LoginContainer = memo<LoginProps>(
|
||||
return () => cancelAnimationFrame(id);
|
||||
}, [usePortal]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
const vp = window.visualViewport;
|
||||
const sync = () => {
|
||||
const next = vp?.height ?? window.innerHeight;
|
||||
setViewportHeight(next);
|
||||
};
|
||||
sync();
|
||||
vp?.addEventListener("resize", sync);
|
||||
vp?.addEventListener("scroll", sync);
|
||||
window.addEventListener("resize", sync);
|
||||
return () => {
|
||||
vp?.removeEventListener("resize", sync);
|
||||
vp?.removeEventListener("scroll", sync);
|
||||
window.removeEventListener("resize", sync);
|
||||
};
|
||||
}, [isOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
if (usePortal && !portalReady) return;
|
||||
|
||||
@@ -33,10 +33,19 @@ export function LoginView({
|
||||
? { height: viewportHeight, maxHeight: viewportHeight }
|
||||
: undefined;
|
||||
|
||||
const belowCardLink = belowCard ? (
|
||||
<div
|
||||
className="shrink-0 text-center"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{belowCard}
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
const content = (
|
||||
<div
|
||||
ref={backdropRef}
|
||||
className={`fixed inset-0 z-[9998] flex flex-col items-center gap-6 overflow-y-auto px-4 py-8 max-md:justify-end max-md:overflow-hidden max-md:px-0 max-md:py-0 md:justify-center ${backdropClasses[backdropVariant]}`}
|
||||
className={`fixed inset-0 z-[9998] flex flex-col items-center gap-6 overflow-y-auto px-4 py-8 max-md:items-stretch max-md:justify-end max-md:overflow-hidden max-md:px-0 max-md:py-0 md:justify-center ${backdropClasses[backdropVariant]}`}
|
||||
style={phoneSheetStyle}
|
||||
onPointerDown={(event) => {
|
||||
if (event.target !== event.currentTarget) return;
|
||||
@@ -50,21 +59,19 @@ export function LoginView({
|
||||
aria-modal="true"
|
||||
aria-label={ariaLabel}
|
||||
aria-labelledby={ariaLabelledBy}
|
||||
className={`flex min-h-0 max-h-[90vh] w-full max-w-[560px] shrink-0 flex-col overflow-hidden rounded-[var(--radius-500)] bg-[var(--color-surface-default-primary)] shadow-[0px_0px_48px_0px_rgba(0,0,0,0.1)] z-[9999] max-md:max-h-full max-md:rounded-b-none ${className}`}
|
||||
className={`flex min-h-0 max-h-[90vh] w-full max-w-[560px] shrink-0 flex-col overflow-hidden rounded-[var(--radius-500)] bg-[var(--color-surface-default-primary)] shadow-[0px_0px_48px_0px_rgba(0,0,0,0.1)] z-[9999] max-md:h-full max-md:max-h-full max-md:max-w-none max-md:rounded-none ${className}`}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<ModalHeader onClose={onClose} showMoreOptionsButton={false} />
|
||||
<div className="scrollbar-design flex min-h-0 flex-1 flex-col overflow-x-clip overflow-y-auto px-6 pb-8 pt-0">
|
||||
<div className="flex min-h-0 flex-1 flex-col overflow-hidden px-6 pb-8 pt-0">
|
||||
{children}
|
||||
{belowCardLink ? (
|
||||
<div className="shrink-0 pt-4 md:hidden">{belowCardLink}</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{belowCard ? (
|
||||
<div
|
||||
className="shrink-0 max-md:w-full max-md:bg-[var(--color-surface-default-primary)] max-md:px-6 max-md:pb-6"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{belowCard}
|
||||
</div>
|
||||
{belowCardLink ? (
|
||||
<div className="hidden md:block">{belowCardLink}</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useCallback, useId, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useTranslation } from "../../../contexts/MessagesContext";
|
||||
import Button from "../../buttons/Button";
|
||||
@@ -11,6 +11,7 @@ import Alert from "../Alert";
|
||||
import { requestMagicLink } from "../../../../lib/create/api";
|
||||
import { EMAIL_MAX_LEN } from "../../../../lib/create/isValidCreateFlowSaveEmail";
|
||||
import { buildCreateFlowDraftPayload } from "../../../../lib/create/buildCreateFlowDraftPayload";
|
||||
import { MAGIC_LINK_TTL_MINUTES } from "../../../../lib/privacyRetention";
|
||||
import { safeInternalPath } from "../../../../lib/safeInternalPath";
|
||||
import {
|
||||
readAnonymousCreateFlowState,
|
||||
@@ -43,6 +44,7 @@ function MailIconInline() {
|
||||
}
|
||||
|
||||
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
const LOGIN_FORM_ID = "login-magic-link-form";
|
||||
|
||||
export type LoginFormVariant =
|
||||
| "default"
|
||||
@@ -50,13 +52,27 @@ export type LoginFormVariant =
|
||||
| "keepRule"
|
||||
| "invite";
|
||||
|
||||
function isExpiredLinkError(errorParam: string | null): boolean {
|
||||
return errorParam === "expired_link" || errorParam === "invalid_link";
|
||||
}
|
||||
|
||||
function loginFormHeading(
|
||||
variant: LoginFormVariant,
|
||||
sent: boolean,
|
||||
linkExpired: boolean,
|
||||
email: string,
|
||||
t: (_key: string) => string,
|
||||
): { title: string; description: string } {
|
||||
if (sent) {
|
||||
return { title: t("successTitle"), description: t("successBody") };
|
||||
return {
|
||||
title: t("successTitle"),
|
||||
description: t("sentBody")
|
||||
.replace("{email}", email)
|
||||
.replace("{minutes}", String(MAGIC_LINK_TTL_MINUTES)),
|
||||
};
|
||||
}
|
||||
if (linkExpired) {
|
||||
return { title: t("expiredTitle"), description: t("expiredBody") };
|
||||
}
|
||||
if (variant === "saveProgress") {
|
||||
return {
|
||||
@@ -97,30 +113,35 @@ export type LoginFormProps = {
|
||||
magicLinkNextPath?: string;
|
||||
/** `keepRule`: Continue without saving. */
|
||||
onDismiss?: () => void;
|
||||
/** Sent-state Close, and the dialog chrome close. */
|
||||
onClose?: () => void;
|
||||
};
|
||||
|
||||
export default function LoginForm({
|
||||
variant = "default",
|
||||
magicLinkNextPath,
|
||||
onDismiss,
|
||||
onClose,
|
||||
}: LoginFormProps) {
|
||||
const t = useTranslation("pages.login");
|
||||
const tFooter = useTranslation("footer");
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const emailErrorId = useId();
|
||||
|
||||
const [email, setEmail] = useState("");
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [emailError, setEmailError] = useState("");
|
||||
const [formError, setFormError] = useState("");
|
||||
const [sent, setSent] = useState(false);
|
||||
const [linkExpired, setLinkExpired] = useState(() =>
|
||||
isExpiredLinkError(searchParams.get("error")),
|
||||
);
|
||||
|
||||
const nextParam = searchParams.get("next");
|
||||
const errorParam = searchParams.get("error");
|
||||
|
||||
const heading = loginFormHeading(variant, sent, t);
|
||||
const heading = loginFormHeading(variant, sent, linkExpired, email, t);
|
||||
|
||||
/** Drop `error` from the URL so URL-driven messages don’t linger after a new attempt. */
|
||||
const stripErrorQuery = useCallback(() => {
|
||||
@@ -166,6 +187,7 @@ export default function LoginForm({
|
||||
setTransferPendingFlag();
|
||||
}
|
||||
setEmail(trimmed);
|
||||
setLinkExpired(false);
|
||||
setSent(true);
|
||||
} catch {
|
||||
setFormError(t("errors.network"));
|
||||
@@ -181,115 +203,143 @@ export default function LoginForm({
|
||||
variant,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isExpiredLinkError(errorParam)) {
|
||||
setLinkExpired(true);
|
||||
}
|
||||
}, [errorParam]);
|
||||
|
||||
const urlErrorMessage =
|
||||
errorParam === "expired_link"
|
||||
? t("errors.expiredLink")
|
||||
: errorParam === "stakeholder_wrong_account"
|
||||
? t("errors.stakeholderWrongAccount")
|
||||
: errorParam === "invalid_link" || errorParam === "server"
|
||||
? errorParam === "server"
|
||||
? t("errors.serverError")
|
||||
: t("errors.invalidLink")
|
||||
: "";
|
||||
errorParam === "stakeholder_wrong_account"
|
||||
? t("errors.stakeholderWrongAccount")
|
||||
: errorParam === "server"
|
||||
? t("errors.serverError")
|
||||
: "";
|
||||
|
||||
const titleId = "login-modal-heading";
|
||||
const submitLabel = linkExpired ? t("sendNewLink") : t("sendMagicLink");
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6 pt-2">
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="relative flex h-12 w-12 shrink-0 items-center justify-center rounded-full bg-[var(--color-surface-invert-brand-primary)]">
|
||||
<MailIconInline />
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-6 pt-2">
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto">
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="relative flex h-12 w-12 shrink-0 items-center justify-center rounded-full bg-[var(--color-surface-invert-brand-primary)]">
|
||||
<MailIconInline />
|
||||
</div>
|
||||
<ContentLockup
|
||||
titleId={titleId}
|
||||
title={heading.title}
|
||||
description={heading.description}
|
||||
variant="login"
|
||||
alignment="left"
|
||||
/>
|
||||
</div>
|
||||
<ContentLockup
|
||||
titleId={titleId}
|
||||
title={heading.title}
|
||||
description={heading.description}
|
||||
variant="login"
|
||||
alignment="left"
|
||||
/>
|
||||
|
||||
{(urlErrorMessage || formError) && (
|
||||
<div className="pointer-events-none fixed inset-x-0 top-4 z-[10000] flex justify-center px-4 md:top-6">
|
||||
<div className="pointer-events-auto flex w-full max-w-[560px] flex-col gap-2">
|
||||
{urlErrorMessage ? (
|
||||
<Alert
|
||||
type="banner"
|
||||
status="danger"
|
||||
size="s"
|
||||
title={urlErrorMessage}
|
||||
hasBodyText={false}
|
||||
hasLeadingIcon
|
||||
onClose={() => {
|
||||
stripErrorQuery();
|
||||
}}
|
||||
className="w-full"
|
||||
/>
|
||||
) : null}
|
||||
{formError ? (
|
||||
<Alert
|
||||
type="banner"
|
||||
status="danger"
|
||||
size="s"
|
||||
title={formError}
|
||||
hasBodyText={false}
|
||||
hasLeadingIcon
|
||||
onClose={() => {
|
||||
setFormError("");
|
||||
}}
|
||||
className="w-full"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!sent ? (
|
||||
<form
|
||||
id={LOGIN_FORM_ID}
|
||||
className="flex flex-col gap-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void sendLink();
|
||||
}}
|
||||
noValidate
|
||||
>
|
||||
<TextInput
|
||||
label={t("emailLabel")}
|
||||
placeholder={t("emailPlaceholder")}
|
||||
type="email"
|
||||
name="email"
|
||||
autoComplete="email"
|
||||
inputMode="email"
|
||||
value={email}
|
||||
onChange={(e) => {
|
||||
setEmail(e.target.value);
|
||||
setEmailError("");
|
||||
stripErrorQuery();
|
||||
}}
|
||||
disabled={submitting}
|
||||
error={Boolean(emailError)}
|
||||
textHint={emailError || false}
|
||||
showHelpIcon={false}
|
||||
maxLength={EMAIL_MAX_LEN}
|
||||
/>
|
||||
</form>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{(urlErrorMessage || formError) && (
|
||||
<div className="pointer-events-none fixed inset-x-0 top-4 z-[10000] flex justify-center px-4 md:top-6">
|
||||
<div className="pointer-events-auto flex w-full max-w-[560px] flex-col gap-2">
|
||||
{urlErrorMessage ? (
|
||||
<Alert
|
||||
type="banner"
|
||||
status="danger"
|
||||
size="s"
|
||||
title={urlErrorMessage}
|
||||
hasBodyText={false}
|
||||
hasLeadingIcon
|
||||
onClose={() => {
|
||||
stripErrorQuery();
|
||||
}}
|
||||
className="w-full"
|
||||
/>
|
||||
) : null}
|
||||
{formError ? (
|
||||
<Alert
|
||||
type="banner"
|
||||
status="danger"
|
||||
size="s"
|
||||
title={formError}
|
||||
hasBodyText={false}
|
||||
hasLeadingIcon
|
||||
onClose={() => {
|
||||
setFormError("");
|
||||
}}
|
||||
className="w-full"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!sent ? (
|
||||
<form
|
||||
className="flex flex-col gap-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void sendLink();
|
||||
}}
|
||||
noValidate
|
||||
>
|
||||
<TextInput
|
||||
label={t("emailLabel")}
|
||||
placeholder={t("emailPlaceholder")}
|
||||
type="email"
|
||||
name="email"
|
||||
autoComplete="email"
|
||||
inputMode="email"
|
||||
value={email}
|
||||
onChange={(e) => {
|
||||
setEmail(e.target.value);
|
||||
stripErrorQuery();
|
||||
}}
|
||||
disabled={submitting}
|
||||
error={Boolean(emailError)}
|
||||
showHelpIcon
|
||||
maxLength={EMAIL_MAX_LEN}
|
||||
/>
|
||||
{emailError ? (
|
||||
<p
|
||||
id={emailErrorId}
|
||||
role="alert"
|
||||
aria-live="polite"
|
||||
className="text-[14px] text-[var(--color-border-default-utility-negative)]"
|
||||
<div className="flex shrink-0 flex-col gap-4">
|
||||
{sent ? (
|
||||
<>
|
||||
<Button
|
||||
type="button"
|
||||
size="large"
|
||||
buttonType="filled"
|
||||
palette="default"
|
||||
autoFocus
|
||||
onClick={() => onClose?.()}
|
||||
className="w-full !justify-center text-center px-[var(--space-400)] py-[var(--space-300)]"
|
||||
>
|
||||
{emailError}
|
||||
</p>
|
||||
) : null}
|
||||
<div className="flex flex-col gap-4 max-md:sticky max-md:bottom-0 max-md:bg-[var(--color-surface-default-primary)] max-md:pt-2">
|
||||
{t("close")}
|
||||
</Button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
void sendLink();
|
||||
}}
|
||||
disabled={submitting}
|
||||
className="text-center text-small-paragraph text-[var(--color-content-default-tertiary)] underline decoration-solid underline-offset-2"
|
||||
>
|
||||
{t("sendAgain")}
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Button
|
||||
type="submit"
|
||||
form={LOGIN_FORM_ID}
|
||||
size="large"
|
||||
buttonType="filled"
|
||||
palette="default"
|
||||
disabled={submitting}
|
||||
className="w-full !justify-center text-center px-[var(--space-400)] py-[var(--space-300)]"
|
||||
>
|
||||
{t("sendMagicLink")}
|
||||
{submitLabel}
|
||||
</Button>
|
||||
{onDismiss ? (
|
||||
<Button
|
||||
@@ -321,9 +371,9 @@ export default function LoginForm({
|
||||
</Link>
|
||||
{t("legalSuffix")}
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user