Some checks failed
Formulaire in-app de remontée de bug / suggestion pour les utilisateurs connectés (PR 1/2 de l'issue #80). - Modèle Prisma `ContactMessage` (+ relation inverse sur `UserProfile`) et migration `20260908120000_contact_message` — table neuve, aucun backfill. `authorId` nullable + `onDelete: SetNull` : un signalement survit à la suppression de son compte. - Contrat partagé `schemas/contact.ts` : `CONTACT_MESSAGE_TYPES`, `submitContactMessageSchema` (type enum, message 10-5000 trim, pageUrl / appVersion optionnels — jamais le user-agent). - Module API `contact` : `POST /contact` (`requireAuth`, monté `/contact`), `204` sans corps. Le user-agent est lu de l'en-tête de requête, jamais du corps. Émet `analytics.recordEvent(contact.submitted, …)`. - Page `/parametres/contact` (`ContactPage` + `contact.ts` + `.scss`) : select de type, textarea, validation cliente via le schéma partagé, états succès / erreur (`ErrorMessageService`, jamais `err.message`). Entrée de nav « Nous contacter » dans `SETTINGS_ITEMS` + clé i18n + icône. `apiClient.submitContactMessage(input)` ajoute `pageUrl` / `appVersion`. - Tests : `apps/api/test/contact.test.ts` (Mocha — insertion, en-tête UA, champs nullables, message trop court / trop long, type inconnu), `contact.feature` + steps (Cypress e2e — envoi + confirmation + contexte), `contact-page.cy.ts` (rendu + garde `RequireAuth` + label d'erreur). - Docs : `batch-cooking-modele.md`, `backend-architecture.md`, `frontend-architecture.md`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
35 lines
1.6 KiB
TypeScript
35 lines
1.6 KiB
TypeScript
import { z } from "zod";
|
|
|
|
// Shared between apps/api (server-side validation, source of truth) and
|
|
// apps/web (client-side validation for instant feedback on the contact
|
|
// form). Same rationale as schemas/auth.ts — one set of rules, French
|
|
// messages surfaced as-is in the form.
|
|
|
|
/**
|
|
* The kind of a contact-form message. A plain `String` in Postgres backed by
|
|
* this const (see `ContactMessage.type` in schema.prisma) rather than a
|
|
* Postgres enum — adding a value is one line here, no migration. `type`
|
|
* structures the admin-side triage; the user picks it from a small select.
|
|
*/
|
|
export const CONTACT_MESSAGE_TYPES = ["bug", "suggestion", "other"] as const;
|
|
export type ContactMessageType = (typeof CONTACT_MESSAGE_TYPES)[number];
|
|
|
|
/**
|
|
* Payload accepted by `POST /contact` (issue #80). `message` is the only
|
|
* thing the user actually types; `pageUrl` / `appVersion` are captured
|
|
* automatically by the client (`window.location.pathname`, `__APP_VERSION__`)
|
|
* and are optional so a direct API call or an older client can omit them.
|
|
* `userAgent` is NOT here — the server reads it from the request header,
|
|
* never trusting the client for it.
|
|
*/
|
|
export const submitContactMessageSchema = z.object({
|
|
type: z.enum(CONTACT_MESSAGE_TYPES),
|
|
message: z
|
|
.string()
|
|
.trim()
|
|
.min(10, "Le message doit faire au moins 10 caractères")
|
|
.max(5000, "Le message ne peut pas dépasser 5000 caractères"),
|
|
pageUrl: z.string().max(500).optional(),
|
|
appVersion: z.string().max(50).optional(),
|
|
});
|
|
export type SubmitContactMessageInput = z.infer<typeof submitContactMessageSchema>;
|