+
+`;
+
+ return { subject, previewText, text, html };
+}
diff --git a/lib/server/mail.ts b/lib/server/mail.ts
index e0838d9..bdb1d10 100644
--- a/lib/server/mail.ts
+++ b/lib/server/mail.ts
@@ -6,6 +6,7 @@ import {
type WorkshopInquiryMailInput,
} from "../workshopSignupMail";
import { MAGIC_LINK_TTL_MINUTES } from "../privacyRetention";
+import { buildMagicLinkMail } from "./magicLinkMail";
import { getSmtpUrl } from "./env";
import {
buildRuleStakeholderInviteMail,
@@ -87,16 +88,12 @@ async function sendHtmlMail(opts: {
export async function sendMagicLinkEmail(
to: string,
verifyUrl: string,
+ origin: string,
): Promise {
- const { text, html } = buildVerifyLinkParts(
- verifyUrl,
- `Open this link to log in (it expires in ${MAGIC_LINK_TTL_MINUTES} minutes):`,
- "If you did not request this, you can ignore this email.\n\nSent because you saved a draft at communityrule.info",
- "Log in",
- );
+ const { subject, text, html } = buildMagicLinkMail({ verifyUrl, origin });
await sendHtmlMail({
to,
- subject: "Log in to Community Rule",
+ subject,
text,
html,
devLog: `[dev] Magic link for ${to}: ${verifyUrl}`,
diff --git a/messages/en/modals/askOrganizerInquiry.json b/messages/en/modals/askOrganizerInquiry.json
index 0e012ec..f3a315b 100644
--- a/messages/en/modals/askOrganizerInquiry.json
+++ b/messages/en/modals/askOrganizerInquiry.json
@@ -1,15 +1,17 @@
{
- "_comment": "CR-107 Ask an organizer modal (Figma 22078-587823)",
- "title": "Ask an Organizer",
+ "_comment": "Ask an organizer modal (Figma 22078-587823, sent/failed 25032:48584 / 25032:48642)",
+ "title": "Ask an organizer",
"description": "Have a question about organizing? Send it over and an experienced organizer will get back to you.",
"emailLabel": "Email address",
"emailPlaceholder": "you@example.com",
"questionLabel": "Your question",
"questionPlaceholder": "What would you like to know?",
- "submitButton": "Confirm Question",
+ "submitButton": "Send question",
"closeAfterSuccess": "Close",
- "successTitle": "Thanks, we received your question",
- "successDescription": "Check your inbox and an organizer will reply when they can.",
+ "successTitle": "Thanks",
+ "successDescription": "One of us will write back within two working days.",
+ "sendFailedTitle": "We could not send that.",
+ "sendFailedDescription": "Your question is still here. Try again in a moment.",
"genericError": "Something went wrong. Please try again.",
"rateLimitedError": "Too many attempts. Please wait a bit and try again.",
"ariaDialog": "Ask an organizer",
diff --git a/messages/en/pages/login.json b/messages/en/pages/login.json
index 85d176d..b68d268 100644
--- a/messages/en/pages/login.json
+++ b/messages/en/pages/login.json
@@ -1,6 +1,6 @@
{
"title": "Log in to CommunityRule",
- "subtitle": "Enter your email and we'll send you a magic link to log in. No password needed!",
+ "subtitle": "Enter your email and we'll send you a login link. No password needed.",
"saveProgressTitle": "Save your progress?",
"saveProgressSubtitle": "We need your email to save, and we'll send you a magic link to log in. If you don't save now you could lose your progress.",
"keepRuleTitle": "Log in to keep this rule on your profile",
@@ -11,9 +11,15 @@
"continueWithoutSaving": "Continue without saving",
"emailLabel": "Email address",
"emailPlaceholder": "you@example.com",
- "sendMagicLink": "Send me a magic link",
+ "sendMagicLink": "Send login link",
+ "sendNewLink": "Send a new link",
+ "sendAgain": "Send it again",
+ "close": "Close",
"successTitle": "Check your email",
"successBody": "We sent a login link that works for 60 minutes. Open it on this device to continue. If you don't see it, check spam or promotions.",
+ "sentBody": "We sent a login link to {email}. It works for {minutes} minutes.",
+ "expiredTitle": "That link has expired",
+ "expiredBody": "That login link has expired or was already used. Send a new one.",
"legalPrefix": "By continuing, you agree to our ",
"legalAnd": " and ",
"legalSuffix": ".",
@@ -21,7 +27,7 @@
"loadingFallback": "Loading…",
"errors": {
"network": "Something went wrong. Check your connection and try again.",
- "emailInvalid": "Enter a valid email address.",
+ "emailInvalid": "Enter an email address like name@example.org.",
"rateLimited": "Too many requests. Try again in {seconds} seconds.",
"generic": "Something went wrong. Try again.",
"invalidLink": "That login link is not valid. Request a new one from the login page.",
diff --git a/stories/modals/Login.stories.tsx b/stories/modals/Login.stories.tsx
index 28e9832..d129644 100644
--- a/stories/modals/Login.stories.tsx
+++ b/stories/modals/Login.stories.tsx
@@ -109,7 +109,7 @@ export const HeaderOverlayBlurred = {
ariaLabelledBy="login-modal-heading"
>
Loading…}>
-
+ {}} />
@@ -154,7 +154,53 @@ export const FullPageRouteSolid = {
}
>
Loading…}>
-
+ {}} />
+
+
+ ),
+};
+
+export const LinkExpired = {
+ name: "Link expired",
+ parameters: {
+ nextjs: {
+ navigation: {
+ pathname: "/login",
+ query: { error: "expired_link" },
+ },
+ },
+ docs: {
+ description: {
+ story:
+ "Expired or used login links land on this heading, with Send a new link.",
+ },
+ },
+ },
+ decorators: [
+ (Story: () => React.ReactNode) => (
+
+
+
+ ),
+ ],
+ render: () => (
+ {}}
+ backdropVariant="solid"
+ usePortal={false}
+ ariaLabelledBy="login-modal-heading"
+ belowCard={
+
+ {backToHome}
+
+ }
+ >
+ Loading…}>
+ {}} />
),
diff --git a/tests/components/AskOrganizerInquiry.test.tsx b/tests/components/AskOrganizerInquiry.test.tsx
new file mode 100644
index 0000000..f4951a8
--- /dev/null
+++ b/tests/components/AskOrganizerInquiry.test.tsx
@@ -0,0 +1,98 @@
+import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
+import { screen, waitFor } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import "@testing-library/jest-dom/vitest";
+import { renderWithProviders } from "../utils/test-utils";
+import AskOrganizerInquiryModal from "../../app/components/modals/AskOrganizerInquiry";
+
+describe("AskOrganizerInquiryModal", () => {
+ const fetchMock = vi.fn();
+
+ beforeEach(() => {
+ fetchMock.mockReset();
+ vi.stubGlobal("fetch", fetchMock);
+ });
+
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ it("opens as a phone sheet and sends the question into the sent state", async () => {
+ const user = userEvent.setup();
+ fetchMock.mockResolvedValue({
+ ok: true,
+ json: async () => ({ ok: true }),
+ });
+ renderWithProviders(
+ ,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByRole("dialog")).toHaveClass("h-full", "max-h-full");
+ });
+ expect(
+ screen.getByRole("heading", { name: "Ask an organizer" }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: /send question/i }),
+ ).toBeInTheDocument();
+
+ await user.type(
+ screen.getByRole("textbox", { name: /email address/i }),
+ "rosa@example.org",
+ );
+ await user.type(
+ screen.getByRole("textbox", { name: /your question/i }),
+ "How do we decide who holds the keys to our shared accounts?",
+ );
+ await user.click(screen.getByRole("button", { name: /send question/i }));
+
+ expect(
+ await screen.findByRole("heading", { name: "Thanks" }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByText(/one of us will write back within two working days/i),
+ ).toBeInTheDocument();
+ expect(
+ screen.getAllByRole("button", { name: /^close$/i }).length,
+ ).toBeGreaterThan(1);
+ });
+
+ it("keeps the question and shows the danger toast when send fails", async () => {
+ const user = userEvent.setup();
+ fetchMock.mockRejectedValue(new Error("network"));
+ renderWithProviders(
+ ,
+ );
+
+ await user.type(
+ screen.getByRole("textbox", { name: /email address/i }),
+ "rosa@example.org",
+ );
+ await user.type(
+ screen.getByRole("textbox", { name: /your question/i }),
+ "How do we decide who holds the keys to our shared accounts?",
+ );
+ await user.click(screen.getByRole("button", { name: /send question/i }));
+
+ await waitFor(() => {
+ expect(
+ screen.getAllByText("We could not send that.").length,
+ ).toBeGreaterThan(0);
+ });
+ expect(
+ screen.getAllByText(/your question is still here/i).length,
+ ).toBeGreaterThan(0);
+ expect(
+ screen.getByRole("textbox", { name: /email address/i }),
+ ).toHaveValue("rosa@example.org");
+ expect(
+ screen.getByRole("textbox", { name: /your question/i }),
+ ).toHaveValue(
+ "How do we decide who holds the keys to our shared accounts?",
+ );
+ expect(
+ screen.getByRole("button", { name: /send question/i }),
+ ).toBeInTheDocument();
+ });
+});
diff --git a/tests/components/Create.test.tsx b/tests/components/Create.test.tsx
index 9f07018..b4de667 100644
--- a/tests/components/Create.test.tsx
+++ b/tests/components/Create.test.tsx
@@ -289,12 +289,10 @@ describe("Create", () => {
,
);
- const closeButton = screen.getByLabelText("Close");
- screen.getByLabelText("Test Input"); // Verify input is rendered
+ const input = screen.getByLabelText("Test Input");
- // Focus should start on first focusable element (close button)
await waitFor(() => {
- expect(closeButton).toHaveFocus();
+ expect(input).toHaveFocus();
});
// Tab should move focus to next element
diff --git a/tests/components/Login.test.tsx b/tests/components/Login.test.tsx
index 757bf22..8f525e0 100644
--- a/tests/components/Login.test.tsx
+++ b/tests/components/Login.test.tsx
@@ -156,8 +156,8 @@ describe("Login", () => {
expect(screen.getByRole("dialog")).toBeInTheDocument();
});
expect(
- screen.getByRole("link", { name: /back to home/i }),
- ).toBeInTheDocument();
+ screen.getAllByRole("link", { name: /back to home/i }).length,
+ ).toBeGreaterThan(0);
});
it("does not render a more-options kebab", async () => {
diff --git a/tests/components/LoginForm.test.tsx b/tests/components/LoginForm.test.tsx
index 2c368d7..dc21934 100644
--- a/tests/components/LoginForm.test.tsx
+++ b/tests/components/LoginForm.test.tsx
@@ -73,7 +73,7 @@ describe("LoginForm", () => {
screen.getByRole("textbox", { name: /email address/i }),
).toHaveAttribute("maxLength", String(EMAIL_MAX_LEN));
expect(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
).toBeInTheDocument();
});
@@ -95,10 +95,10 @@ describe("LoginForm", () => {
"not-an-email",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
expect(
- await screen.findByText(/enter a valid email address/i),
+ await screen.findByText(/enter an email address like name@example.org/i),
).toBeInTheDocument();
expect(requestMagicLink).not.toHaveBeenCalled();
});
@@ -112,7 +112,7 @@ describe("LoginForm", () => {
" Pat@Example.COM ",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -124,8 +124,14 @@ describe("LoginForm", () => {
expect(
await screen.findByRole("heading", { name: /check your email/i }),
).toBeInTheDocument();
- expect(screen.getByText(/we sent a login link/i)).toBeInTheDocument();
- expect(screen.getByText(/check spam or promotions/i)).toBeInTheDocument();
+ expect(
+ screen.getByText(/we sent a login link to pat@example.com/i),
+ ).toBeInTheDocument();
+ expect(screen.getByText(/it works for 60 minutes/i)).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: /^close$/i })).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: /send it again/i }),
+ ).toBeInTheDocument();
});
it("submits a long email without treating length as invalid", async () => {
@@ -139,7 +145,7 @@ describe("LoginForm", () => {
email,
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(email, "/", undefined);
@@ -162,7 +168,7 @@ describe("LoginForm", () => {
"save@example.com",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -199,7 +205,7 @@ describe("LoginForm", () => {
"guest@example.com",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -237,7 +243,7 @@ describe("LoginForm", () => {
"guest@example.com",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -286,7 +292,7 @@ describe("LoginForm", () => {
"a@b.co",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -309,7 +315,7 @@ describe("LoginForm", () => {
"ok@example.com",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
expect(await screen.findByText("Server says no")).toBeInTheDocument();
});
@@ -327,7 +333,7 @@ describe("LoginForm", () => {
"ok@example.com",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
expect(
await screen.findByText(/try again in 4 seconds/i),
@@ -338,7 +344,13 @@ describe("LoginForm", () => {
navMock.searchParams = new URLSearchParams("error=expired_link");
renderLoginForm();
expect(
- screen.getByText(/that login link has expired/i),
+ screen.getByRole("heading", { name: /that link has expired/i }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByText(/expired or was already used/i),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: /send a new link/i }),
).toBeInTheDocument();
});
@@ -346,7 +358,10 @@ describe("LoginForm", () => {
navMock.searchParams = new URLSearchParams("error=invalid_link");
renderLoginForm();
expect(
- screen.getByText(/that login link is not valid/i),
+ screen.getByRole("heading", { name: /that link has expired/i }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: /send a new link/i }),
).toBeInTheDocument();
});
@@ -383,10 +398,30 @@ describe("LoginForm", () => {
"ok@example.com",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
expect(
await screen.findByText(/check your connection/i),
).toBeInTheDocument();
});
+
+ it("send it again requests another link from the sent state", async () => {
+ const user = userEvent.setup();
+ vi.mocked(requestMagicLink).mockResolvedValue({ ok: true });
+ renderLoginForm();
+ await user.type(
+ screen.getByRole("textbox", { name: /email address/i }),
+ "pat@example.com",
+ );
+ await user.click(
+ screen.getByRole("button", { name: /send login link/i }),
+ );
+ expect(
+ await screen.findByRole("button", { name: /send it again/i }),
+ ).toBeInTheDocument();
+ await user.click(screen.getByRole("button", { name: /send it again/i }));
+ await waitFor(() => {
+ expect(requestMagicLink).toHaveBeenCalledTimes(2);
+ });
+ });
});
diff --git a/tests/contexts/AuthModalContext.test.tsx b/tests/contexts/AuthModalContext.test.tsx
index 84fbc22..bcb0f62 100644
--- a/tests/contexts/AuthModalContext.test.tsx
+++ b/tests/contexts/AuthModalContext.test.tsx
@@ -177,7 +177,7 @@ describe("AuthModalProvider (header overlay)", () => {
"guest@example.com",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -211,7 +211,7 @@ describe("AuthModalProvider (header overlay)", () => {
"guest@example.com",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -285,14 +285,14 @@ describe("AuthModalProvider (header overlay)", () => {
screen.getByRole("heading", { name: /log in to invite your members/i }),
).toBeInTheDocument();
expect(
- screen.getByRole("button", { name: /back to your rule/i }),
- ).toBeInTheDocument();
+ screen.getAllByRole("button", { name: /back to your rule/i }).length,
+ ).toBeGreaterThan(0);
await user.type(
screen.getByRole("textbox", { name: /email address/i }),
"guest@example.com",
);
await user.click(
- screen.getByRole("button", { name: /send me a magic link/i }),
+ screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
diff --git a/tests/unit/authMagicLinkRequestRoute.test.ts b/tests/unit/authMagicLinkRequestRoute.test.ts
index 18ee53c..3d56cf7 100644
--- a/tests/unit/authMagicLinkRequestRoute.test.ts
+++ b/tests/unit/authMagicLinkRequestRoute.test.ts
@@ -111,6 +111,7 @@ describe("POST /api/auth/magic-link/request", () => {
expect(sendMagicLinkEmailMock).toHaveBeenCalledWith(
"member@example.com",
expect.stringContaining("/api/auth/magic-link/verify?token="),
+ "https://x.test",
);
});
@@ -130,6 +131,7 @@ describe("POST /api/auth/magic-link/request", () => {
expect(sendMagicLinkEmailMock).toHaveBeenCalledWith(
email,
expect.stringContaining("/api/auth/magic-link/verify?token="),
+ "https://x.test",
);
});
diff --git a/tests/unit/magicLinkMail.test.ts b/tests/unit/magicLinkMail.test.ts
new file mode 100644
index 0000000..eeec16d
--- /dev/null
+++ b/tests/unit/magicLinkMail.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, it } from "vitest";
+import { MAGIC_LINK_TTL_MINUTES } from "../../lib/privacyRetention";
+import { buildMagicLinkMail } from "../../lib/server/magicLinkMail";
+
+const VERIFY_URL =
+ "https://communityrule.info/api/auth/magic-link/verify?token=abc";
+
+describe("buildMagicLinkMail", () => {
+ const mail = buildMagicLinkMail({
+ verifyUrl: VERIFY_URL,
+ origin: "https://communityrule.info",
+ });
+
+ it("uses the drawn subject, once-and-minutes line, and log in button", () => {
+ expect(mail.subject).toBe("Your login link for CommunityRule");
+ expect(mail.previewText).toBe(
+ `It works once, for ${MAGIC_LINK_TTL_MINUTES} minutes.`,
+ );
+ expect(mail.text).toContain("Log in to CommunityRule");
+ expect(mail.text).toContain(VERIFY_URL);
+ expect(mail.text).toContain(
+ `It works once, for ${MAGIC_LINK_TTL_MINUTES} minutes.`,
+ );
+ expect(mail.html).toContain("background:#000000");
+ expect(mail.html).toContain(">Log in");
+ expect(mail.html).toContain(`href="${VERIFY_URL}"`);
+ expect(mail.html).toContain("/privacy");
+ expect(mail.html).toContain("/about");
+ });
+
+ it("does not invent a first name", () => {
+ expect(mail.html).not.toContain("Hi ");
+ expect(mail.text).not.toContain("Hi ");
+ });
+});
diff --git a/tests/unit/privacyRetention.test.ts b/tests/unit/privacyRetention.test.ts
index 133a75d..f53c77f 100644
--- a/tests/unit/privacyRetention.test.ts
+++ b/tests/unit/privacyRetention.test.ts
@@ -4,8 +4,8 @@ import { MAGIC_LINK_TTL_MINUTES } from "../../lib/privacyRetention";
describe("privacy retention copy", () => {
it("states the login link lifetime in the sent state", () => {
- expect(login.successBody).toContain(
- `works for ${MAGIC_LINK_TTL_MINUTES} minutes`,
- );
+ expect(
+ login.sentBody.replace("{minutes}", String(MAGIC_LINK_TTL_MINUTES)),
+ ).toContain(`works for ${MAGIC_LINK_TTL_MINUTES} minutes`);
});
});
--
2.53.0
From 39807ef452d22844d98c96a60f7eb7c241566471 Mon Sep 17 00:00:00 2001
From: adilallo <39313955+adilallo@users.noreply.github.com>
Date: Wed, 11 Nov 2026 17:01:44 -0700
Subject: [PATCH 2/2] Pin phone sheets to the visible viewport, and let people
correct login and organizer errors.
---
.../AskOrganizerInquiryModal.container.tsx | 16 +++++-
.../AskOrganizerInquiryModal.types.ts | 2 +
.../AskOrganizerInquiryModal.view.tsx | 2 +
.../modals/Create/Create.container.tsx | 5 +-
app/components/modals/Create/Create.types.ts | 2 +
app/components/modals/Create/Create.view.tsx | 2 +
.../modals/Create/CreateModalFrame.view.tsx | 10 +++-
.../modals/Login/Login.container.tsx | 5 +-
app/components/modals/Login/Login.types.ts | 2 +
app/components/modals/Login/Login.view.tsx | 8 ++-
app/components/modals/Login/LoginForm.tsx | 3 ++
app/hooks/useVisualViewportHeight.ts | 32 +++++++++---
messages/en/modals/askOrganizerInquiry.json | 2 +
tests/components/AskOrganizerInquiry.test.tsx | 49 ++++++++++++++++++
tests/components/Login.test.tsx | 37 +++++++++++++-
tests/components/LoginForm.test.tsx | 25 ++++++++++
.../hooks/useVisualViewportHeight.test.ts | 50 +++++++++++++++++++
17 files changed, 236 insertions(+), 16 deletions(-)
create mode 100644 tests/unit/hooks/useVisualViewportHeight.test.ts
diff --git a/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.container.tsx b/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.container.tsx
index 7c0fb85..0c999ad 100644
--- a/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.container.tsx
+++ b/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.container.tsx
@@ -23,8 +23,10 @@ const AskOrganizerInquiryModalContainer = memo(
description: t("description"),
emailLabel: t("emailLabel"),
emailPlaceholder: t("emailPlaceholder"),
+ emailInvalid: t("emailInvalid"),
questionLabel: t("questionLabel"),
questionPlaceholder: t("questionPlaceholder"),
+ questionTooShort: t("questionTooShort"),
submitButton: t("submitButton"),
closeAfterSuccess: t("closeAfterSuccess"),
successTitle: t("successTitle"),
@@ -59,6 +61,16 @@ const AskOrganizerInquiryModalContainer = memo(
}
}, [isOpen]);
+ const onEmailChange = useCallback((value: string) => {
+ setEmail(value);
+ setEmailError(false);
+ }, []);
+
+ const onMessageChange = useCallback((value: string) => {
+ setMessage(value);
+ setQuestionError(false);
+ }, []);
+
const onSubmit = useCallback(
async (e: FormEvent) => {
e.preventDefault();
@@ -149,8 +161,8 @@ const AskOrganizerInquiryModalContainer = memo(
sendFailed={sendFailed}
emailError={emailError}
questionError={questionError}
- onEmailChange={setEmail}
- onMessageChange={setMessage}
+ onEmailChange={onEmailChange}
+ onMessageChange={onMessageChange}
onHoneypotChange={setHoneypot}
onSubmit={onSubmit}
onDismissFailed={() => setSendFailed(false)}
diff --git a/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.types.ts b/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.types.ts
index 85b7fdf..a66d8a3 100644
--- a/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.types.ts
+++ b/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.types.ts
@@ -8,8 +8,10 @@ export interface AskOrganizerInquiryModalCopy {
description: string;
emailLabel: string;
emailPlaceholder: string;
+ emailInvalid: string;
questionLabel: string;
questionPlaceholder: string;
+ questionTooShort: string;
submitButton: string;
closeAfterSuccess: string;
successTitle: string;
diff --git a/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.view.tsx b/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.view.tsx
index 657931a..e3212fb 100644
--- a/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.view.tsx
+++ b/app/components/modals/AskOrganizerInquiry/AskOrganizerInquiryModal.view.tsx
@@ -125,6 +125,7 @@ export function AskOrganizerInquiryModalView({
value={email}
onChange={(e) => onEmailChange(e.target.value)}
error={emailError}
+ textHint={emailError ? copy.emailInvalid : false}
inputSize="medium"
showHelpIcon={false}
/>
@@ -136,6 +137,7 @@ export function AskOrganizerInquiryModalView({
value={message}
onChange={(e) => onMessageChange(e.target.value)}
error={questionError}
+ textHint={questionError ? copy.questionTooShort : false}
size="medium"
appearance="embedded"
rows={4}
diff --git a/app/components/modals/Create/Create.container.tsx b/app/components/modals/Create/Create.container.tsx
index 095f641..87affc3 100644
--- a/app/components/modals/Create/Create.container.tsx
+++ b/app/components/modals/Create/Create.container.tsx
@@ -48,7 +48,7 @@ const CreateContainer = memo(
}) => {
const createRef = useRef(null);
const overlayRef = useRef(null);
- const viewportHeight = useVisualViewportHeight(
+ const viewport = useVisualViewportHeight(
isOpen && presentation === "sheet",
);
@@ -92,7 +92,8 @@ const CreateContainer = memo(
kebabMenuItems={kebabMenuItems}
belowCard={belowCard}
presentation={presentation}
- viewportHeight={viewportHeight}
+ viewportHeight={viewport?.height}
+ viewportOffsetTop={viewport?.offsetTop}
/>
);
},
diff --git a/app/components/modals/Create/Create.types.ts b/app/components/modals/Create/Create.types.ts
index 3a4d60e..6563114 100644
--- a/app/components/modals/Create/Create.types.ts
+++ b/app/components/modals/Create/Create.types.ts
@@ -95,4 +95,6 @@ export interface CreateViewProps {
belowCard?: React.ReactNode;
presentation: CreateModalPresentationValue;
viewportHeight?: number;
+ /** `visualViewport.offsetTop`, so a phone sheet tracks the visible region on iOS. */
+ viewportOffsetTop?: number;
}
diff --git a/app/components/modals/Create/Create.view.tsx b/app/components/modals/Create/Create.view.tsx
index a704cf6..63f79c1 100644
--- a/app/components/modals/Create/Create.view.tsx
+++ b/app/components/modals/Create/Create.view.tsx
@@ -43,6 +43,7 @@ export function CreateView({
belowCard,
presentation,
viewportHeight,
+ viewportOffsetTop,
}: CreateViewProps) {
return (
(
const backdropRef = useRef(null);
const previousActiveElementRef = useRef(null);
const [portalReady, setPortalReady] = useState(() => !usePortal);
- const viewportHeight = useVisualViewportHeight(isOpen);
+ const viewport = 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
@@ -135,7 +135,8 @@ const LoginContainer = memo(
portalReady={portalReady}
usePortal={usePortal}
backdropVariant={backdropVariant}
- viewportHeight={viewportHeight}
+ viewportHeight={viewport?.height}
+ viewportOffsetTop={viewport?.offsetTop}
>
{children}
diff --git a/app/components/modals/Login/Login.types.ts b/app/components/modals/Login/Login.types.ts
index 310a178..f2884b1 100644
--- a/app/components/modals/Login/Login.types.ts
+++ b/app/components/modals/Login/Login.types.ts
@@ -35,4 +35,6 @@ export interface LoginViewProps {
backdropVariant: LoginBackdropVariant;
/** Visible viewport height on phones so the footer rides above the keyboard. */
viewportHeight?: number;
+ /** `visualViewport.offsetTop`, so the sheet tracks the visible region on iOS. */
+ viewportOffsetTop?: number;
}
diff --git a/app/components/modals/Login/Login.view.tsx b/app/components/modals/Login/Login.view.tsx
index 8de85b6..3136f03 100644
--- a/app/components/modals/Login/Login.view.tsx
+++ b/app/components/modals/Login/Login.view.tsx
@@ -24,13 +24,19 @@ export function LoginView({
usePortal,
backdropVariant,
viewportHeight,
+ viewportOffsetTop,
}: LoginViewProps) {
if (!isOpen) return null;
if (usePortal && !portalReady) return null;
const phoneSheetStyle =
viewportHeight != null
- ? { height: viewportHeight, maxHeight: viewportHeight }
+ ? {
+ top: viewportOffsetTop ?? 0,
+ bottom: "auto" as const,
+ height: viewportHeight,
+ maxHeight: viewportHeight,
+ }
: undefined;
const belowCardLink = belowCard ? (
diff --git a/app/components/modals/Login/LoginForm.tsx b/app/components/modals/Login/LoginForm.tsx
index bcd2ba1..24e3620 100644
--- a/app/components/modals/Login/LoginForm.tsx
+++ b/app/components/modals/Login/LoginForm.tsx
@@ -158,6 +158,7 @@ export default function LoginForm({
setFormError("");
const trimmed = email.trim().toLowerCase();
if (!EMAIL_PATTERN.test(trimmed)) {
+ setSent(false);
setEmailError(t("errors.emailInvalid"));
return;
}
@@ -173,6 +174,7 @@ export default function LoginForm({
: undefined;
const result = await requestMagicLink(trimmed, nextPath, draft);
if (result.ok === false) {
+ setSent(false);
if (result.retryAfterMs != null && result.retryAfterMs > 0) {
const seconds = Math.ceil(result.retryAfterMs / 1000);
setFormError(
@@ -190,6 +192,7 @@ export default function LoginForm({
setLinkExpired(false);
setSent(true);
} catch {
+ setSent(false);
setFormError(t("errors.network"));
} finally {
setSubmitting(false);
diff --git a/app/hooks/useVisualViewportHeight.ts b/app/hooks/useVisualViewportHeight.ts
index 83e741f..6698278 100644
--- a/app/hooks/useVisualViewportHeight.ts
+++ b/app/hooks/useVisualViewportHeight.ts
@@ -1,22 +1,40 @@
import { useEffect, useState } from "react";
/**
- * Visible viewport height, including the shrink when a phone keyboard opens.
+ * Visible viewport box, including the shrink and offset when a phone keyboard opens.
+ *
+ * iOS Safari reports the keyboard by shrinking `visualViewport.height` and
+ * shifting `offsetTop`. A `fixed` overlay has to use both, or its footer stays
+ * in the layout viewport behind the keyboard.
*
* @param enabled When false, skip listeners and return `undefined`.
- * @returns Pixel height of `visualViewport`, or `undefined` when disabled.
+ * @returns Height and top offset of `visualViewport`, or `undefined` when disabled.
*
* @example
- * const viewportHeight = useVisualViewportHeight(isOpen);
+ * const viewport = useVisualViewportHeight(isOpen);
*/
-export function useVisualViewportHeight(enabled: boolean): number | undefined {
- const [height, setHeight] = useState(undefined);
+export function useVisualViewportHeight(
+ enabled: boolean,
+): { height: number; offsetTop: number } | undefined {
+ const [frame, setFrame] = useState<
+ { height: number; offsetTop: number } | undefined
+ >(undefined);
useEffect(() => {
if (!enabled) return;
const vp = window.visualViewport;
const sync = () => {
- setHeight(vp?.height ?? window.innerHeight);
+ const next = {
+ height: vp?.height ?? window.innerHeight,
+ offsetTop: vp?.offsetTop ?? 0,
+ };
+ setFrame((prev) =>
+ prev &&
+ prev.height === next.height &&
+ prev.offsetTop === next.offsetTop
+ ? prev
+ : next,
+ );
};
sync();
vp?.addEventListener("resize", sync);
@@ -29,5 +47,5 @@ export function useVisualViewportHeight(enabled: boolean): number | undefined {
};
}, [enabled]);
- return enabled ? height : undefined;
+ return enabled ? frame : undefined;
}
diff --git a/messages/en/modals/askOrganizerInquiry.json b/messages/en/modals/askOrganizerInquiry.json
index f3a315b..539cc89 100644
--- a/messages/en/modals/askOrganizerInquiry.json
+++ b/messages/en/modals/askOrganizerInquiry.json
@@ -4,7 +4,9 @@
"description": "Have a question about organizing? Send it over and an experienced organizer will get back to you.",
"emailLabel": "Email address",
"emailPlaceholder": "you@example.com",
+ "emailInvalid": "Enter an email address like name@example.org.",
"questionLabel": "Your question",
+ "questionTooShort": "Please enter at least 10 characters.",
"questionPlaceholder": "What would you like to know?",
"submitButton": "Send question",
"closeAfterSuccess": "Close",
diff --git a/tests/components/AskOrganizerInquiry.test.tsx b/tests/components/AskOrganizerInquiry.test.tsx
index f4951a8..2cbbab0 100644
--- a/tests/components/AskOrganizerInquiry.test.tsx
+++ b/tests/components/AskOrganizerInquiry.test.tsx
@@ -95,4 +95,53 @@ describe("AskOrganizerInquiryModal", () => {
screen.getByRole("button", { name: /send question/i }),
).toBeInTheDocument();
});
+
+ it("shows field hints for an invalid email and a short question, then clears them on edit", async () => {
+ const user = userEvent.setup();
+ renderWithProviders(
+ ,
+ );
+
+ await user.type(
+ screen.getByRole("textbox", { name: /email address/i }),
+ "not-an-email",
+ );
+ await user.type(
+ screen.getByRole("textbox", { name: /your question/i }),
+ "Too short",
+ );
+ await user.click(screen.getByRole("button", { name: /send question/i }));
+
+ expect(
+ await screen.findByText("Enter an email address like name@example.org."),
+ ).toBeInTheDocument();
+ expect(fetchMock).not.toHaveBeenCalled();
+
+ await user.type(
+ screen.getByRole("textbox", { name: /email address/i }),
+ "@example.org",
+ );
+ expect(
+ screen.queryByText("Enter an email address like name@example.org."),
+ ).not.toBeInTheDocument();
+
+ await user.clear(screen.getByRole("textbox", { name: /email address/i }));
+ await user.type(
+ screen.getByRole("textbox", { name: /email address/i }),
+ "rosa@example.org",
+ );
+ await user.click(screen.getByRole("button", { name: /send question/i }));
+
+ expect(
+ await screen.findByText("Please enter at least 10 characters."),
+ ).toBeInTheDocument();
+
+ await user.type(
+ screen.getByRole("textbox", { name: /your question/i }),
+ " more",
+ );
+ expect(
+ screen.queryByText("Please enter at least 10 characters."),
+ ).not.toBeInTheDocument();
+ });
});
diff --git a/tests/components/Login.test.tsx b/tests/components/Login.test.tsx
index 8f525e0..d9a8064 100644
--- a/tests/components/Login.test.tsx
+++ b/tests/components/Login.test.tsx
@@ -1,14 +1,23 @@
-import { describe, it, expect, vi, beforeEach } from "vitest";
+import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { screen, fireEvent, waitFor } from "@testing-library/react";
import "@testing-library/jest-dom/vitest";
import { renderWithProviders } from "../utils/test-utils";
import Login from "../../app/components/modals/Login";
describe("Login", () => {
+ const originalViewport = window.visualViewport;
+
beforeEach(() => {
vi.clearAllMocks();
});
+ afterEach(() => {
+ Object.defineProperty(window, "visualViewport", {
+ configurable: true,
+ value: originalViewport,
+ });
+ });
+
it("uses blurredYellow backdrop by default (header overlay)", async () => {
renderWithProviders(
@@ -172,4 +181,30 @@ describe("Login", () => {
expect(screen.getByLabelText("Close")).toBeInTheDocument();
expect(screen.queryByLabelText("More options")).not.toBeInTheDocument();
});
+
+ it("pins the overlay to the visual viewport offset", async () => {
+ Object.defineProperty(window, "visualViewport", {
+ configurable: true,
+ value: {
+ height: 500,
+ offsetTop: 80,
+ addEventListener: () => {},
+ removeEventListener: () => {},
+ },
+ });
+ renderWithProviders(
+
+