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"
|
||||
|
||||
Reference in new issue
Block a user