diff --git a/docs/de/platform/knowledge/structured-data.md b/docs/de/platform/knowledge/structured-data.md index 374dec35cd..15cb11cc9c 100644 --- a/docs/de/platform/knowledge/structured-data.md +++ b/docs/de/platform/knowledge/structured-data.md @@ -38,7 +38,7 @@ Zum Pflegen der Organisationsdatensätze brauchst du die Rolle Redakteur oder h 2. Prüfe **Sprache**. Das Feld ist mit `en` vorbelegt; passe es an die Sprache des Kontakts an. 3. Wähle **Speichern**. Der Kontakt erscheint mit seinen Angaben und dem Erstellungsdatum in der Tabelle. -Vor dem Speichern prüft das Formular jedes Feld gegen das, was Tale speichert: **Name** bis 300 Zeichen, **Telefon** bis 50, **Sprache** bis 20 und bei der **E-Mail** höchstens 64 Zeichen vor dem `@`. Ein Wert über einer Grenze wird unter seinem Feld genannt, und gespeichert wird erst, wenn du ihn korrigiert hast. +Vor dem Speichern prüft das Formular jedes Feld gegen das, was Tale speichert: **Name** bis 300 Zeichen, **Telefon** bis 50, **Sprache** bis 20 und bei der **E-Mail** höchstens 64 Zeichen vor dem `@`. Ein Wert über einer Grenze wird unter seinem Feld genannt, und gespeichert wird erst, wenn du ihn korrigiert hast. **Telefon** nimmt nur Ziffern, Leerzeichen und `+ ( ) . -` an. Ein anderes Zeichen bleibt stehen, wo du es eingegeben hast, ein Hinweis unter dem Feld sagt es dir, und gespeichert wird erst, wenn du es entfernt hast. Um nur die Kontakte einer Sprache zu sehen, wähle über der Kontaktliste **Filter** und unter **Sprache** die gewünschte Sprache. Eine Sprache schließt ihre regionalen Varianten ein: **FR** zeigt Kontakte mit der Sprache `fr`, `fr-CH` oder `fr_CA`. Ein Kontakt ohne Sprache erscheint nur, solange keine Sprache gewählt ist. diff --git a/docs/en/platform/knowledge/structured-data.md b/docs/en/platform/knowledge/structured-data.md index f2e5ce89fb..07105b8049 100644 --- a/docs/en/platform/knowledge/structured-data.md +++ b/docs/en/platform/knowledge/structured-data.md @@ -38,7 +38,7 @@ You need an Editor role or higher to maintain organization records. Open **Knowl 2. Check **Locale**, which starts as `en`, and set the language appropriate to the contact. 3. Choose **Save**. The new row appears in Contacts with its details and added date. -The form holds each field to what Tale stores before it saves: a **Name** of up to 300 characters, a **Phone** of up to 50, a **Locale** of up to 20, and an **Email** with at most 64 characters before the `@`. A value past a limit is named under its field, and nothing is saved until you fix it. +The form holds each field to what Tale stores before it saves: a **Name** of up to 300 characters, a **Phone** of up to 50, a **Locale** of up to 20, and an **Email** with at most 64 characters before the `@`. A value past a limit is named under its field, and nothing is saved until you fix it. **Phone** takes digits, spaces and `+ ( ) . -` only. Another character stays where you typed it, a message under the field says so, and nothing is saved until you remove it. To see only the contacts in one language, choose **Filter** above the Contacts list and pick the language under **Locale**. A language includes its regional variants: **FR** lists contacts whose locale is `fr`, `fr-CH`, or `fr_CA`. A contact without a locale appears only while no language is picked. diff --git a/docs/fr/platform/knowledge/structured-data.md b/docs/fr/platform/knowledge/structured-data.md index 767fe58c56..1adc865f39 100644 --- a/docs/fr/platform/knowledge/structured-data.md +++ b/docs/fr/platform/knowledge/structured-data.md @@ -38,7 +38,7 @@ Le rôle Rédacteur ou un rôle supérieur est nécessaire pour modifier les fic 2. Vérifie **Langue**, dont la valeur initiale est `en`, et adapte-la à la langue du contact. 3. Choisis **Enregistrer**. La fiche apparaît dans Contacts avec ses coordonnées et sa date d’ajout. -Avant d’enregistrer, le formulaire vérifie chaque champ selon ce que Tale conserve : un **Nom** de 300 caractères au plus, un **Téléphone** de 50 au plus, une **Langue** de 20 au plus et un **Courriel** d’au plus 64 caractères avant le `@`. Une valeur qui dépasse une limite est signalée sous son champ, et rien n’est enregistré tant que tu ne l’as pas corrigée. +Avant d’enregistrer, le formulaire vérifie chaque champ selon ce que Tale conserve : un **Nom** de 300 caractères au plus, un **Téléphone** de 50 au plus, une **Langue** de 20 au plus et un **Courriel** d’au plus 64 caractères avant le `@`. Une valeur qui dépasse une limite est signalée sous son champ, et rien n’est enregistré tant que tu ne l’as pas corrigée. **Téléphone** n’accepte que des chiffres, des espaces et `+ ( ) . -`. Un autre caractère reste là où tu l’as saisi, un message sous le champ te le signale, et rien n’est enregistré tant que tu ne l’as pas retiré. Pour n’afficher que les contacts d’une langue, choisis **Filtre** au-dessus de la liste des contacts, puis la langue sous **Langue**. Une langue inclut ses variantes régionales : **FR** affiche les contacts dont la langue est `fr`, `fr-CH` ou `fr_CA`. Un contact sans langue n’apparaît que tant qu’aucune langue n’est choisie. diff --git a/services/platform/app/features/contacts/components/contact-create-dialog.test.tsx b/services/platform/app/features/contacts/components/contact-create-dialog.test.tsx index caee8a2141..5c9287f079 100644 --- a/services/platform/app/features/contacts/components/contact-create-dialog.test.tsx +++ b/services/platform/app/features/contacts/components/contact-create-dialog.test.tsx @@ -103,6 +103,34 @@ describe('ContactCreateDialog', () => { }); }); + it('keeps letters in the phone and creates nothing until they are removed (#3825)', async () => { + const onClose = vi.fn(); + const { user } = render( + , + ); + + await user.type(screen.getByLabelText(/email/i), 'jane@example.com'); + const phoneInput = screen.getByLabelText(/phone/i); + await user.type(phoneInput, '+41abc'); + await user.click(screen.getByRole('button', { name: /save/i })); + + // Not `+41`: the shared fields used to strip the letters and the + // schema then passed what was left. + await waitFor(() => { + expect(phoneInput).toHaveFocus(); + }); + expect(phoneInput).toHaveValue('+41abc'); + expect(screen.getByRole('alert')).toHaveTextContent( + 'Enter a phone number using digits and + ( ) - only', + ); + expect(mockMutateAsync).not.toHaveBeenCalled(); + expect(onClose).not.toHaveBeenCalled(); + }); + it('shows a duplicate-email error toast on CONTACT_DUPLICATE_EMAIL', async () => { mockMutateAsync.mockRejectedValueOnce( new AppError({ code: 'CONTACT_DUPLICATE_EMAIL' }), diff --git a/services/platform/app/features/contacts/components/contact-edit-dialog.test.tsx b/services/platform/app/features/contacts/components/contact-edit-dialog.test.tsx index 86b3b0583e..c2a6e5cac8 100644 --- a/services/platform/app/features/contacts/components/contact-edit-dialog.test.tsx +++ b/services/platform/app/features/contacts/components/contact-edit-dialog.test.tsx @@ -11,6 +11,8 @@ import { ContactEditDialog } from './contact-edit-dialog'; const mockMutateAsync = vi.fn(); const mockToast = vi.fn(); +const PHONE_MESSAGE = 'Enter a phone number using digits and + ( ) - only'; + vi.mock('@tale/ui/use-toast', () => ({ toast: (...args: unknown[]) => mockToast(...args), })); @@ -112,7 +114,7 @@ describe('ContactEditDialog', () => { }); }); - it('strips letters from the phone field and explains why', async () => { + it('keeps letters typed into the phone field and explains why', async () => { const onClose = vi.fn(); const { user } = render( { await user.clear(phoneInput); await user.type(phoneInput, '00kkkk'); - expect(phoneInput).toHaveValue('00'); - expect( - await screen.findByText( - 'Enter a phone number using digits and + ( ) - only', - ), - ).toBeInTheDocument(); + // Never rewritten behind the person's back (#3825): what they typed + // stays, and the field says why it can't be saved yet. + expect(phoneInput).toHaveValue('00kkkk'); + expect(await screen.findByText(PHONE_MESSAGE)).toBeInTheDocument(); + expect(phoneInput).toHaveAttribute('aria-invalid', 'true'); + }); + + // #3825 (duplicates #3824, #3826): the letters used to be stripped as they + // were typed and the schema then passed the cleaned value, so Save sent + // `00` for `00kkkk` and the only explanation vanished. + describe('a phone holding a character no number has', () => { + it.each(['00kkkk', '+41abc'])( + 'blocks Save on %s and keeps the error under the field', + async (typed) => { + const onClose = vi.fn(); + const { user } = render( + , + ); + + const phoneInput = screen.getByDisplayValue('+1-555-0100'); + await user.clear(phoneInput); + await user.type(phoneInput, typed); + await user.click(screen.getByRole('button', { name: /save/i })); + + // The refused submit hands focus back to the field: proof the + // submit's validation ran and failed, not merely that it is pending. + await waitFor(() => { + expect(phoneInput).toHaveFocus(); + }); + expect(phoneInput).toHaveValue(typed); + expect(phoneInput).toHaveAttribute('aria-invalid', 'true'); + expect(screen.getByRole('alert')).toHaveTextContent(PHONE_MESSAGE); + expect(mockMutateAsync).not.toHaveBeenCalled(); + expect(mockToast).not.toHaveBeenCalled(); + expect(onClose).not.toHaveBeenCalled(); + }, + ); + + it('saves the number once the person removes the letters', async () => { + const { user } = render( + , + ); + + const phoneInput = screen.getByDisplayValue('+1-555-0100'); + await user.clear(phoneInput); + await user.type(phoneInput, '00kkkk'); + await user.click(screen.getByRole('button', { name: /save/i })); + await waitFor(() => { + expect(phoneInput).toHaveFocus(); + }); + + await user.type(phoneInput, '{Backspace>4/}'); + expect(phoneInput).toHaveValue('00'); + await waitFor(() => { + expect(screen.queryByRole('alert')).not.toBeInTheDocument(); + }); + await user.click(screen.getByRole('button', { name: /save/i })); + + await waitFor(() => { + expect(mockMutateAsync).toHaveBeenCalledWith({ + contactId: 'contact-1', + name: 'John', + email: 'test@example.com', + phone: '00', + locale: 'en', + }); + }); + }); + + it.each(['+41 79 123 45 67', '+1 (555) 010-0100', '079.123.45.67'])( + 'still saves %s, digits and phone punctuation only', + async (number) => { + const { user } = render( + , + ); + + const phoneInput = screen.getByDisplayValue('+1-555-0100'); + await user.clear(phoneInput); + await user.paste(number); + expect(screen.queryByRole('alert')).not.toBeInTheDocument(); + await user.click(screen.getByRole('button', { name: /save/i })); + + await waitFor(() => { + expect(mockMutateAsync).toHaveBeenCalledWith( + expect.objectContaining({ phone: number }), + ); + }); + }, + ); }); it('shows a visible, localized inline error when a required field is emptied', async () => { diff --git a/services/platform/app/features/contacts/components/contact-form-fields.tsx b/services/platform/app/features/contacts/components/contact-form-fields.tsx index 70ca104347..2ffc1d2372 100644 --- a/services/platform/app/features/contacts/components/contact-form-fields.tsx +++ b/services/platform/app/features/contacts/components/contact-form-fields.tsx @@ -12,8 +12,12 @@ import { useT } from '@/lib/i18n/client'; import type { ContactFormValues } from '../hooks/use-contact-form'; -/** Digits plus the punctuation people type in phone numbers. */ -const PHONE_ALLOWED = /[^\d+().\s-]/g; +/** + * A character no phone number holds: anything but digits and the punctuation + * people type in them (`CONTACT_PHONE_PATTERN`'s alphabet). Not global, so + * `test` doesn't resume from the previous match. + */ +const PHONE_FORBIDDEN_CHARACTER = /[^\d+().\s-]/; interface ContactFormFieldsProps { register: UseFormRegister; @@ -77,13 +81,13 @@ export function ContactFormFields({ label={tContacts('phone')} placeholder={tContacts('phonePlaceholder')} {...register('phone', { - // Refuse letters, but say so — silent stripping feels like a - // broken keyboard. Digits and phone punctuation stay. + // Name a letter as it is typed, but keep it in the field: stripping + // it changed the number behind the person's back, and Save then + // sent the cleaned value (`00kkkk` became `00`) once this message + // was gone (#3825). The schema refuses the same characters, so + // Save stays blocked until they are removed. onChange: (event) => { - const raw = event.target.value; - const cleaned = raw.replace(PHONE_ALLOWED, ''); - if (raw !== cleaned) { - event.target.value = cleaned; + if (PHONE_FORBIDDEN_CHARACTER.test(event.target.value)) { setError('phone', { type: 'manual', message: tCommon('validation.phone'), diff --git a/services/platform/tests/manual/reference/automation.md b/services/platform/tests/manual/reference/automation.md index bf4ca69b40..caeac69fea 100644 --- a/services/platform/tests/manual/reference/automation.md +++ b/services/platform/tests/manual/reference/automation.md @@ -410,6 +410,7 @@ Legend: ✅ fully automated · 🔶 partially automated · ⛔ manual-only (no s | [projects](../suites/projects.md) | A project switch from the Files tab (#3918): the breadcrumb switcher keeps `/files` but leaves the previous project's `?folderId=` behind, and the Files route keys the tab by organization and project, so the project switched to opens at its root — no row claims `aria-current`, the drop zone reads **Add file** (`projects.files.addButton`) and its upload names that project with no `folderId`, whether the project is empty or has folders of its own; a project opened fresh uploads to its root, and a folder picked in the project on screen or named by its own `?folderId=` stays the upload target | ✅ route + component | `app/routes/dashboard/$id/projects/$projectId/files.test.tsx`, `app/features/projects/components/project-breadcrumb-switcher.test.tsx` | | [knowledge](../suites/knowledge.md) | `KNOW-F25` half: a documents read that fails beside loaded folders keeps the folders under one notice with **Try again** (`documents.loadFailed`), counts them as **the first N — the rest couldn't be loaded**, never **Showing all**, and reads a search that matches no folder as **No results among the loaded items** with the search box kept; with more folders than one page, a search that matches them all and its clearing keep every loaded folder on screen; a folder whose documents answer empty lists its subfolders with no notice; nothing at all to list is the table's error state. Through the real hooks, adapters and four-attempt retry policy against a closed synthetic transport: a keyboard retry that fails (the folders and the notice stay, focus on the region) and one that heals (exact count), a background retry that keeps a search and an open **Rename folder** draft, a focused **Try again** kept through a background re-failure and handed to the region on heal, EN/DE/FR; `useListPage` takes the host's `loadFailed`, keeps rows through a first-load retry, and keeps every loaded row reachable while halted through managed and controlled search and filter resets; `DataTable` never says "all" for a stopped list; the paginated hook stays `unavailable` through a retry | ✅ component + unit | `app/features/documents/components/documents-table.read-failure.test.tsx`, `app/hooks/use-cached-paginated-query.test.tsx`, `packages/ui/src/hooks/use-list-page.test.ts`, `packages/ui/src/components/data-table/data-table.test.tsx` | | [knowledge](../suites/knowledge.md) | Contact details dialog (`dialogs.contactInfo.title`); **New email** / **Edit** in the header; Cancel returns to the details | ✅ automated | `app/features/contacts/components/contact-view-dialog.test.tsx` | +| [knowledge](../suites/knowledge.md) | The contact create and edit forms keep what was typed into **Phone** (#3825): a character no phone number holds (`00kkkk`, `+41abc`) stays in the field, which says so under itself as it is typed (`common.validation.phone`); **Save** sends nothing, keeps that message and hands focus back to the field until the characters are removed, and the corrected number then saves as typed (never a silently stripped `00` or `+41`); digits with `+`, spaces, dashes, dots and parentheses save unchanged | 🔶 component | `app/features/contacts/components/contact-edit-dialog.test.tsx`, `app/features/contacts/components/contact-create-dialog.test.tsx`; the German and French message and a screen reader's announcement in a real browser stay manual | | [knowledge](../suites/knowledge.md) | `KNOW-B21` (the component half; the real stack, the reload and the screen reader stay manual): the contacts list's checkboxes follow the row menu's rule (`canEditContact`: a writer, on a manually entered or uploaded contact) — a synced or conversation contact has no checkbox and no **Delete**, **Select all** and **Delete selected** reach only the others, a contact a sync took over after it was ticked drops out of the bar and is never deleted, a Member gets no checkbox, and a page where no row can be selected names its select column **Select row** instead of a blank header (axe) | 🔶 component | `app/features/contacts/components/contact-table.bulk-delete.test.tsx` (the real column config, row menu, selection and bulk bar), `packages/ui/src/components/data-table/data-table.test.tsx` | | [knowledge](../suites/knowledge.md) | Retrieval admits every fused candidate against its live document BEFORE the page is cut (a trashed top match never empties a `limit: 1` page; `limit: 1` is a prefix of `limit: 3`), repeated passages are dropped after admission, `fusedScore` / `legs` / `diagnostics.admitted` are answered, an active entry's delete de-indexes its document at once, `` never leads a passage | ✅ automated | `lib/knowledge/retrieve.test.ts`, `lib/knowledge/dedupe.test.ts`, `backend/core/knowledge/search.test.ts`, `backend/domains/knowledge_entries/service.delete.test.ts`, `lib/knowledge/html-to-text.test.ts`, the `knowledge RAG loop` lane in `backend:integration` | | [knowledge](../suites/knowledge.md) | A document rewritten, replaced or deleted while its indexing job is queued or running never comes back into the corpus: the indexer asks the release seam's own liveness predicate before it downloads and again after it claims its corpus row, a slice whose row was released underneath stops as `released` (no chunk insert on a missing row, no re-claim of the dead ref), and `indexUploadedFile` ends such a run without a `failed` status, a rethrow or a retry | ✅ automated | `backend/core/knowledge/indexing.test.ts`, `backend/domains/knowledge/service.released.test.ts`, `backend/domains/knowledge/service.status-codes.test.ts`, the `indexing vs release` lanes in `backend:integration` (`checkIndexingReleaseRace`: the release landing during the embedding of a single-slice and of a later slice, on the real worker; the already-superseded late job) |