feat(checkout): let the admin choose the details asked at checkout
ci-api / test (push) Successful in 20m38s
ci-web / test (push) Successful in 11m20s

The admin enables or disables each option (phone, address, Snapchat,
Instagram, Telegram, SimpleX, WhatsApp, Signal, notes, preferred time)
from a new "Checkout fields" page; the customer's name is always asked.

Backend
- checkoutfields module: single-row settings (CHECK id = 1), public GET
  and admin GET/PUT.
- orders: answers stored as JSONB (contacts, info_sup); the customer
  phone moves from customer_phone to contacts.phone (migration 000034
  copies existing values before dropping the column).
- Orders are validated against the live settings: disabled options and
  unknown keys are dropped, enabled phone/address are required, and
  format, length and control characters are checked.
- The Telegram notification includes the answers.

Frontend
- Checkout form generated from the enabled options; admin settings page;
  answers shown in the order list and detail.
- API calls live in src/api (checkoutFields.ts, orders.ts); ApiError
  keeps the response body so the rejected field can be reported.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Xor290
2026-10-04 16:16:22 +02:00
co-authored by Claude Sonnet 5.5
parent 178652ef14
commit f9bfdc9d3c
37 changed files with 1579 additions and 119 deletions
@@ -0,0 +1,2 @@
ALTER TABLE orders
ADD COLUMN customer_email TEXT NOT NULL DEFAULT '';
@@ -0,0 +1,2 @@
ALTER TABLE orders
DROP COLUMN customer_email;
@@ -0,0 +1 @@
DROP TABLE IF EXISTS checkout_fields;
@@ -0,0 +1,18 @@
-- Réglages du formulaire de commande (quels champs le client doit renseigner).
-- Une seule ligne : CHECK (id = 1) interdit toute autre ligne, sinon un bug
-- pourrait en créer une 2e et le service lirait l'une ou l'autre au hasard.
CREATE TABLE checkout_fields (
id SMALLINT PRIMARY KEY DEFAULT 1 CHECK (id = 1),
checkout_phone BOOLEAN NOT NULL DEFAULT true,
checkout_address BOOLEAN NOT NULL DEFAULT true,
checkout_snap BOOLEAN NOT NULL DEFAULT false,
checkout_insta BOOLEAN NOT NULL DEFAULT false,
checkout_telegram BOOLEAN NOT NULL DEFAULT false,
checkout_simple_x BOOLEAN NOT NULL DEFAULT false,
checkout_whatsapp BOOLEAN NOT NULL DEFAULT false,
checkout_signal BOOLEAN NOT NULL DEFAULT false,
checkout_notes BOOLEAN NOT NULL DEFAULT false,
checkout_hour BOOLEAN NOT NULL DEFAULT false
);
INSERT INTO checkout_fields (id) VALUES (1);
@@ -0,0 +1,3 @@
ALTER TABLE orders
DROP COLUMN IF EXISTS info_sup,
DROP COLUMN IF EXISTS contacts;
@@ -0,0 +1,5 @@
-- Réponses du client aux options de contact activées par l'admin (adresse,
-- messageries, heure) : une colonne JSON plutôt qu'une colonne par option.
ALTER TABLE orders
ADD COLUMN contacts JSONB NOT NULL DEFAULT '{}'::jsonb,
ADD COLUMN info_sup JSONB NOT NULL DEFAULT '{}'::jsonb;
@@ -0,0 +1,5 @@
ALTER TABLE orders
ADD COLUMN customer_phone TEXT NOT NULL DEFAULT '';
UPDATE orders
SET customer_phone = COALESCE(contacts->>'phone', '');
@@ -0,0 +1,8 @@
-- Le téléphone vit désormais dans contacts->>'phone' avec les messageries
-- (voir 000033) : les anciennes commandes sont recopiées avant de supprimer
-- la colonne.
UPDATE orders
SET contacts = contacts || jsonb_build_object('phone', customer_phone)
WHERE customer_phone <> '';
ALTER TABLE orders DROP COLUMN customer_phone;