Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
18bee0a
Add the translator and English catalog that localization builds on
claude Nov 13, 2026
d5f43d9
Keep the message catalogs out of client files with a lint rule
claude Nov 13, 2026
287efb2
Merge branch 'main' into claude/issue-620-client-lint
richshaw Nov 13, 2026
1930b8a
Check the message catalogs in pnpm test
claude Nov 13, 2026
28a7b8b
Merge claude/issue-620-client-lint, which now has main with #889
claude Nov 13, 2026
a4559c0
Lint hard-coded text where it has moved to the catalogs
claude Nov 13, 2026
218b7d9
Merge branch 'main' into claude/issue-623-catalog-check
richshaw Nov 13, 2026
a7a10ed
Catch a select shown as a plain placeholder in the catalog check
claude Nov 13, 2026
4480055
Precompile the message catalogs at build time
claude Nov 13, 2026
701bd61
Merge branch 'claude/issue-623-catalog-check' into claude/issue-623-t…
claude Nov 14, 2026
dd50e3b
Merge branch 'main' into claude/issue-623-text-lint
richshaw Nov 14, 2026
20409b8
Give slot dates and times a language
claude Nov 14, 2026
18564d2
Escape backslashes too in filesAt's globs
claude Nov 14, 2026
9ca3cb6
Merge branch 'claude/issue-623-text-lint' into claude/issue-624-preco…
claude Nov 14, 2026
86a0365
Merge branch 'claude/issue-624-precompile' into claude/issue-622-slot…
claude Nov 14, 2026
1559802
Merge branch 'main' into claude/issue-624-precompile
claude Nov 14, 2026
ee870e1
Merge branch 'claude/issue-624-precompile' into claude/issue-622-slot…
claude Nov 14, 2026
325f17a
Merge branch 'main' into claude/issue-622-slot-format
richshaw Nov 14, 2026
d768b87
Give the other formatters a language
claude Nov 14, 2026
3c9b122
Merge branch 'claude/issue-622-slot-format' into claude/issue-622-oth…
claude Nov 14, 2026
40bb396
Give a signup a language and an instance a default one, with no visib…
claude Nov 14, 2026
07afbfd
Add a Signup language control to the Settings tab, hidden while one l…
claude Nov 14, 2026
a5d1fab
Keep the language rules out of the browser's view, so no page grows
claude Nov 14, 2026
efff208
Read any stored signup language leniently, and check the one sent as …
claude Nov 14, 2026
d53625b
Say plainly that DEFAULT_LOCALE accepts only en today
claude Nov 14, 2026
49db138
Keep the Signup language form in the Settings page's own file
claude Nov 14, 2026
a7f3825
Merge branch 'main' into claude/issue-625-signup-locale
claude Nov 14, 2026
f9e4103
Merge branch 'claude/issue-625-signup-locale' into claude/issue-625-s…
claude Nov 14, 2026
fe68bb1
Work out an organizer's language as pure logic, with no storage yet
claude Nov 14, 2026
bd3c442
Read a public signup's row once per request, through a cached loader
claude Nov 14, 2026
5ddc90f
Carry the organizer's saved language in the session and the token con…
claude Nov 14, 2026
afaf7be
Let an organizer save a language for new signups, hidden until a seco…
claude Nov 14, 2026
dd7ef70
Start new signups in their organizer's language, once there's a choice
claude Nov 14, 2026
e99765d
Let create_signup take a locale, else the organizer's language
claude Nov 14, 2026
1e53268
Have the public signup pages work out the signup's language
claude Nov 14, 2026
d0a8a6b
Find the signup's language on the not-found pages from the request path
claude Nov 14, 2026
522775f
Show a signup's language to AI assistants and the public API
claude Nov 14, 2026
8811cf2
Share one ship() test helper for languages that haven't shipped
claude Nov 14, 2026
39eb1eb
Take the footer's language and the Banner and BottomSheet labels as p…
claude Nov 14, 2026
855ea58
Move the public signup page's server-rendered text into the catalogs
claude Nov 14, 2026
8fcca7f
Give the sign-up dialog its messages from a client provider
claude Nov 14, 2026
c536029
Take the sign-up dialog's text and the error copy from the catalog
claude Nov 14, 2026
2e10c73
Add a partial Swedish catalog and a Swedish test signup
claude Nov 14, 2026
5911881
Give the edit and unsubscribe pages their signup's language
claude Nov 14, 2026
b3d5f3c
Fit the Swedish Spots label, and warn when the e2e locale hook is on
claude Nov 14, 2026
45c4dce
Take the edit, cancel and unsubscribe pages' text from the catalog
claude Nov 14, 2026
3aebf1d
Name the case of a refused sign-up or edit in details.reason
claude Nov 14, 2026
b94d806
Merge #914's final branch into #915
claude Nov 14, 2026
e9d6a14
Merge #915's branch into #916
claude Nov 14, 2026
05eba67
Find the edit form's Swedish Spots field by its new label
claude Nov 14, 2026
56ce1b3
Merge #916's branch into #917
claude Nov 14, 2026
4eabed3
Word every sign-up and edit-page error from the catalog
claude Nov 14, 2026
91fae7d
Merge remote-tracking branch 'origin/claude/issue-631-error-reasons' …
claude Nov 14, 2026
57c8242
Find the Swedish Spots field by its catalog label; widen quantity_not…
claude Nov 14, 2026
8ac41eb
Write participant email subjects from the catalog, in the signup's la…
claude Nov 14, 2026
6f0cf51
Check the Swedish preview text is the subject
claude Nov 14, 2026
45f6bec
Write participant emails from the catalog, in the signup's language
claude Nov 14, 2026
2ab7365
Lint hard-coded text in the participant email templates
claude Nov 14, 2026
78df23f
Warn when the worker starts with E2E_UNSHIPPED_LOCALES set
claude Nov 14, 2026
9242a0f
Make no claim after an answer that isn't the API's error
claude Nov 14, 2026
50d2bd9
Take the calendar file's description and the share text from the catalog
claude Nov 14, 2026
3749e69
Make no claim when the edit page's save or cancel gets no answer
claude Nov 14, 2026
1e1ed68
Keep the slot's letters in the calendar file's name
claude Nov 14, 2026
76a7b50
Merge #918's final branch into #919
claude Nov 14, 2026
00d47a2
Merge #919's branch into #920
claude Nov 14, 2026
a393208
Merge #920's branch into #921
claude Nov 14, 2026
bad9f41
Name a new signup's columns and the Build tab's defaults in its language
claude Nov 14, 2026
40985a9
Say in the CHANGELOG that new signups' default names follow their lan…
claude Nov 14, 2026
8bc4be4
Reword the Build tab's language prop comment
claude Nov 14, 2026
b14b06a
Merge #921's branch into #925
claude Nov 14, 2026
435e410
Merge #925's branch into #926
claude Nov 14, 2026
eaa788a
Merge main into claude/issue-625-signup-locale
claude Nov 15, 2026
009a51b
Merge main (Next.js 15.5.29, #984, #806) into the client messages PR
claude Nov 15, 2026
3d90da2
Merge #897's final head into claude/issue-625-settings-control
claude Nov 15, 2026
271a335
Merge main: #897 landed as c1f13bd, same tree as its head
claude Nov 15, 2026
67dbde0
Raise the edit page budget for Next.js 15.5.29
claude Nov 15, 2026
0f5ae9d
Merge #899's final head into claude/issue-626-organizer-locale-core
claude Nov 15, 2026
e4c7170
Merge main: #899 landed as 1d2a721, same tree as its head
claude Nov 15, 2026
9d4ec17
Merge the client messages PR (main's Next.js 15.5.29, #984, #806) int…
claude Nov 15, 2026
1dee0ac
Raise the edit page budget for Next.js 15.5.29
claude Nov 15, 2026
2074a5f
Merge #901's final head into claude/issue-628-signup-row-loader
claude Nov 15, 2026
f1e9bb4
Merge main: #901 landed as c2fb12a, same tree as its head
claude Nov 15, 2026
f031cc5
Merge the dialog text PR (main's Next.js 15.5.29, #984, #806) into th…
claude Nov 15, 2026
1330c8e
Merge the Swedish seed PR (main's Next.js 15.5.29, #984, #806) into t…
claude Nov 15, 2026
47ec19d
Merge #902's final head into claude/issue-626-organizer-locale-column
claude Nov 15, 2026
d348453
Merge main: #902 landed as 9f39d58, same tree as its head
claude Nov 15, 2026
5487a05
Merge the edit page locale PR (main's Next.js 15.5.29, #984, #806) in…
claude Nov 16, 2026
4ccf859
Merge #903's final head into claude/issue-626-account-language
claude Nov 16, 2026
4dbb0cc
Merge main: #903 landed as f8dabd9, same tree as its head
claude Nov 16, 2026
a1fa37d
Merge the edit page text PR (main's Next.js 15.5.29, #984, #806) into…
claude Nov 16, 2026
d34b5b0
Merge the error reasons PR (main's Next.js 15.5.29, #984, #806) into …
claude Nov 16, 2026
084a0d4
Merge #904's final head into claude/issue-627-signup-starts-in-language
claude Nov 16, 2026
b31a87c
Merge main: #904 landed as e2b4f49, same tree as its head
claude Nov 16, 2026
7b0d70e
Raise the edit page budget for Next.js 15.5.29
claude Nov 16, 2026
a13405e
Merge the client error text PR (main's Next.js 15.5.29, #984, #806) i…
claude Nov 16, 2026
fd3afe4
Merge #905's final head into claude/issue-627-mcp-create-locale
claude Nov 16, 2026
300bfc7
Merge main: #905 landed as 950f718, same tree as its head
claude Nov 16, 2026
58de416
Merge the email subjects PR (main's Next.js 15.5.29, #984, #806) into…
claude Nov 16, 2026
0c3c170
Merge #906's final head into claude/issue-628-page-locale
claude Nov 16, 2026
02989f4
Merge main: #906 landed as 614a0d7, same tree as its head
claude Nov 16, 2026
eedebd5
Merge the email templates PR (main's Next.js 15.5.29, #984, #806) int…
claude Nov 16, 2026
b108a9b
Merge #907's final head into claude/issue-628-path-header
claude Nov 16, 2026
7797da1
Merge main: #907 landed as ba75aae, same tree as its head
claude Nov 16, 2026
329d114
Merge the calendar share text PR (main's Next.js 15.5.29, #984, #806)…
claude Nov 16, 2026
07d80d2
Merge #908's final head into claude/issue-625-locale-in-api
claude Nov 16, 2026
9694d0d
Merge main: #908 landed as 80d071b, same tree as its head
claude Nov 16, 2026
353242f
Merge the calendar file name PR (main's Next.js 15.5.29, #984, #806) …
claude Nov 16, 2026
7910cb1
Merge #909's final head into claude/issue-629-common
claude Nov 16, 2026
4320ec9
Merge main: #909 landed as debb086, same tree as its head
claude Nov 16, 2026
f242d12
Merge #910's final head into claude/issue-629-server-text
claude Nov 16, 2026
d9ec84e
Merge main: #910 landed as bda7dfd, same tree as its head
claude Nov 16, 2026
40116ab
Merge #911's final head into claude/issue-629-client-messages
claude Nov 16, 2026
17e8e0f
Merge main: #911 landed as 2f93094, same tree as its head
claude Nov 16, 2026
20a474d
Merge #912's final head into claude/issue-629-dialog-text
claude Nov 16, 2026
ac3e06f
Merge main: #912 landed as 2e2e314, same tree as its head
claude Nov 16, 2026
6c85da5
Merge #913's final head into claude/issue-629-swedish-seed
claude Nov 16, 2026
baefdf4
Merge main: #913 landed as 271e16d, same tree as its head
claude Nov 16, 2026
01f9d2b
Merge #914's final head into claude/issue-630-edit-page-locale
claude Nov 16, 2026
6a7d27e
Merge main: #914 landed as 9324bc0, same tree as its head
claude Nov 16, 2026
e97074e
Merge #915's final head into claude/issue-630-edit-page-text
claude Nov 16, 2026
b961f87
Merge main: #915 landed as c5ac17a, same tree as its head
claude Nov 16, 2026
54f38b7
Merge #916's final head into claude/issue-631-error-reasons
claude Nov 16, 2026
f58589b
Merge main: #916 landed as d492687, same tree as its head
claude Nov 16, 2026
4814f8b
Merge #917's final head into claude/issue-631-client-error-text
claude Nov 16, 2026
997b554
Merge main: #917 landed as fe30dcb, same tree as its head
claude Nov 16, 2026
17e294e
Merge #918's final head into claude/issue-632-email-subjects
claude Nov 16, 2026
278fd84
Merge main: #918 landed as 00c230a, same tree as its head
claude Nov 16, 2026
14aa4e4
Merge #919's final head into claude/issue-632-email-templates
claude Nov 16, 2026
9ffaccc
Merge main: #919 landed as 471b451, same tree as its head
claude Nov 16, 2026
eddba5d
Merge #920's final head into claude/issue-633-calendar-share-text
claude Nov 16, 2026
0c82935
Merge main: #920 landed as 809b797, same tree as its head
claude Nov 16, 2026
49229ce
Merge #921's final head into claude/issue-633-calendar-file-name
claude Nov 16, 2026
0861a72
Merge main: #921 landed as 360d235, same tree as its head
claude Nov 16, 2026
ce1f313
Merge #925's final head into claude/issue-634-default-columns
claude Nov 16, 2026
6395824
Merge main: #925 landed as 2035f0e, same tree as its head
claude Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to OpenSignup are documented here. Format follows [Keep a Ch
- A place for each organizer's own language (#626): migration `0015` adds `organizers.locale`, an empty, nullable text column. Nothing sets it yet, and nothing anyone sees follows it. It's read with the rest of the organizer's account, on each of their pages and each request from their AI assistant, in the query that already ran there, so neither sends another statement to the database. A stored value is passed along as it is, so one that names no language can't stop anyone signing in.
- The privacy page now lists, among what an organizer's account holds, the language they choose for their new signups (#626). Account Settings has a "Language for new signups" choice for it, which appears only once a second language has shipped to participants and offers only those, so it isn't there yet. New signups don't follow it yet either.
- New signups start in their organizer's language (#627), once there's a choice: made by `POST /api/signups`, the New signup form or Magic Compose, a signup takes the organizer's saved language, else the instance's `DEFAULT_LOCALE`, else the top language their browser asks for, else English, each only if it has shipped to participants. While only English has shipped, which is today, they store no language, as before, so nothing changes yet. A `settings.locale` sent to `POST /api/signups` still wins, and is still refused unless it has shipped. Changing the organizer's language later doesn't move signups already made. `signup.created` activity rows for a signup created with a language gain `locale` and `localeSource` (`setting`, `instance`, `browser`, `api` or `default`), and the privacy page's activity-log paragraph says so. The AI connector's `create_signup` follows the same rule, without the browser step (an assistant's browser language is its vendor's, not the organizer's), and takes an optional `locale`, which wins over the organizer's and is recorded as `api`; one that hasn't shipped to participants (anything but `en` so far) is refused with `invalid_input` on `locale`, naming the ones that have, before anything is created or counted against the hourly create limit.
- A new signup's two starting columns, "What" and "Date", are named in the signup's language (#634), as are the names the Build tab gives a field saved without one ("Untitled") and a new list's first option ("Option 1"): participants read all four. The columns' refs stay `what` and `date` in every language. Signups made by Magic Compose or an AI assistant don't start from these columns, so they're unaffected. While only English has shipped, nothing changes. The Build tab also sorts its group headings in the signup's alphabetical order. It used to sort them in the server's language and again in the browser's, so where the two disagree (Swedish puts Å, Ä and Ö after Z) the browser redrew the list and logged an error.
- An organizer who opens their own signup's public link now sees a strip across the top of the page (#647), styled like the organizer app's header and above the brand mark, outside the page's content: "**Your signup.** Only organizers see this bar.", with **See responses** and **Edit signup**, which go to the signup's Responses and Build tabs. Screen readers meet it as an "Organizer" navigation landmark. It shows on an open or closed signup to any member of the signup's workspace, viewers included, who is signed in on that browser. Participants see no change, and neither does an organizer from another workspace. The page now reads the organizer's session; a visitor with no session cookie still costs it nothing, since Auth.js answers without the database, and a signed-in organizer's visit sends two more statements (the session and their workspaces), which `budgets.json` pins as its own case.
- `pnpm oauth:keys rotate` and `pnpm oauth:keys retire <kid>` rotate the key that signs connected AI assistants' access tokens (#564). `rotate` adds a key and lists the active ones; after it, restart every web instance and wait 16 minutes. `retire` refuses an unknown key, and refuses an old key until a newer one has been signing for an access token's lifetime plus the verifier's 15 seconds of clock tolerance, which catches a forgotten restart; it can only see that one instance moved to the new key, so with several instances every one still has to be restarted first. `retire --force <kid>` retires a leaked key at once, at the cost of one refresh for each connected assistant, and still refuses the newest key. Each instance now records when it starts signing with a key (a new `signing_since` column on `oauth_signing_keys`, added by migration `0013`), and re-reads its signing keys from the table every 5 minutes, in the background, as well as on an unknown key, so a retired key stops being trusted without a restart; if that re-read fails, it keeps verifying with the keys it holds. Requests that need the keys at the same time share one read. Neither the CLI nor the server log prints a failed key query's parameters, which for a new key include its private half. The steps are in `docs/connect-ai-assistant.md`. In the Docker setup, run it as `docker compose exec web pnpm oauth:keys …`.
- Magic Compose asks a few questions when a description doesn't say what people sign up for (#570). A description that is only an event's name, like "Bake sale", used to get three "TBD" rows or made-up jobs. Now the AI answers with the topics the description leaves out (what, when, how many) and two to four suggestions for what people could sign up for, in the description's language; it never suggests dates or counts, which the page asks for with its own controls. The organizer's answers go back with the description, and that second call always drafts or refuses, with "TBD:" rows for anything left blank and for **Draft with placeholders**. A description that says what but not when or how many still drafts straight away, with "TBD:" rows where the slots need dates or times, and a list of items, roles or tasks, or a schedule of dated practices or shifts, counts as saying what. A first reply with questions the page can't show (no "what", or one usable option) is tried once more on the same quota, and extra options are cut to four. A slot gets no limit only when the description or the answers say there's none. Both calls count toward the hour's AI drafts, so the limit goes from 10 to 12 an hour. The privacy page now says the answers go to the AI provider along with the description. `pnpm eval:magic-compose` scores questions: a case can expect them (`questions.*` checks), or give `answers` to send after a first call that must ask, and the draft made from them is scored. `ev_008`, the vague team prompt, now expects questions instead of 1-6 placeholder slots (and is about a swim club, not the soccer team of the prompt's own example, so it scores the rule rather than recall), and ten new made-up cases cover prompts that must ask, near misses that must still draft, and drafts from answers. `pnpm eval:mcp` passes an assistant that asks the organizer on those cases and skips the ones with answers.
Expand Down
93 changes: 93 additions & 0 deletions src/app/app/(chrome)/signups/[id]/build/page.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// @vitest-environment jsdom

import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, render } from '@testing-library/react';
import { ship } from '@/i18n/testing/ship';

// Unit tests have no server environment. The instance sets no language
// unless a test sets one. Text comes from the catalog in English, and as a
// stand-in naming its key in any other language.
const instance = vi.hoisted(() => ({ defaultLocale: undefined as string | undefined }));
vi.mock('@/i18n/server', async () => ({
instanceDefaultLocale: () => instance.defaultLocale,
getServerTranslator: (await import('@/i18n/testing/translator')).getTestServerTranslator,
}));

// The signup as the page loads it, and what the page needs around it: a
// session and the view it records, which need a database.
const stored = vi.hoisted(() => ({ settings: {} as Record<string, unknown> }));
vi.mock('@/auth/session', () => ({
requireOrganizerSession: async () => ({}),
toActor: () => ({ kind: 'anonymous' }),
}));
vi.mock('@/services/signups.cached', () => ({
loadSignupForOrganizer: async () => ({
ok: true,
value: {
id: 'sig_1',
workspaceId: 'ws_1',
title: 'Bake sale',
description: '',
settings: stored.settings,
fields: [],
slots: [],
},
}),
loadCommittedBySlotForOrganizer: async () => ({ ok: true, value: {} }),
}));
vi.mock('@/lib/view-tracker', () => ({ trackOrganizerView: async () => {} }));
const builder = vi.hoisted(() => ({ props: undefined as Record<string, unknown> | undefined }));
vi.mock('@/components/build-wysiwyg/BuildWysiwyg', () => ({
BuildWysiwyg: (props: Record<string, unknown>) => {
builder.props = props;
return null;
},
}));

const { default: BuildTab } = await import('./page');

/** What the page hands the Build tab's client components. */
async function handedDown() {
render(await BuildTab({ params: Promise.resolve({ id: 'sig_1' }) }));
const { locale, fieldDefaults } = builder.props ?? {};
return { locale, fieldDefaults };
}

afterEach(() => {
cleanup();
stored.settings = {};
instance.defaultLocale = undefined;
builder.props = undefined;
});

describe('Build tab: the signup’s language', () => {
it('hands down English, and English defaults, for an English signup', async () => {
expect(await handedDown()).toEqual({
locale: 'en',
fieldDefaults: { name: 'Untitled', firstChoice: 'Option 1' },
});
});

it('hands down the signup’s language, and its defaults from the catalog in it', async () => {
ship('participant', ['en', 'sv']);
stored.settings = { locale: 'sv' };
expect(await handedDown()).toEqual({
locale: 'sv',
fieldDefaults: {
name: 'participant.defaults.untitledField in sv',
firstChoice: 'participant.defaults.firstChoice in sv',
},
});
});

it('takes the language participants get: the instance’s, for a signup with none', async () => {
ship('participant', ['en', 'sv']);
instance.defaultLocale = 'sv';
expect((await handedDown()).locale).toBe('sv');
});

it('stays English for a stored language that hasn’t shipped', async () => {
stored.settings = { locale: 'sv' };
expect((await handedDown()).locale).toBe('en');
});
});
10 changes: 10 additions & 0 deletions src/app/app/(chrome)/signups/[id]/build/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { requireOrganizerSession, toActor } from '@/auth/session';
import { signupLocale } from '@/i18n/config';
import { getServerTranslator, instanceDefaultLocale } from '@/i18n/server';
import { loadCommittedBySlotForOrganizer, loadSignupForOrganizer } from '@/services/signups.cached';
import { trackOrganizerView } from '@/lib/view-tracker';
import { BuildWysiwyg } from '@/components/build-wysiwyg/BuildWysiwyg';
Expand All @@ -15,6 +17,12 @@ export default async function BuildTab({ params }: PageParams) {
const filled = await loadCommittedBySlotForOrganizer(actor, id);
if (!filled.ok) return null;
const sig = result.value;
// The Build tab's text is the organizer's, in English for now, but what it
// writes into the signup for participants to read is in the signup's
// language: decided here and handed down as props, so the browser loads no
// catalog.
const locale = signupLocale(sig.settings.locale, instanceDefaultLocale());
const t = getServerTranslator(locale, 'participant.defaults');
await trackOrganizerView({
actor,
signupId: sig.id,
Expand All @@ -38,6 +46,8 @@ export default async function BuildTab({ params }: PageParams) {
}))}
initialSettings={SignupSettingsSchema.parse(sig.settings)}
committedBySlot={filled.value}
locale={locale}
fieldDefaults={{ name: t('untitledField'), firstChoice: t('firstChoice') }}
/>
</>
);
Expand Down
79 changes: 79 additions & 0 deletions src/components/build-wysiwyg/BuildWysiwyg.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const baseProps = {
initialSlots: [],
initialSettings: settings,
committedBySlot: {},
locale: 'en' as const,
fieldDefaults: { name: 'Untitled', firstChoice: 'Option 1' },
};

function findSheet(container: HTMLElement): HTMLElement | null {
Expand Down Expand Up @@ -209,6 +211,83 @@ describe('BuildWysiwyg — group headers', () => {
});
});

describe('BuildWysiwyg — the signup’s language', () => {
afterEach(() => {
vi.unstubAllGlobals();
});

/** A signup grouped by a text field, its groups in no order. */
const groupedBy = (locale: 'en' | 'sv') =>
render(
<BuildWysiwyg
{...baseProps}
locale={locale}
initialFields={[
{
id: 'f-who',
ref: 'who',
label: 'Who',
fieldType: 'text',
sortOrder: 0,
config: { fieldType: 'text', maxLength: 200 },
},
]}
initialSettings={{ ...settings, groupByFieldRefs: ['who'] }}
initialSlots={['Ödla', 'Zebra', 'Äpple', 'Apa'].map((who, i) => ({
id: `slot_${i}`,
capacity: 1,
sortOrder: i,
values: { who },
}))}
/>,
);
const headings = () =>
screen
.getAllByRole('button', { name: /Group header/ })
.map((b) => b.getAttribute('aria-label')?.replace('Group header \u2014 ', ''));

it('sorts group headings in its alphabetical order, Å, Ä and Ö after Z in Swedish', () => {
groupedBy('sv');
expect(headings()).toEqual(['Apa', 'Zebra', 'Äpple', 'Ödla']);
});

it('sorts them in English’s for an English signup, whatever the browser’s language', () => {
groupedBy('en');
expect(headings()).toEqual(['Apa', 'Äpple', 'Ödla', 'Zebra']);
});

it('names a field added without a name, and its first option, with the defaults it’s given', async () => {
const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => {
const body = JSON.parse(String(init?.body)) as Record<string, unknown>;
return new Response(JSON.stringify({ data: { id: 'f-new', sortOrder: 0, ...body } }), {
status: 201,
headers: { 'Content-Type': 'application/json' },
});
});
vi.stubGlobal('fetch', fetchMock);
render(
<BuildWysiwyg
{...baseProps}
locale="sv"
fieldDefaults={{ name: 'Namnlös', firstChoice: 'Alternativ 1' }}
/>,
);

fireEvent.click(screen.getByRole('button', { name: /Fields/ }));
fireEvent.click(screen.getByRole('button', { name: 'Add field' }));
fireEvent.click(screen.getByRole('button', { name: 'List' }));
fireEvent.click(screen.getByRole('button', { name: /^Add field$/ }));

await waitFor(() => expect(fetchMock).toHaveBeenCalled());
const [url, init] = fetchMock.mock.calls[0]!;
expect(url).toBe('/api/signups/sig_t/fields');
expect(JSON.parse(String(init?.body))).toMatchObject({
label: 'Namnlös',
config: { fieldType: 'enum', choices: ['Alternativ 1'] },
});
});
});

describe('BuildWysiwyg — duplicate', () => {
afterEach(() => {
vi.unstubAllGlobals();
Expand Down
34 changes: 30 additions & 4 deletions src/components/build-wysiwyg/BuildWysiwyg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { useReorderable } from '../build-shared/useReorderable';
import { Editable } from './Editable';
import { EditingRail } from './EditingRail';
import { FieldsPopover } from './FieldsPopover';
import type { FieldDefaults } from './InlineFieldForm';
import { WysiwygGroup, type SlotGroup } from './WysiwygGroup';
import type { CatalogLocale } from '@/i18n/config';
import { isBlankSlotValue } from '@/lib/blank-slot-value';
import { MAX_CHOICES } from '@/schemas/slot-field-basics';
import type { SlotFieldDefinition } from '@/schemas/slot-fields';
Expand All @@ -36,6 +38,17 @@ type BuildWysiwygProps = {
* Slots added in this session start empty, so they read 0 without an entry.
*/
committedBySlot: Record<string, number>;
/**
* The signup's language, the one its participants get. Group headings sort
* in its alphabetical order, so the server's render and the browser's
* agree: each sorting in its own language could disagree. Dates and times
* here stay English, like the rest of the organizer's screens for now:
* they're formatted in the browser too, whose ICU can abbreviate a
* language's days differently from the server's.
*/
locale: CatalogLocale;
/** What a new field gets for what the organizer leaves unset, in the signup's language. */
fieldDefaults: FieldDefaults;
};

const EMPTY_GROUP_KEY = '__empty__';
Expand Down Expand Up @@ -65,8 +78,15 @@ function sheetMaxWidthClass(fieldCount: number): string {
return 'md:max-w-[960px]';
}

/** Bucket rows by the group field's value. Empty / missing values go into `__empty__`. */
function partitionRows(rows: BuildRow[], groupField: BuildField | null): SlotGroup[] {
/**
* Bucket rows by the group field's value, in `locale`'s alphabetical order.
* Empty / missing values go into `__empty__`, last.
*/
function partitionRows(
rows: BuildRow[],
groupField: BuildField | null,
locale: CatalogLocale,
): SlotGroup[] {
if (!groupField) {
return [{ key: '__flat__', rawValue: '', rows }];
}
Expand All @@ -84,7 +104,7 @@ function partitionRows(rows: BuildRow[], groupField: BuildField | null): SlotGro
const keys = [...buckets.keys()].sort((a, b) => {
if (a === EMPTY_GROUP_KEY) return 1;
if (b === EMPTY_GROUP_KEY) return -1;
return a.localeCompare(b);
return a.localeCompare(b, locale);
});
return keys.map((k) => ({
key: k,
Expand All @@ -100,6 +120,8 @@ export function BuildWysiwyg({
initialSlots,
initialSettings,
committedBySlot,
locale,
fieldDefaults,
}: BuildWysiwygProps) {
const {
state,
Expand Down Expand Up @@ -161,7 +183,10 @@ export function BuildWysiwyg({
// collapsed row's anchor — order matters, no type-based promotion here.
const displayFields = state.fields.filter((f) => f.ref !== groupField?.ref);

const groups = useMemo(() => partitionRows(state.rows, groupField), [state.rows, groupField]);
const groups = useMemo(
() => partitionRows(state.rows, groupField, locale),
[state.rows, groupField, locale],
);
// Groups are keyed by their value, so a heading rename would remount the
// group. A click outside the heading's picker commits it on mousedown, and
// the remount before mouseup lost the click: Add a slot under the renamed
Expand Down Expand Up @@ -425,6 +450,7 @@ export function BuildWysiwyg({
open={fieldsOpen}
onOpenChange={setFieldsOpen}
fields={state.fields}
fieldDefaults={fieldDefaults}
groupByFieldRef={state.groupByFieldRef}
reminderFieldRef={state.reminderFieldRef}
onAddField={(name, config) => {
Expand Down
6 changes: 6 additions & 0 deletions src/components/build-wysiwyg/FieldsPopover.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function makeField(overrides: Partial<BuildField> = {}): BuildField {
};
}

/** A new field's defaults, as the Build tab page gives them for an English signup. */
const DEFAULTS = { name: 'Untitled', firstChoice: 'Option 1' };

type UpdateFieldFn = (
fieldId: string,
patch: { name?: string; config?: SlotFieldConfig },
Expand Down Expand Up @@ -49,6 +52,7 @@ function renderPopover(overrides: RenderProps = {}) {
open={overrides.open ?? true}
onOpenChange={onOpenChange}
fields={overrides.fields ?? [makeField()]}
fieldDefaults={DEFAULTS}
groupByFieldRef={overrides.groupByFieldRef ?? null}
reminderFieldRef={overrides.reminderFieldRef ?? null}
onAddField={onAddField}
Expand Down Expand Up @@ -224,6 +228,7 @@ describe('FieldsPopover', () => {
open={false}
onOpenChange={noopOpen}
fields={[makeField()]}
fieldDefaults={DEFAULTS}
groupByFieldRef={null}
reminderFieldRef={null}
onAddField={onAddField}
Expand All @@ -239,6 +244,7 @@ describe('FieldsPopover', () => {
open
onOpenChange={noopOpen}
fields={[makeField()]}
fieldDefaults={DEFAULTS}
groupByFieldRef={null}
reminderFieldRef={null}
onAddField={onAddField}
Expand Down
Loading
Loading