Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c1708cd8f5 | |||
| 74f0f981d8 |
@@ -1,362 +1,209 @@
|
|||||||
# Starseed
|
# Starseed
|
||||||
|
|
||||||
CRM/ERP en architecture **modular monolith DDD** — Symfony 8 (API Platform 4) + Nuxt 4.
|
CRM/ERP — Symfony 8 (API Platform 4) + Nuxt 4
|
||||||
|
|
||||||
Le backend est la **source de vérité unique** : il décide des modules actifs et de
|
|
||||||
l'organisation de la sidebar. Le frontend scanne `frontend/modules/*/` comme layers
|
|
||||||
Nuxt et consomme l'API pour la navigation.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Sommaire
|
|
||||||
|
|
||||||
- [Stack](#stack)
|
|
||||||
- [Prérequis](#prérequis)
|
|
||||||
- [Démarrage rapide](#démarrage-rapide)
|
|
||||||
- [Dev local : avec ou sans données de seed](#dev-local--avec-ou-sans-données-de-seed)
|
|
||||||
- [Comptes (dev)](#comptes-dev)
|
|
||||||
- [Bases de données : dev et test](#bases-de-données--dev-et-test)
|
|
||||||
- [Tests](#tests)
|
|
||||||
- [Déploiement : seed RBAC en recette / prod](#déploiement--seed-rbac-en-recette--prod)
|
|
||||||
- [Commandes make](#commandes-make)
|
|
||||||
- [Architecture](#architecture)
|
|
||||||
- [Structure du dépôt](#structure-du-dépôt)
|
|
||||||
- [CI/CD](#cicd)
|
|
||||||
- [Conventions](#conventions)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Stack
|
## Stack
|
||||||
|
|
||||||
- **Backend** : PHP 8.4, Symfony 8, API Platform 4, Doctrine ORM, PostgreSQL 16
|
- **Backend** : PHP 8.4, Symfony 8, API Platform 4, Doctrine ORM, PostgreSQL 16
|
||||||
- **Frontend** : Nuxt 4 (SPA, SSR off), Vue 3, Pinia, Tailwind CSS, @malio/layer-ui, @nuxtjs/i18n
|
- **Frontend** : Nuxt 4 (SPA), Vue 3, Pinia, Tailwind CSS, @malio/layer-ui
|
||||||
- **Auth** : JWT HTTP-only cookie (Lexik), login sur `/login_check`
|
- **Auth** : JWT HTTP-only cookie (Lexik)
|
||||||
- **Infra** : Docker Compose (dev + prod multi-stage)
|
- **Infra** : Docker Compose (dev + prod multi-stage)
|
||||||
- **CI/CD** : Gitea Actions (auto-tag + build Docker)
|
- **CI/CD** : Gitea Actions (auto-tag + build Docker)
|
||||||
|
|
||||||
| Service | Port |
|
## Quick Start
|
||||||
|---------------|------|
|
|
||||||
| API (Nginx) | 8083 |
|
|
||||||
| Frontend dev | 3004 |
|
|
||||||
| PostgreSQL | 5437 |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Prérequis
|
|
||||||
|
|
||||||
- Docker + Docker Compose
|
|
||||||
- `make`
|
|
||||||
- `nvm` (la version de Node est fixée par `.nvmrc`, voir `make node-use`)
|
|
||||||
|
|
||||||
Toutes les commandes `make` s'exécutent dans le container PHP (`php-starseed-fpm`) ;
|
|
||||||
rien n'est requis sur l'hôte hormis Docker — **sauf les tests E2E**, qui tournent sur
|
|
||||||
l'hôte (navigateur réel, voir [Tests](#tests)).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Démarrage rapide
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make start # Démarre les containers Docker
|
make start # Demarrer les containers Docker
|
||||||
make install # Composer + clés JWT + migrations + permissions + BDD de test
|
make install # Composer, migrations, fixtures, build Nuxt
|
||||||
make dev-nuxt # Serveur Nuxt avec hot reload (http://localhost:3004)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`make install` prépare une base de dev **vierge** (schéma + RBAC structurel, sans
|
Dev frontend (hot reload) :
|
||||||
données de démo) et la base de **test**. Pour obtenir des comptes et des données de
|
|
||||||
démo prêtes à l'emploi, lis la section suivante.
|
|
||||||
|
|
||||||
> Override local possible : `make` lit `infra/dev/.env.docker`, surchargé par
|
|
||||||
> `infra/dev/.env.docker.local` s'il existe (créé automatiquement par `make env-init`).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Dev local : avec ou sans données de seed
|
|
||||||
|
|
||||||
Le projet distingue deux états de base de données de dev. Les **fixtures Doctrine sont
|
|
||||||
en `require-dev`** : elles n'existent qu'en dev, jamais dans le build de prod.
|
|
||||||
|
|
||||||
### Sans données de seed (base vierge)
|
|
||||||
|
|
||||||
C'est ce que produit `make install`. La base contient :
|
|
||||||
|
|
||||||
- le **schéma** complet (toutes les migrations jouées) ;
|
|
||||||
- les **rôles système** `admin` / `user` (seedés en SQL par la migration RBAC) ;
|
|
||||||
- le **catalogue de permissions** synchronisé (`app:sync-permissions`).
|
|
||||||
|
|
||||||
Mais **aucun compte utilisateur ni donnée métier**. Pour pouvoir te connecter,
|
|
||||||
crée toi-même un compte :
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make shell
|
make dev-nuxt # Port 3003
|
||||||
php bin/console app:create-user admin monMotDePasse --admin # compte ROLE_ADMIN
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Optionnel — provisionner les **rôles métier** (bureau / compta / commerciale / usine
|
## Ports
|
||||||
+ matrice RBAC § 2.7) sans comptes de démo :
|
|
||||||
|
|
||||||
```bash
|
| Service | Port |
|
||||||
php bin/console app:seed-rbac
|
|------------|------|
|
||||||
```
|
| API (Nginx)| 8083 |
|
||||||
|
| Frontend | 3004 |
|
||||||
|
| PostgreSQL | 5437 |
|
||||||
|
|
||||||
Cet état est utile pour repartir d'une base propre, reproduire un bug sur données
|
## Commandes
|
||||||
minimales, ou tester un parcours d'onboarding réel.
|
|
||||||
|
|
||||||
### Avec données de seed (base de démo)
|
| Commande | Description |
|
||||||
|
|----------|-------------|
|
||||||
`make db-reset` (ou `make fixtures` après un `make install`) recharge la base de dev
|
| `make start` | Demarrer les containers |
|
||||||
avec un jeu complet de données de démonstration, **idempotent** :
|
| `make stop` | Arreter les containers |
|
||||||
|
| `make restart` | Redemarrer les containers |
|
||||||
```bash
|
| `make install` | Install complet |
|
||||||
make db-reset # ATTENTION : drop + recrée la base de dev, puis charge tout le seed
|
| `make reset` | Tout supprimer et reinstaller |
|
||||||
```
|
| `make dev-nuxt` | Serveur dev Nuxt (hot reload) |
|
||||||
|
| `make shell` | Shell dans le container PHP |
|
||||||
Ce que les fixtures posent :
|
| `make cache-clear` | Vider le cache Symfony |
|
||||||
|
| `make migration-migrate` | Lancer les migrations |
|
||||||
- **3 utilisateurs système** : `admin` (ROLE_ADMIN), `alice`, `bob` (ROLE_USER),
|
| `make fixtures` | Charger les fixtures |
|
||||||
rattachés à des sites distincts ;
|
| `make db-reset` | Reset BDD + migrations + fixtures |
|
||||||
- **3 sites** : Chatellerault, Saint-Jean, Pommevic ;
|
| `make test` | PHPUnit (tests back) |
|
||||||
- **les comptes de démo RBAC métier** (`bureau`, `compta`, `commerciale`, `usine`,
|
| `make nuxt-test` | Vitest (tests unitaires front) |
|
||||||
mot de passe `demo`) avec la matrice § 2.7 attachée ;
|
| `make test-e2e` | Playwright (tests E2E front) |
|
||||||
- les **référentiels et données métier** des modules (catégories, clients de démo,
|
| `make test-e2e-ui` | Playwright UI interactive (debug) |
|
||||||
référentiels comptables…).
|
| `make seed-e2e` | Seed les 6 personas E2E |
|
||||||
|
| `make install-e2e-deps` | One-time : Chromium + libs systeme (sudo) |
|
||||||
Toutes les fixtures sont rejouables sans effet de bord (lookup par clé naturelle,
|
| `make php-cs-fixer-allow-risky` | Fix code style PHP |
|
||||||
aucun doublon).
|
| `make logs-dev` | Tail logs Symfony |
|
||||||
|
|
||||||
> Différence avec `make install` : `install` ne charge **pas** les fixtures sur la base
|
|
||||||
> de dev (il alimente uniquement la base de test). Utilise `make db-reset` ou
|
|
||||||
> `make fixtures` quand tu veux des données de démo en dev.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Comptes (dev)
|
|
||||||
|
|
||||||
Disponibles uniquement après `make db-reset` / `make fixtures` (état « avec seed ») :
|
|
||||||
|
|
||||||
| Username | Password | Rôle | RBAC métier |
|
|
||||||
|---------------|----------|------------|---------------------------------------------------------------|
|
|
||||||
| `admin` | `admin` | ROLE_ADMIN | bypass complet (`is_admin`) |
|
|
||||||
| `alice` | `alice` | ROLE_USER | — |
|
|
||||||
| `bob` | `bob` | ROLE_USER | — |
|
|
||||||
| `bureau` | `demo` | ROLE_USER | clients : view + manage |
|
|
||||||
| `compta` | `demo` | ROLE_USER | clients : view + accounting.view / manage |
|
|
||||||
| `commerciale` | `demo` | ROLE_USER | clients : view + manage (Information obligatoire — RG-1.04) |
|
|
||||||
| `usine` | `demo` | ROLE_USER | aucun accès clients |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Bases de données : dev et test
|
|
||||||
|
|
||||||
Deux bases distinctes vivent dans le **même container PostgreSQL** (port 5437) :
|
|
||||||
|
|
||||||
| Base | Environnement | Construite par | Usage |
|
|
||||||
|------------|---------------|--------------------------------------|--------------------------------|
|
|
||||||
| `<db>` | `dev` | `make install` / `make db-reset` | développement manuel, dev-nuxt |
|
|
||||||
| `<db>_test` | `test` | `make test-db-setup` | PHPUnit (jamais touchée à la main) |
|
|
||||||
|
|
||||||
Le suffixe `_test` est appliqué **automatiquement** par Doctrine quand `APP_ENV=test`
|
|
||||||
(config `when@test` dans `config/packages/doctrine.yaml`). La base de test est donc
|
|
||||||
totalement **isolée** de la base de dev : lancer `make test` ne touche jamais tes
|
|
||||||
données de dev.
|
|
||||||
|
|
||||||
`make test-db-setup` fait davantage que jouer les migrations, car certaines structures
|
|
||||||
ne sont pas portées par des migrations « métier » :
|
|
||||||
|
|
||||||
1. `doctrine:migrations:migrate` — schéma métier réel ;
|
|
||||||
2. `doctrine:schema:update --force` — crée les tables mappées en `when@test`
|
|
||||||
uniquement (entités de test) ;
|
|
||||||
3. `app:apply-column-comments` — réapplique les `COMMENT ON COLUMN` que
|
|
||||||
`schema:update` efface sur les tables managées par l'ORM (garde-fou
|
|
||||||
`ColumnsHaveSqlCommentTest`) ;
|
|
||||||
4. `fixtures:load` → `sync-permissions` → `seed-rbac` — dans cet ordre précis
|
|
||||||
(le purger des fixtures vide la table `permission`, donc la sync passe après) ;
|
|
||||||
5. recréation des **index partiels uniques** (`LOWER(...) WHERE ...`) non exprimables
|
|
||||||
en attributs ORM, indispensables aux tests d'unicité (RG-1.07, RG-1.16, RG-1.03/1.29).
|
|
||||||
|
|
||||||
`make install` et `make db-reset` appellent déjà `test-db-setup` : tu n'as à le
|
|
||||||
relancer à la main que si la base de test diverge (nouvelle migration, nouvelle
|
|
||||||
permission) sans vouloir reseed la base de dev.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
|
||||||
| Suite | Commande | Outil | Où |
|
- **Back** : `make test` (PHPUnit). Fixtures dediees sous `tests/Fixtures/`.
|
||||||
|-------------------|------------------|----------------------|-----------------------------------|
|
- **Front unitaire** : `make nuxt-test` (Vitest, happy-dom). Composables, utils, stores — rapide, <30s.
|
||||||
| Back | `make test` | PHPUnit | container PHP, base `<db>_test` |
|
- **Front E2E** : `make test-e2e` (Playwright). Couvre login + matrice RBAC sidebar. Suite volontairement minimaliste (11 tests) — voir la regle d'or dans `CLAUDE.md`.
|
||||||
| Front unitaire | `make nuxt-test` | Vitest (happy-dom) | container Node, < 30 s |
|
|
||||||
| Front E2E | `make test-e2e` | Playwright | **hôte** (navigateur réel requis) |
|
|
||||||
| Tout (back+front) | `make test-all` | PHPUnit + Vitest | — |
|
|
||||||
|
|
||||||
### Tests back (PHPUnit)
|
|
||||||
|
|
||||||
|
**Bootstrap E2E (une fois par poste)** :
|
||||||
```bash
|
```bash
|
||||||
make test # toute la suite
|
make install-e2e-deps # Telecharge Chromium + libs systeme via apt (sudo)
|
||||||
make test FILES=tests/Module/Commercial # un dossier / fichier ciblé
|
|
||||||
```
|
```
|
||||||
|
|
||||||
PHPUnit force `APP_ENV=test` (`phpunit.dist.xml`) : les tests tournent **toujours**
|
**Workflow E2E** :
|
||||||
sur la base `<db>_test`, jamais sur la base de dev. Prérequis : que la base de test
|
|
||||||
existe — c'est le cas après `make install`. Si elle a divergé, rejoue
|
|
||||||
`make test-db-setup` (cf. [Bases de données](#bases-de-données--dev-et-test)).
|
|
||||||
|
|
||||||
### Tests front unitaires (Vitest)
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make nuxt-test # composables, utils, stores — rapide et stable
|
# Terminal 1 : containers + dev server
|
||||||
```
|
|
||||||
|
|
||||||
C'est la **place par défaut** pour étendre la couverture (cf. règle d'or ci-dessous).
|
|
||||||
|
|
||||||
### Tests E2E (Playwright)
|
|
||||||
|
|
||||||
Suite volontairement minimaliste (login + matrice RBAC sidebar). **Règle d'or : un
|
|
||||||
nouveau test E2E ne s'ajoute que si un bug critique est passé en prod** — sinon,
|
|
||||||
préférer un test Vitest ou étendre un persona existant.
|
|
||||||
|
|
||||||
Bootstrap (une fois par poste) :
|
|
||||||
|
|
||||||
```bash
|
|
||||||
make install-e2e-deps # télécharge Chromium + libs système (apt/dnf, sudo)
|
|
||||||
```
|
|
||||||
|
|
||||||
Workflow :
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Terminal 1 — containers, seed des personas, serveur dev
|
|
||||||
make start && make seed-e2e && make dev-nuxt
|
make start && make seed-e2e && make dev-nuxt
|
||||||
|
|
||||||
# Terminal 2 — tests
|
# Terminal 2 : tests
|
||||||
make test-e2e # headless
|
make test-e2e
|
||||||
make test-e2e-ui # UI interactive (debug)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
> Toute permission testable touche **3 miroirs** à garder alignés : `config/sidebar.php`,
|
|
||||||
> `frontend/tests/e2e/_fixtures/personas.ts`, `SeedE2ECommand.php`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Déploiement : seed RBAC en recette / prod
|
|
||||||
|
|
||||||
Les fixtures Doctrine étant en `require-dev`, elles sont **absentes du build de prod**.
|
|
||||||
Le RBAC métier (rôles `bureau` / `compta` / `commerciale` / `usine` + matrice § 2.7)
|
|
||||||
est seedé par une **commande applicative idempotente**, jouée dans l'étape de release,
|
|
||||||
**après** les migrations et la synchronisation des permissions :
|
|
||||||
|
|
||||||
```bash
|
|
||||||
php bin/console doctrine:migrations:migrate --no-interaction
|
|
||||||
php bin/console app:sync-permissions # pose les permissions (commercial.clients.*, …)
|
|
||||||
php bin/console app:seed-rbac # PROD : rôles + matrice § 2.7 (sans comptes démo)
|
|
||||||
```
|
|
||||||
|
|
||||||
En **recette / staging**, ajouter le flag pour disposer de logins de test. Le mot de
|
|
||||||
passe est fourni **explicitement** (jamais en dur, jamais committé) :
|
|
||||||
|
|
||||||
```bash
|
|
||||||
php bin/console app:seed-rbac --with-demo-users --password='<mot-de-passe>'
|
|
||||||
# ou via la variable d'environnement RBAC_DEMO_PASSWORD
|
|
||||||
```
|
|
||||||
|
|
||||||
La commande est rejouable sans effet de bord (aucun doublon de rôle, de lien ou de
|
|
||||||
compte). Pour créer un premier administrateur en prod :
|
|
||||||
|
|
||||||
```bash
|
|
||||||
php bin/console app:create-user <username> <password> --admin
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Commandes make
|
|
||||||
|
|
||||||
`make` (sans argument) ou `make help` affiche l'aide colorée. Les principales :
|
|
||||||
|
|
||||||
| Commande | Description |
|
|
||||||
|--------------------------------|----------------------------------------------------------|
|
|
||||||
| `make start` / `stop` / `restart` | Cycle de vie des containers |
|
|
||||||
| `make install` | Install complet (base dev vierge + base de test) |
|
|
||||||
| `make reset` | Tout supprimer et réinstaller (**drop la BDD**) |
|
|
||||||
| `make dev-nuxt` | Serveur Nuxt hot reload (port 3004) |
|
|
||||||
| `make shell` / `shell-root` | Shell bash dans le container PHP |
|
|
||||||
| `make migration-migrate` | Jouer les migrations Doctrine |
|
|
||||||
| `make fixtures` | Charger les fixtures (données de démo dev) |
|
|
||||||
| `make sync-permissions` | Synchroniser le catalogue RBAC |
|
|
||||||
| `make seed-rbac` | Seed RBAC métier (rôles + matrice § 2.7) |
|
|
||||||
| `make db-reset` | Reset base dev : drop + migrate + fixtures + RBAC |
|
|
||||||
| `make test-db-setup` | (Re)construire la base de test |
|
|
||||||
| `make test` | PHPUnit (back) |
|
|
||||||
| `make nuxt-test` | Vitest (front unitaire) |
|
|
||||||
| `make test-all` | PHPUnit + Vitest |
|
|
||||||
| `make test-e2e` / `test-e2e-ui`| Playwright (E2E, sur l'hôte) |
|
|
||||||
| `make seed-e2e` | Seed des 6 personas E2E |
|
|
||||||
| `make php-cs-fixer-allow-risky`| Fix du code style PHP |
|
|
||||||
| `make php-cs-fixer-check` | Dry-run du fixer (CI / avant push) |
|
|
||||||
| `make logs-dev` | Tail des logs Symfony |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
**Modular Monolith DDD** : chaque module est un bounded context autonome,
|
**Modular Monolith DDD** : chaque module est un bounded context autonome, activable/desactivable par tenant. Le backend est la seule source de verite pour l'activation et l'organisation de la sidebar.
|
||||||
activable / désactivable par tenant. Le backend est la seule source de vérité pour
|
|
||||||
l'activation des modules et l'organisation de la sidebar.
|
|
||||||
|
|
||||||
- `config/modules.php` — liste des modules actifs
|
- `config/modules.php` — liste des modules actifs
|
||||||
- `config/sidebar.php` — structure de la sidebar (sections + items avec module owner)
|
- `config/sidebar.php` — structure de la sidebar (sections + items avec module owner)
|
||||||
- `GET /api/modules` — IDs des modules actifs (public)
|
- `GET /api/sidebar` — retourne les sections filtrees par les modules actifs + les routes desactivees
|
||||||
- `GET /api/sidebar` — sections filtrées par modules actifs + routes désactivées (public)
|
- Frontend : chaque `frontend/modules/*/` est auto-detecte comme layer Nuxt, la sidebar est fetchee de l'API
|
||||||
|
|
||||||
**Désactiver un module** : commenter sa ligne dans `config/modules.php`, vider le cache.
|
Pour desactiver un module : commenter sa ligne dans `config/modules.php`, clear cache. Ses items de sidebar disparaissent et ses routes sont bloquees par le middleware front.
|
||||||
Ses items de sidebar disparaissent et ses routes sont bloquées par le middleware front.
|
|
||||||
Le code reste dans le bundle (layer auto-détecté) → réactivation instantanée.
|
|
||||||
|
|
||||||
**Réorganiser la sidebar** : éditer `config/sidebar.php` uniquement — le code des
|
Pour reorganiser la sidebar (ex: deplacer un item d'une section a l'autre) : editer `config/sidebar.php` uniquement, le code des modules n'est pas touche.
|
||||||
modules n'est pas touché.
|
|
||||||
|
|
||||||
**Communication inter-modules** : jamais d'import direct d'un module à l'autre. Passer
|
## Structure
|
||||||
par `Shared/Domain/Contract/` (interfaces) ou des domain events.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Structure du dépôt
|
|
||||||
|
|
||||||
```
|
```
|
||||||
src/ # Backend Symfony
|
src/ # Backend Symfony
|
||||||
Shared/ # Noyau technique partagé (Domain/, Application/Bus/, Infrastructure/ApiPlatform/)
|
Kernel.php
|
||||||
|
Shared/ # Noyau technique partage
|
||||||
|
Domain/
|
||||||
|
ValueObject/ # Email, ...
|
||||||
|
Event/ # DomainEventInterface
|
||||||
|
Contract/ # Interfaces inter-modules
|
||||||
|
Application/
|
||||||
|
Bus/ # CommandBusInterface, QueryBusInterface
|
||||||
|
Infrastructure/
|
||||||
|
ApiPlatform/
|
||||||
|
Resource/ # AppVersion, ModulesResource, SidebarResource
|
||||||
|
State/ # AppVersionProvider, ModulesProvider, SidebarProvider
|
||||||
Module/
|
Module/
|
||||||
Core/ # Module obligatoire (auth, users, RBAC)
|
Core/ # Module obligatoire (auth, users)
|
||||||
CoreModule.php # Déclaration (ID, LABEL, REQUIRED, permissions())
|
CoreModule.php # Declaration (ID, LABEL, REQUIRED)
|
||||||
Domain/ Application/ Infrastructure/
|
Domain/
|
||||||
Commercial/ Catalog/ Sites/ # Modules métier
|
Entity/ # User
|
||||||
|
Repository/ # UserRepositoryInterface
|
||||||
|
Event/ # UserCreated
|
||||||
|
Application/
|
||||||
|
DTO/ # UserOutput
|
||||||
|
Infrastructure/
|
||||||
|
Doctrine/ # DoctrineUserRepository, Migrations/
|
||||||
|
ApiPlatform/State/
|
||||||
|
Provider/ # MeProvider
|
||||||
|
Processor/ # UserPasswordHasherProcessor
|
||||||
|
Console/ # CreateUserCommand
|
||||||
|
DataFixtures/ # AppFixtures
|
||||||
|
Commercial/ # Autre module (exemple)
|
||||||
|
CommercialModule.php
|
||||||
config/
|
config/
|
||||||
modules.php # Source de vérité : activation
|
modules.php # Source de verite activation
|
||||||
sidebar.php # Source de vérité : navigation
|
sidebar.php # Source de verite navigation
|
||||||
packages/ # Config Symfony (doctrine, api_platform, security…)
|
version.yaml
|
||||||
migrations/ # Migrations d'initialisation (namespace racine : setup, RBAC, seed de base)
|
packages/ # Config Symfony
|
||||||
|
jwt/ # Cles JWT
|
||||||
|
migrations/ # Anciennes migrations
|
||||||
frontend/ # App Nuxt 4 (SPA)
|
frontend/ # App Nuxt 4 (SPA)
|
||||||
app/ # Shell : layouts, middlewares (auth.global, modules.global)
|
app/
|
||||||
shared/ # Code inter-modules (composables, stores, utils, types)
|
layouts/ # default.vue, auth.vue
|
||||||
modules/ # Layers Nuxt auto-détectés (core/, commercial/…)
|
middleware/ # auth.global.ts, modules.global.ts
|
||||||
i18n/locales/ # Traductions (sidebar.*, audit.entity.*, …)
|
shared/ # Code partage (hors modules)
|
||||||
|
composables/ # useApi, useAppVersion, useSidebar
|
||||||
|
components/ui/ # AppTopNav, ...
|
||||||
|
stores/ # auth, ui
|
||||||
|
services/ # auth
|
||||||
|
types/ # SidebarSection, UserData
|
||||||
|
utils/ # api (Hydra)
|
||||||
|
modules/ # Modules auto-detectes comme layers Nuxt
|
||||||
|
core/
|
||||||
|
nuxt.config.ts # Marqueur layer
|
||||||
|
pages/ # index, login, logout
|
||||||
|
commercial/
|
||||||
|
nuxt.config.ts
|
||||||
|
pages/ # commercial.vue
|
||||||
|
app.vue
|
||||||
|
nuxt.config.ts # Scanne modules/*/ automatiquement
|
||||||
|
i18n/locales/ # Traductions (sidebar.*, etc.)
|
||||||
|
assets/ # CSS, images
|
||||||
|
public/ # Fichiers statiques
|
||||||
infra/
|
infra/
|
||||||
dev/ # Docker dev (Dockerfile, nginx, php.ini, xdebug, .env.docker)
|
dev/ # Docker dev (Dockerfile, nginx, php.ini, xdebug)
|
||||||
prod/ # Docker prod (multi-stage, nginx, php-prod.ini)
|
prod/ # Docker prod (multi-stage, nginx, php-prod.ini)
|
||||||
.gitea/workflows/ # CI Gitea (auto-tag, build Docker)
|
.gitea/workflows/ # CI Gitea (auto-tag, build Docker)
|
||||||
|
.claude/
|
||||||
|
skills/create-module/ # Skill Claude Code pour scaffolder un module
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## CI/CD
|
## CI/CD
|
||||||
|
|
||||||
- **Auto Tag** : push sur `develop` → bump `config/version.yaml` → tag `vX.Y.Z`
|
- **Auto Tag** : push sur `develop` → bump `config/version.yaml` → tag `vX.Y.Z`
|
||||||
- **Build Docker** : push tag `v*` → build image multi-stage → push Gitea Registry
|
- **Build Docker** : push tag `v*` → build image multi-stage → push Gitea Registry
|
||||||
|
|
||||||
Secrets requis dans Gitea :
|
Secrets requis dans Gitea :
|
||||||
|
|
||||||
- `RELEASE_TOKEN` — PAT avec droits `write:repository`
|
- `RELEASE_TOKEN` — PAT avec droits `write:repository`
|
||||||
- `REGISTRY_TOKEN` — token pour le registry Docker
|
- `REGISTRY_TOKEN` — token pour le registry Docker
|
||||||
|
|
||||||
---
|
## Déploiement — seed RBAC (recette / prod)
|
||||||
|
|
||||||
|
Le RBAC métier (rôles `bureau` / `compta` / `commerciale` / `usine` + matrice § 2.7)
|
||||||
|
est seedé par une **commande applicative idempotente** (présente dans le build prod,
|
||||||
|
contrairement aux fixtures Doctrine en `require-dev`). À jouer dans l'étape de release,
|
||||||
|
**après** les migrations et la synchronisation des permissions :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php bin/console doctrine:migrations:migrate --no-interaction
|
||||||
|
php bin/console app:sync-permissions # pose les permissions commercial.clients.*
|
||||||
|
php bin/console app:seed-rbac # PROD : rôles + matrice § 2.7 (sans comptes démo)
|
||||||
|
```
|
||||||
|
|
||||||
|
En **recette / staging**, ajouter le flag pour disposer de logins de test (mot de passe
|
||||||
|
fourni explicitement, jamais en dur) :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php bin/console app:seed-rbac --with-demo-users --password='<mot-de-passe>'
|
||||||
|
# ou via la variable d'env RBAC_DEMO_PASSWORD
|
||||||
|
```
|
||||||
|
|
||||||
|
La commande est rejouable sans effet de bord (aucun doublon de rôle, de lien ou de compte).
|
||||||
|
En dev, `make db-reset` produit le même résultat (rôles + matrice + comptes démo).
|
||||||
|
|
||||||
|
## Credentials (dev)
|
||||||
|
|
||||||
|
| Username | Password | Role | RBAC métier |
|
||||||
|
|----------|----------|------|-------------|
|
||||||
|
| admin | admin | ROLE_ADMIN | bypass (is_admin) |
|
||||||
|
| alice | alice | ROLE_USER | — |
|
||||||
|
| bob | bob | ROLE_USER | — |
|
||||||
|
| bureau | demo | ROLE_USER | clients : view + manage |
|
||||||
|
| compta | demo | ROLE_USER | clients : view + accounting.view/manage |
|
||||||
|
| commerciale | demo | ROLE_USER | clients : view + manage (Information obligatoire — RG-1.04) |
|
||||||
|
| usine | demo | ROLE_USER | aucun accès clients |
|
||||||
|
|
||||||
## Conventions
|
## Conventions
|
||||||
|
|
||||||
@@ -366,13 +213,4 @@ Secrets requis dans Gitea :
|
|||||||
<type>(<scope optionnel>) : <message>
|
<type>(<scope optionnel>) : <message>
|
||||||
```
|
```
|
||||||
|
|
||||||
Espaces obligatoires autour du `:`. Types : `build`, `chore`, `ci`, `docs`, `feat`,
|
Types : `build`, `chore`, `ci`, `docs`, `feat`, `fix`, `perf`, `refactor`, `revert`, `style`, `test`
|
||||||
`fix`, `perf`, `refactor`, `revert`, `style`, `test`.
|
|
||||||
|
|
||||||
### Langue
|
|
||||||
|
|
||||||
- UI et communication : **français**
|
|
||||||
- Code (classes, méthodes, variables) : **anglais**
|
|
||||||
- Commentaires (PHP, TS, Vue) : **français**
|
|
||||||
|
|
||||||
> Règles détaillées : `CLAUDE.md` et `.claude/rules/`.
|
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.1.78'
|
app.version: '0.1.74'
|
||||||
|
|||||||
@@ -258,8 +258,7 @@ Le composant `Code postal` + `Ville` + `Adresse` est branché sur **api-adresse.
|
|||||||
|
|
||||||
- Composable dédié `useAddressAutocomplete()` (à créer en M1).
|
- Composable dédié `useAddressAutocomplete()` (à créer en M1).
|
||||||
- Appel HTTP **direct depuis le front** (CORS OK), pas de proxy back.
|
- Appel HTTP **direct depuis le front** (CORS OK), pas de proxy back.
|
||||||
- Pattern : à la saisie du code postal (5 chiffres), GET `https://api-adresse.data.gouv.fr/search/?q={cp}&type=municipality` → alimente le select Ville. Sur saisie d'adresse : `?q={addr}&postcode={cp}` (sans filtre `type`) → suggestions adresse.
|
- Pattern : à la saisie du code postal (5 chiffres), GET `https://api-adresse.data.gouv.fr/search/?q={cp}&type=municipality` → alimente le select Ville. Sur saisie d'adresse : `?q={addr}&postcode={cp}&type=housenumber` → suggestions adresse.
|
||||||
- ⚠ **Ne pas forcer `type=housenumber`** sur la recherche d'adresse (corrigé en ERP-66) : la BAN ne renvoie un résultat de ce type qu'une fois un numéro saisi, donc une recherche par nom de rue (« boulevard du port ») renverrait **0 résultat** pendant toute la frappe. Sans filtre `type`, la BAN classe rues + numéros par pertinence — comportement d'autocomplétion attendu.
|
|
||||||
- Cas dégradé : si l'API ne répond pas (offline, timeout), le champ Ville devient un `<MalioInputText>` libre éditable + toast d'avertissement. Validation serveur acceptera la saisie libre.
|
- Cas dégradé : si l'API ne répond pas (offline, timeout), le champ Ville devient un `<MalioInputText>` libre éditable + toast d'avertissement. Validation serveur acceptera la saisie libre.
|
||||||
|
|
||||||
## Points laissés ouverts par la V0 (résolus côté back)
|
## Points laissés ouverts par la V0 (résolus côté back)
|
||||||
|
|||||||
@@ -10,11 +10,7 @@
|
|||||||
"confirm": "Confirmer",
|
"confirm": "Confirmer",
|
||||||
"yes": "Oui",
|
"yes": "Oui",
|
||||||
"no": "Non",
|
"no": "Non",
|
||||||
"actions": "Actions",
|
"actions": "Actions"
|
||||||
"comingSoon": {
|
|
||||||
"title": "En cours de dev",
|
|
||||||
"subtitle": "Cette fonctionnalité arrive bientôt."
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
"administration": {
|
"administration": {
|
||||||
@@ -99,6 +95,8 @@
|
|||||||
"back": "Retour au répertoire",
|
"back": "Retour au répertoire",
|
||||||
"loading": "Chargement du client…",
|
"loading": "Chargement du client…",
|
||||||
"notFound": "Client introuvable.",
|
"notFound": "Client introuvable.",
|
||||||
|
"emptyContacts": "Aucun contact enregistré.",
|
||||||
|
"emptyAddresses": "Aucune adresse enregistrée.",
|
||||||
"confirmArchive": {
|
"confirmArchive": {
|
||||||
"title": "Archiver le client",
|
"title": "Archiver le client",
|
||||||
"message": "Ce client n'apparaîtra plus dans le répertoire actif. Confirmer l'archivage ?"
|
"message": "Ce client n'apparaîtra plus dans le répertoire actif. Confirmer l'archivage ?"
|
||||||
@@ -113,6 +111,8 @@
|
|||||||
"back": "Retour au répertoire",
|
"back": "Retour au répertoire",
|
||||||
"loading": "Chargement du client…",
|
"loading": "Chargement du client…",
|
||||||
"notFound": "Client introuvable.",
|
"notFound": "Client introuvable.",
|
||||||
|
"emptyContacts": "Aucun contact enregistré.",
|
||||||
|
"emptyAddresses": "Aucune adresse enregistrée.",
|
||||||
"save": "Valider"
|
"save": "Valider"
|
||||||
},
|
},
|
||||||
"validation": {
|
"validation": {
|
||||||
@@ -133,9 +133,14 @@
|
|||||||
"duplicateCompany": "Un client portant ce nom de société existe déjà.",
|
"duplicateCompany": "Un client portant ce nom de société existe déjà.",
|
||||||
"main": {
|
"main": {
|
||||||
"companyName": "Nom du client (Entreprise)",
|
"companyName": "Nom du client (Entreprise)",
|
||||||
|
"firstName": "Prénom du contact principal",
|
||||||
|
"lastName": "Nom du contact principal",
|
||||||
|
"email": "Email",
|
||||||
|
"phonePrimary": "Téléphone",
|
||||||
|
"phoneSecondary": "Téléphone (2)",
|
||||||
|
"addPhone": "Ajouter un numéro",
|
||||||
"categories": "Catégorie",
|
"categories": "Catégorie",
|
||||||
"relation": "Distributeur / Courtier",
|
"relation": "Distributeur / Courtier",
|
||||||
"relationNone": "Aucun",
|
|
||||||
"relationDistributor": "Dépend du distributeur",
|
"relationDistributor": "Dépend du distributeur",
|
||||||
"relationBroker": "Dépend du courtier",
|
"relationBroker": "Dépend du courtier",
|
||||||
"distributorName": "Nom du distributeur",
|
"distributorName": "Nom du distributeur",
|
||||||
|
|||||||
@@ -201,8 +201,7 @@ const model = computed(() => props.modelValue)
|
|||||||
const degraded = ref(false)
|
const degraded = ref(false)
|
||||||
// Villes proposees par la BAN (alimentees a la saisie du code postal).
|
// Villes proposees par la BAN (alimentees a la saisie du code postal).
|
||||||
const banCityOptions = ref<RefOption[]>([])
|
const banCityOptions = ref<RefOption[]>([])
|
||||||
// Adresses proposees par la BAN (alimentees a la saisie d'adresse).
|
const addressOptions = ref<RefOption[]>([])
|
||||||
const banAddressOptions = ref<RefOption[]>([])
|
|
||||||
|
|
||||||
// Options ville effectives : on garantit que la ville courante figure toujours
|
// Options ville effectives : on garantit que la ville courante figure toujours
|
||||||
// dans la liste, sinon MalioSelect (qui resout le libelle depuis ses options)
|
// dans la liste, sinon MalioSelect (qui resout le libelle depuis ses options)
|
||||||
@@ -215,20 +214,6 @@ const cityOptions = computed<RefOption[]>(() => {
|
|||||||
}
|
}
|
||||||
return banCityOptions.value
|
return banCityOptions.value
|
||||||
})
|
})
|
||||||
|
|
||||||
// Meme garantie que cityOptions pour le champ Adresse : la rue courante doit
|
|
||||||
// toujours figurer dans les options, sinon MalioInputAutocomplete (qui resout
|
|
||||||
// l'affichage depuis ses options) laisse le champ VIDE des que la liste de
|
|
||||||
// suggestions BAN est vide — typiquement juste apres validation (remontage) ou
|
|
||||||
// a l'edition d'une adresse existante (1.12), alors que la valeur est bien
|
|
||||||
// persistee. On reinjecte donc la rue liee si la BAN ne l'a pas (re)proposee.
|
|
||||||
const addressOptions = computed<RefOption[]>(() => {
|
|
||||||
const current = props.modelValue.street
|
|
||||||
if (current && !banAddressOptions.value.some(o => o.value === current)) {
|
|
||||||
return [{ value: current, label: current }, ...banAddressOptions.value]
|
|
||||||
}
|
|
||||||
return banAddressOptions.value
|
|
||||||
})
|
|
||||||
const addressLoading = ref(false)
|
const addressLoading = ref(false)
|
||||||
// Conserve les suggestions d'adresse pour retrouver ville/CP au moment du select.
|
// Conserve les suggestions d'adresse pour retrouver ville/CP au moment du select.
|
||||||
let lastAddressSuggestions: AddressSuggestion[] = []
|
let lastAddressSuggestions: AddressSuggestion[] = []
|
||||||
@@ -295,7 +280,7 @@ async function onAddressSearch(query: string): Promise<void> {
|
|||||||
const postalCode = (model.value.postalCode ?? '').replace(/\D/g, '') || undefined
|
const postalCode = (model.value.postalCode ?? '').replace(/\D/g, '') || undefined
|
||||||
const suggestions = await autocomplete.searchAddress(query, postalCode)
|
const suggestions = await autocomplete.searchAddress(query, postalCode)
|
||||||
lastAddressSuggestions = suggestions
|
lastAddressSuggestions = suggestions
|
||||||
banAddressOptions.value = suggestions.map(s => ({ value: s.street, label: s.label }))
|
addressOptions.value = suggestions.map(s => ({ value: s.street, label: s.label }))
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
enterDegraded()
|
enterDegraded()
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<template>
|
||||||
|
<!--
|
||||||
|
Placeholder des onglets non encore implementes (Transport, Statistiques,
|
||||||
|
Rapports, Echanges). Frame vide blanche : aucun champ, aucun bouton,
|
||||||
|
aucun message « En cours » (decision Tristan 28/05). L'orchestrateur passe
|
||||||
|
automatiquement a l'onglet suivant — ce composant n'est qu'une coquille
|
||||||
|
visuelle reutilisee par 1.11/1.12.
|
||||||
|
-->
|
||||||
|
<div class="min-h-[240px] rounded-md bg-white" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
// Composant purement presentationnel : aucune prop, aucun event.
|
||||||
|
</script>
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
import { describe, it, expect, vi } from 'vitest'
|
|
||||||
import { mount } from '@vue/test-utils'
|
|
||||||
import { defineComponent, h, ref, computed } from 'vue'
|
|
||||||
import { emptyAddress } from '~/modules/commercial/types/clientForm'
|
|
||||||
import ClientAddressBlock from '../ClientAddressBlock.vue'
|
|
||||||
|
|
||||||
// Le composable BAN est mocke : aucun appel reseau, aucune suggestion chargee.
|
|
||||||
// On reproduit ainsi l'etat « adresse persistee, mais liste de suggestions
|
|
||||||
// vide » (remontage apres validation / edition d'une adresse existante).
|
|
||||||
vi.mock('~/shared/composables/useAddressAutocomplete', () => ({
|
|
||||||
useAddressAutocomplete: () => ({
|
|
||||||
searchCity: vi.fn(),
|
|
||||||
searchAddress: vi.fn(),
|
|
||||||
}),
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Auto-imports Nuxt/Vue utilises sans import explicite par le composant.
|
|
||||||
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
|
||||||
vi.stubGlobal('ref', ref)
|
|
||||||
vi.stubGlobal('computed', computed)
|
|
||||||
|
|
||||||
// Stub de MalioInputAutocomplete : expose les `value` des options recues, pour
|
|
||||||
// verifier que la rue courante figure bien dans la liste (sinon le composant
|
|
||||||
// Malio ne peut pas resoudre/afficher la valeur liee -> champ vide).
|
|
||||||
const MalioInputAutocompleteStub = defineComponent({
|
|
||||||
name: 'MalioInputAutocomplete',
|
|
||||||
props: {
|
|
||||||
modelValue: { type: [String, Number, null], default: undefined },
|
|
||||||
options: { type: Array as () => { value: string | number, label: string }[], default: () => [] },
|
|
||||||
loading: { type: Boolean, default: false },
|
|
||||||
minSearchLength: { type: Number, default: 0 },
|
|
||||||
label: { type: String, default: '' },
|
|
||||||
readonly: { type: Boolean, default: false },
|
|
||||||
},
|
|
||||||
emits: ['update:modelValue', 'search', 'select'],
|
|
||||||
setup(props) {
|
|
||||||
return () => h('div', {
|
|
||||||
'data-testid': 'addr-autocomplete',
|
|
||||||
'data-options': JSON.stringify(props.options.map(o => o.value)),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
function mountBlock(street: string | null) {
|
|
||||||
return mount(ClientAddressBlock, {
|
|
||||||
props: {
|
|
||||||
modelValue: { ...emptyAddress(), street },
|
|
||||||
title: 'Adresse',
|
|
||||||
categoryOptions: [],
|
|
||||||
siteOptions: [],
|
|
||||||
contactOptions: [],
|
|
||||||
countryOptions: [],
|
|
||||||
},
|
|
||||||
global: {
|
|
||||||
stubs: {
|
|
||||||
MalioButtonIcon: true,
|
|
||||||
MalioCheckbox: true,
|
|
||||||
MalioSelect: true,
|
|
||||||
MalioSelectCheckbox: true,
|
|
||||||
MalioInputText: true,
|
|
||||||
MalioInputAutocomplete: MalioInputAutocompleteStub,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('ClientAddressBlock — affichage de l\'adresse persistee', () => {
|
|
||||||
it('inclut la rue courante dans les options de l\'autocomplete meme sans recherche BAN', () => {
|
|
||||||
const wrapper = mountBlock('8 Boulevard du Port')
|
|
||||||
|
|
||||||
const el = wrapper.find('[data-testid="addr-autocomplete"]')
|
|
||||||
const values = JSON.parse(el.attributes('data-options') ?? '[]')
|
|
||||||
|
|
||||||
expect(values).toContain('8 Boulevard du Port')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -28,7 +28,7 @@ describe('useClientReferentials.loadCommon (resilience ERP-102)', () => {
|
|||||||
return Promise.reject(new Error('403 Forbidden'))
|
return Promise.reject(new Error('403 Forbidden'))
|
||||||
}
|
}
|
||||||
if (url === '/sites') {
|
if (url === '/sites') {
|
||||||
return Promise.resolve({ member: [{ '@id': '/api/sites/1', name: 'Chatellerault', postalCode: '86100' }] })
|
return Promise.resolve({ member: [{ '@id': '/api/sites/1', name: 'Chatellerault' }] })
|
||||||
}
|
}
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
member: [{ '@id': '/api/x/1', code: 'X', label: 'Libelle X' }],
|
member: [{ '@id': '/api/x/1', code: 'X', label: 'Libelle X' }],
|
||||||
@@ -40,8 +40,7 @@ describe('useClientReferentials.loadCommon (resilience ERP-102)', () => {
|
|||||||
await refs.loadCommon()
|
await refs.loadCommon()
|
||||||
|
|
||||||
// Resilience : les referentiels OK sont peuples malgre l'echec de /categories.
|
// Resilience : les referentiels OK sont peuples malgre l'echec de /categories.
|
||||||
// Le libelle d'un site est son numero de departement (2 premiers chiffres du code postal).
|
expect(refs.sites.value).toEqual([{ value: '/api/sites/1', label: 'Chatellerault' }])
|
||||||
expect(refs.sites.value).toEqual([{ value: '/api/sites/1', label: '86' }])
|
|
||||||
expect(refs.tvaModes.value).toEqual([{ value: '/api/x/1', label: 'Libelle X' }])
|
expect(refs.tvaModes.value).toEqual([{ value: '/api/x/1', label: 'Libelle X' }])
|
||||||
expect(refs.banks.value).toEqual([{ value: '/api/x/1', label: 'Libelle X' }])
|
expect(refs.banks.value).toEqual([{ value: '/api/x/1', label: 'Libelle X' }])
|
||||||
|
|
||||||
@@ -57,7 +56,7 @@ describe('useClientReferentials.loadCommon (resilience ERP-102)', () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (url === '/sites') {
|
if (url === '/sites') {
|
||||||
return Promise.resolve({ member: [{ '@id': '/api/sites/1', name: 'Chatellerault', postalCode: '86100' }] })
|
return Promise.resolve({ member: [{ '@id': '/api/sites/1', name: 'Chatellerault' }] })
|
||||||
}
|
}
|
||||||
return Promise.resolve({ member: [] })
|
return Promise.resolve({ member: [] })
|
||||||
})
|
})
|
||||||
@@ -68,7 +67,6 @@ describe('useClientReferentials.loadCommon (resilience ERP-102)', () => {
|
|||||||
expect(refs.categories.value).toEqual([
|
expect(refs.categories.value).toEqual([
|
||||||
{ value: '/api/categories/1', label: 'Secteur', code: 'SECTEUR' },
|
{ value: '/api/categories/1', label: 'Secteur', code: 'SECTEUR' },
|
||||||
])
|
])
|
||||||
// Le libelle d'un site est son numero de departement (2 premiers chiffres du code postal).
|
expect(refs.sites.value).toEqual([{ value: '/api/sites/1', label: 'Chatellerault' }])
|
||||||
expect(refs.sites.value).toEqual([{ value: '/api/sites/1', label: '86' }])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ interface CategoryMember extends HydraMember {
|
|||||||
|
|
||||||
interface SiteMember extends HydraMember {
|
interface SiteMember extends HydraMember {
|
||||||
name: string
|
name: string
|
||||||
postalCode: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ReferentialMember extends HydraMember {
|
interface ReferentialMember extends HydraMember {
|
||||||
@@ -102,10 +101,7 @@ export function useClientReferentials() {
|
|||||||
fetchAll<CategoryMember>('/categories')
|
fetchAll<CategoryMember>('/categories')
|
||||||
.then((cats) => { categories.value = cats.map(c => ({ value: c['@id'], label: c.name, code: c.code })) }),
|
.then((cats) => { categories.value = cats.map(c => ({ value: c['@id'], label: c.name, code: c.code })) }),
|
||||||
fetchAll<SiteMember>('/sites')
|
fetchAll<SiteMember>('/sites')
|
||||||
// Libelle = numero de departement (2 premiers chiffres du code
|
.then((sitesList) => { sites.value = sitesList.map(s => ({ value: s['@id'], label: s.name })) }),
|
||||||
// postal du site), ex: 86100 -> « 86 ». Le code postal est deja
|
|
||||||
// expose par /sites (groupe site:read) — aucune colonne a ajouter.
|
|
||||||
.then((sitesList) => { sites.value = sitesList.map(s => ({ value: s['@id'], label: (s.postalCode ?? '').slice(0, 2) })) }),
|
|
||||||
fetchAll<ReferentialMember>('/tva_modes')
|
fetchAll<ReferentialMember>('/tva_modes')
|
||||||
.then((tva) => { tvaModes.value = tva.map(t => ({ value: t['@id'], label: t.label })) }),
|
.then((tva) => { tvaModes.value = tva.map(t => ({ value: t['@id'], label: t.label })) }),
|
||||||
fetchAll<ReferentialMember>('/payment_delays')
|
fetchAll<ReferentialMember>('/payment_delays')
|
||||||
|
|||||||
@@ -29,6 +29,16 @@
|
|||||||
:required="true"
|
:required="true"
|
||||||
:readonly="businessReadonly"
|
:readonly="businessReadonly"
|
||||||
/>
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="main.lastName"
|
||||||
|
:label="t('commercial.clients.form.main.lastName')"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="main.firstName"
|
||||||
|
:label="t('commercial.clients.form.main.firstName')"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
/>
|
||||||
<MalioSelectCheckbox
|
<MalioSelectCheckbox
|
||||||
:model-value="main.categoryIris"
|
:model-value="main.categoryIris"
|
||||||
:options="mainCategoryOptions"
|
:options="mainCategoryOptions"
|
||||||
@@ -37,11 +47,34 @@
|
|||||||
:disabled="businessReadonly"
|
:disabled="businessReadonly"
|
||||||
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
||||||
/>
|
/>
|
||||||
|
<MalioInputPhone
|
||||||
|
v-model="main.phonePrimary"
|
||||||
|
:label="t('commercial.clients.form.main.phonePrimary')"
|
||||||
|
:mask="PHONE_MASK"
|
||||||
|
:required="true"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
add-icon-name="mdi:plus"
|
||||||
|
:addable="!main.hasSecondaryPhone && !businessReadonly"
|
||||||
|
:add-button-label="t('commercial.clients.form.main.addPhone')"
|
||||||
|
@add="main.hasSecondaryPhone = true"
|
||||||
|
/>
|
||||||
|
<MalioInputPhone
|
||||||
|
v-if="main.hasSecondaryPhone"
|
||||||
|
v-model="main.phoneSecondary"
|
||||||
|
:label="t('commercial.clients.form.main.phoneSecondary')"
|
||||||
|
:mask="PHONE_MASK"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
/>
|
||||||
|
<MalioInputEmail
|
||||||
|
v-model="main.email"
|
||||||
|
:label="t('commercial.clients.form.main.email')"
|
||||||
|
:required="true"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
:model-value="main.relationType"
|
:model-value="main.relationType"
|
||||||
:options="relationOptions"
|
:options="relationOptions"
|
||||||
:label="t('commercial.clients.form.main.relation')"
|
:label="t('commercial.clients.form.main.relation')"
|
||||||
:empty-option-label="t('commercial.clients.form.main.relationNone')"
|
|
||||||
:disabled="businessReadonly"
|
:disabled="businessReadonly"
|
||||||
@update:model-value="onRelationChange"
|
@update:model-value="onRelationChange"
|
||||||
/>
|
/>
|
||||||
@@ -146,6 +179,9 @@
|
|||||||
@update:model-value="(v) => contacts[index] = v"
|
@update:model-value="(v) => contacts[index] = v"
|
||||||
@remove="askRemoveContact(index)"
|
@remove="askRemoveContact(index)"
|
||||||
/>
|
/>
|
||||||
|
<p v-if="contacts.length === 0" class="text-center text-black/60">
|
||||||
|
{{ t('commercial.clients.edit.emptyContacts') }}
|
||||||
|
</p>
|
||||||
<div v-if="!businessReadonly" class="flex justify-center gap-6">
|
<div v-if="!businessReadonly" class="flex justify-center gap-6">
|
||||||
<MalioButton
|
<MalioButton
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
@@ -183,6 +219,9 @@
|
|||||||
@remove="askRemoveAddress(index)"
|
@remove="askRemoveAddress(index)"
|
||||||
@degraded="onAddressDegraded"
|
@degraded="onAddressDegraded"
|
||||||
/>
|
/>
|
||||||
|
<p v-if="addresses.length === 0" class="text-center text-black/60">
|
||||||
|
{{ t('commercial.clients.edit.emptyAddresses') }}
|
||||||
|
</p>
|
||||||
<div v-if="!businessReadonly" class="flex justify-center gap-6">
|
<div v-if="!businessReadonly" class="flex justify-center gap-6">
|
||||||
<MalioButton
|
<MalioButton
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
@@ -206,7 +245,7 @@
|
|||||||
<template v-if="canAccountingView" #accounting>
|
<template v-if="canAccountingView" #accounting>
|
||||||
<div class="mt-12 flex flex-col gap-6">
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
<div class="grid grid-cols-3 gap-x-[80px] gap-y-5">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="accounting.siren"
|
v-model="accounting.siren"
|
||||||
:label="t('commercial.clients.form.accounting.siren')"
|
:label="t('commercial.clients.form.accounting.siren')"
|
||||||
@@ -273,7 +312,7 @@
|
|||||||
v-bind="{ ariaLabel: t('commercial.clients.form.accounting.removeRib') }"
|
v-bind="{ ariaLabel: t('commercial.clients.form.accounting.removeRib') }"
|
||||||
@click="askRemoveRib(index)"
|
@click="askRemoveRib(index)"
|
||||||
/>
|
/>
|
||||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
<div class="grid grid-cols-3 gap-x-[80px] gap-y-5">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="rib.label"
|
v-model="rib.label"
|
||||||
:label="t('commercial.clients.form.accounting.ribLabel')"
|
:label="t('commercial.clients.form.accounting.ribLabel')"
|
||||||
@@ -311,10 +350,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Onglets non encore implementes : frame vide (navigation libre). -->
|
<!-- Onglets non encore implementes : frame vide (navigation libre). -->
|
||||||
<template #transport><ComingSoonPlaceholder /></template>
|
<template #transport><TabPlaceholderBlank /></template>
|
||||||
<template #statistics><ComingSoonPlaceholder /></template>
|
<template #statistics><TabPlaceholderBlank /></template>
|
||||||
<template #reports><ComingSoonPlaceholder /></template>
|
<template #reports><TabPlaceholderBlank /></template>
|
||||||
<template #exchanges><ComingSoonPlaceholder /></template>
|
<template #exchanges><TabPlaceholderBlank /></template>
|
||||||
</MalioTabList>
|
</MalioTabList>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -391,6 +430,7 @@ import {
|
|||||||
import { extractApiErrorMessage } from '~/shared/utils/api'
|
import { extractApiErrorMessage } from '~/shared/utils/api'
|
||||||
|
|
||||||
// Masques de saisie (la normalisation finale reste serveur).
|
// Masques de saisie (la normalisation finale reste serveur).
|
||||||
|
const PHONE_MASK = '## ## ## ## ##'
|
||||||
const SIREN_MASK = '#########'
|
const SIREN_MASK = '#########'
|
||||||
const EMPLOYEES_MASK = '#######'
|
const EMPLOYEES_MASK = '#######'
|
||||||
|
|
||||||
@@ -455,11 +495,6 @@ function hydrate(detail: ClientDetail): void {
|
|||||||
contacts.value = (detail.contacts ?? []).map(mapContactToDraft)
|
contacts.value = (detail.contacts ?? []).map(mapContactToDraft)
|
||||||
addresses.value = (detail.addresses ?? []).map(mapAddressToDraft)
|
addresses.value = (detail.addresses ?? []).map(mapAddressToDraft)
|
||||||
ribs.value = (detail.ribs ?? []).map(mapRibToDraft)
|
ribs.value = (detail.ribs ?? []).map(mapRibToDraft)
|
||||||
// Chaque bloc reste visible meme vide : si une collection est vide, on amorce
|
|
||||||
// un bloc vierge (non persiste tant qu'incomplet — cf. submit*/canValidate*).
|
|
||||||
if (contacts.value.length === 0) contacts.value.push(emptyContact())
|
|
||||||
if (addresses.value.length === 0) addresses.value.push(emptyAddress())
|
|
||||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
|
||||||
// Charge les listes distributeur / courtier si une relation est deja posee.
|
// Charge les listes distributeur / courtier si une relation est deja posee.
|
||||||
if (main.relationType === 'distributeur') referentials.loadDistributors().catch(() => {})
|
if (main.relationType === 'distributeur') referentials.loadDistributors().catch(() => {})
|
||||||
if (main.relationType === 'courtier') referentials.loadBrokers().catch(() => {})
|
if (main.relationType === 'courtier') referentials.loadBrokers().catch(() => {})
|
||||||
@@ -586,6 +621,9 @@ const isMainValid = computed(() => {
|
|||||||
|| (main.relationType === 'distributeur' && filled(main.distributorIri))
|
|| (main.relationType === 'distributeur' && filled(main.distributorIri))
|
||||||
|| (main.relationType === 'courtier' && filled(main.brokerIri))
|
|| (main.relationType === 'courtier' && filled(main.brokerIri))
|
||||||
return filled(main.companyName)
|
return filled(main.companyName)
|
||||||
|
&& filled(main.email)
|
||||||
|
&& filled(main.phonePrimary)
|
||||||
|
&& (filled(main.firstName) || filled(main.lastName))
|
||||||
&& main.categoryIris.length >= 1
|
&& main.categoryIris.length >= 1
|
||||||
&& relationValid
|
&& relationValid
|
||||||
})
|
})
|
||||||
@@ -656,8 +694,6 @@ function askRemoveContact(index: number): void {
|
|||||||
const removed = contacts.value[index]
|
const removed = contacts.value[index]
|
||||||
if (removed?.id != null) removedContactIds.value.push(removed.id)
|
if (removed?.id != null) removedContactIds.value.push(removed.id)
|
||||||
contacts.value.splice(index, 1)
|
contacts.value.splice(index, 1)
|
||||||
// Garde au moins un bloc visible (cf. amorce a l'hydratation).
|
|
||||||
if (contacts.value.length === 0) contacts.value.push(emptyContact())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -706,9 +742,7 @@ const canValidateAddresses = computed(() =>
|
|||||||
addresses.value.length > 0
|
addresses.value.length > 0
|
||||||
&& addresses.value.every((a) => {
|
&& addresses.value.every((a) => {
|
||||||
const filledBillingEmail = a.billingEmail !== null && a.billingEmail.trim() !== ''
|
const filledBillingEmail = a.billingEmail !== null && a.billingEmail.trim() !== ''
|
||||||
return a.siteIris.length >= 1
|
return a.siteIris.length >= 1 && (!isBillingEmailRequired(a) || filledBillingEmail)
|
||||||
&& a.categoryIris.length >= 1
|
|
||||||
&& (!isBillingEmailRequired(a) || filledBillingEmail)
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -721,8 +755,6 @@ function askRemoveAddress(index: number): void {
|
|||||||
const removed = addresses.value[index]
|
const removed = addresses.value[index]
|
||||||
if (removed?.id != null) removedAddressIds.value.push(removed.id)
|
if (removed?.id != null) removedAddressIds.value.push(removed.id)
|
||||||
addresses.value.splice(index, 1)
|
addresses.value.splice(index, 1)
|
||||||
// Garde au moins un bloc visible (cf. amorce a l'hydratation).
|
|
||||||
if (addresses.value.length === 0) addresses.value.push(emptyAddress())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -801,8 +833,6 @@ function askRemoveRib(index: number): void {
|
|||||||
const removed = ribs.value[index]
|
const removed = ribs.value[index]
|
||||||
if (removed?.id != null) removedRibIds.value.push(removed.id)
|
if (removed?.id != null) removedRibIds.value.push(removed.id)
|
||||||
ribs.value.splice(index, 1)
|
ribs.value.splice(index, 1)
|
||||||
// Garde au moins un bloc RIB visible (cf. amorce a l'hydratation).
|
|
||||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,16 @@
|
|||||||
:label="t('commercial.clients.form.main.companyName')"
|
:label="t('commercial.clients.form.main.companyName')"
|
||||||
readonly
|
readonly
|
||||||
/>
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="client.lastName"
|
||||||
|
:label="t('commercial.clients.form.main.lastName')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="client.firstName"
|
||||||
|
:label="t('commercial.clients.form.main.firstName')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
<MalioSelectCheckbox
|
<MalioSelectCheckbox
|
||||||
:model-value="categoryIris"
|
:model-value="categoryIris"
|
||||||
:options="mainCategoryOptions"
|
:options="mainCategoryOptions"
|
||||||
@@ -59,16 +69,26 @@
|
|||||||
:display-tag="true"
|
:display-tag="true"
|
||||||
disabled
|
disabled
|
||||||
/>
|
/>
|
||||||
<!-- Relation toujours affichee (vide = « Aucun »), comme en edition. -->
|
<MalioInputPhone
|
||||||
|
v-for="(phone, index) in mainPhones"
|
||||||
|
:key="index"
|
||||||
|
:model-value="phone"
|
||||||
|
:label="index === 0 ? t('commercial.clients.form.main.phonePrimary') : t('commercial.clients.form.main.phoneSecondary')"
|
||||||
|
:mask="PHONE_MASK"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputEmail
|
||||||
|
:model-value="client.email"
|
||||||
|
:label="t('commercial.clients.form.main.email')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
|
v-if="relation.type"
|
||||||
:model-value="relation.type"
|
:model-value="relation.type"
|
||||||
:options="relationOptions"
|
:options="relationOptions"
|
||||||
:label="t('commercial.clients.form.main.relation')"
|
:label="t('commercial.clients.form.main.relation')"
|
||||||
:empty-option-label="t('commercial.clients.form.main.relationNone')"
|
|
||||||
disabled
|
disabled
|
||||||
/>
|
/>
|
||||||
<!-- Nom du distributeur/courtier : conditionnel (libelle type-dependant,
|
|
||||||
aucune valeur sans relation — meme comportement qu'en edition). -->
|
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-if="relation.type"
|
v-if="relation.type"
|
||||||
:model-value="relation.name"
|
:model-value="relation.name"
|
||||||
@@ -139,6 +159,9 @@
|
|||||||
:title="t('commercial.clients.form.contact.title', { n: index + 1 })"
|
:title="t('commercial.clients.form.contact.title', { n: index + 1 })"
|
||||||
readonly
|
readonly
|
||||||
/>
|
/>
|
||||||
|
<p v-if="contacts.length === 0" class="text-center text-black/60">
|
||||||
|
{{ t('commercial.clients.consultation.emptyContacts') }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -151,11 +174,14 @@
|
|||||||
:model-value="view.draft"
|
:model-value="view.draft"
|
||||||
:title="t('commercial.clients.form.address.title', { n: index + 1 })"
|
:title="t('commercial.clients.form.address.title', { n: index + 1 })"
|
||||||
:category-options="view.categoryOptions"
|
:category-options="view.categoryOptions"
|
||||||
:site-options="allSiteOptions"
|
:site-options="view.siteOptions"
|
||||||
:contact-options="contactOptions"
|
:contact-options="contactOptions"
|
||||||
:country-options="countryOptions"
|
:country-options="countryOptions"
|
||||||
readonly
|
readonly
|
||||||
/>
|
/>
|
||||||
|
<p v-if="addressViews.length === 0" class="text-center text-black/60">
|
||||||
|
{{ t('commercial.clients.consultation.emptyAddresses') }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -163,7 +189,7 @@
|
|||||||
<template v-if="canAccountingView" #accounting>
|
<template v-if="canAccountingView" #accounting>
|
||||||
<div class="mt-12 flex flex-col gap-6">
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
<div class="grid grid-cols-3 gap-x-[80px] gap-y-5">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
:model-value="accounting.siren"
|
:model-value="accounting.siren"
|
||||||
:label="t('commercial.clients.form.accounting.siren')"
|
:label="t('commercial.clients.form.accounting.siren')"
|
||||||
@@ -218,7 +244,7 @@
|
|||||||
:key="rib.id ?? index"
|
:key="rib.id ?? index"
|
||||||
class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
||||||
>
|
>
|
||||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
<div class="grid grid-cols-3 gap-x-[80px] gap-y-5">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
:model-value="rib.label"
|
:model-value="rib.label"
|
||||||
:label="t('commercial.clients.form.accounting.ribLabel')"
|
:label="t('commercial.clients.form.accounting.ribLabel')"
|
||||||
@@ -240,10 +266,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Onglets non encore implementes : frame vide (navigation libre). -->
|
<!-- Onglets non encore implementes : frame vide (navigation libre). -->
|
||||||
<template #transport><ComingSoonPlaceholder /></template>
|
<template #transport><TabPlaceholderBlank /></template>
|
||||||
<template #statistics><ComingSoonPlaceholder /></template>
|
<template #statistics><TabPlaceholderBlank /></template>
|
||||||
<template #reports><ComingSoonPlaceholder /></template>
|
<template #reports><TabPlaceholderBlank /></template>
|
||||||
<template #exchanges><ComingSoonPlaceholder /></template>
|
<template #exchanges><TabPlaceholderBlank /></template>
|
||||||
</MalioTabList>
|
</MalioTabList>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -293,9 +319,10 @@ import {
|
|||||||
type ClientDetail,
|
type ClientDetail,
|
||||||
type SelectOption,
|
type SelectOption,
|
||||||
} from '~/modules/commercial/utils/clientConsultation'
|
} from '~/modules/commercial/utils/clientConsultation'
|
||||||
import { emptyAddress, emptyContact, emptyRib } from '~/modules/commercial/types/clientForm'
|
import { formatPhoneFR } from '~/shared/utils/phone'
|
||||||
|
|
||||||
// Masque d'affichage (purement visuel, la donnee reste celle du serveur).
|
// Masques d'affichage (purement visuels, la donnee reste celle du serveur).
|
||||||
|
const PHONE_MASK = '## ## ## ## ##'
|
||||||
const SIREN_MASK = '#########'
|
const SIREN_MASK = '#########'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
@@ -303,7 +330,6 @@ const route = useRoute()
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { can, canAny } = usePermissions()
|
const { can, canAny } = usePermissions()
|
||||||
const authStore = useAuthStore()
|
|
||||||
|
|
||||||
// Gating de la route : la consultation exige `view`. Usine (sans view) est
|
// Gating de la route : la consultation exige `view`. Usine (sans view) est
|
||||||
// redirige vers le repertoire (lui-meme protege). Cf. matrice § 2.7.
|
// redirige vers le repertoire (lui-meme protege). Cf. matrice § 2.7.
|
||||||
@@ -328,6 +354,13 @@ const headerTitle = computed(() => client.value?.companyName ?? t('commercial.cl
|
|||||||
const relation = computed(() => (client.value ? relationOf(client.value) : { type: null, name: null }))
|
const relation = computed(() => (client.value ? relationOf(client.value) : { type: null, name: null }))
|
||||||
const categoryIris = computed(() => (client.value?.categories ?? []).map(c => c['@id']))
|
const categoryIris = computed(() => (client.value?.categories ?? []).map(c => c['@id']))
|
||||||
|
|
||||||
|
// Telephones du formulaire principal, formates XX XX XX XX XX (RG d'affichage).
|
||||||
|
const mainPhones = computed(() =>
|
||||||
|
[client.value?.phonePrimary, client.value?.phoneSecondary]
|
||||||
|
.filter((p): p is string => Boolean(p))
|
||||||
|
.map(formatPhoneFR),
|
||||||
|
)
|
||||||
|
|
||||||
const information = computed(() => ({
|
const information = computed(() => ({
|
||||||
description: client.value?.description ?? null,
|
description: client.value?.description ?? null,
|
||||||
competitors: client.value?.competitors ?? null,
|
competitors: client.value?.competitors ?? null,
|
||||||
@@ -339,21 +372,10 @@ const information = computed(() => ({
|
|||||||
directorName: client.value?.directorName ?? null,
|
directorName: client.value?.directorName ?? null,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Chaque bloc reste visible meme vide en consultation : si la collection est
|
const contacts = computed(() => (client.value?.contacts ?? []).map(mapContactToDraft))
|
||||||
// vide, on affiche un bloc vierge en lecture seule (pas de message « Aucun … »).
|
|
||||||
const contacts = computed(() => {
|
|
||||||
const list = (client.value?.contacts ?? []).map(mapContactToDraft)
|
|
||||||
return list.length ? list : [emptyContact()]
|
|
||||||
})
|
|
||||||
// Vue par adresse : brouillon + options (sites/categories) propres a l'adresse.
|
// Vue par adresse : brouillon + options (sites/categories) propres a l'adresse.
|
||||||
const addressViews = computed(() => {
|
const addressViews = computed(() => (client.value?.addresses ?? []).map(mapAddressView))
|
||||||
const views = (client.value?.addresses ?? []).map(mapAddressView)
|
const ribs = computed(() => (client.value?.ribs ?? []).map(mapRibToDraft))
|
||||||
return views.length ? views : [{ draft: emptyAddress(), siteOptions: [], categoryOptions: [] }]
|
|
||||||
})
|
|
||||||
const ribs = computed(() => {
|
|
||||||
const list = (client.value?.ribs ?? []).map(mapRibToDraft)
|
|
||||||
return list.length ? list : [emptyRib()]
|
|
||||||
})
|
|
||||||
// Draft comptable (tout null si l'utilisateur n'a pas accounting.view).
|
// Draft comptable (tout null si l'utilisateur n'a pas accounting.view).
|
||||||
const accounting = computed(() => mapAccountingDraft(client.value ?? ({} as ClientDetail)))
|
const accounting = computed(() => mapAccountingDraft(client.value ?? ({} as ClientDetail)))
|
||||||
|
|
||||||
@@ -363,18 +385,6 @@ const accounting = computed(() => mapAccountingDraft(client.value ?? ({} as Clie
|
|||||||
const mainCategoryOptions = computed(() => categoryOptionsOf(client.value?.categories))
|
const mainCategoryOptions = computed(() => categoryOptionsOf(client.value?.categories))
|
||||||
const contactOptions = computed(() => contactOptionsOf(client.value?.contacts))
|
const contactOptions = computed(() => contactOptionsOf(client.value?.contacts))
|
||||||
|
|
||||||
// Liste COMPLETE des sites disponibles, issue de /api/me (groupe me:read — donc
|
|
||||||
// pas de 403 pour les roles metier, contrairement a GET /sites). Libelle = numero
|
|
||||||
// de departement (2 premiers chiffres du code postal). Permet d'afficher TOUJOURS
|
|
||||||
// toutes les cases « Sites » (86 / 17 / 82) dans le bloc adresse, meme celles non
|
|
||||||
// rattachees a l'adresse consultee (les rattachees restent cochees via siteIris).
|
|
||||||
const allSiteOptions = computed<SelectOption[]>(() =>
|
|
||||||
(authStore.user?.sites ?? []).map(s => ({
|
|
||||||
value: `/api/sites/${s.id}`,
|
|
||||||
label: (s.postalCode ?? '').slice(0, 2),
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
|
|
||||||
const relationOptions = computed<SelectOption[]>(() => [
|
const relationOptions = computed<SelectOption[]>(() => [
|
||||||
{ value: 'distributeur', label: t('commercial.clients.form.main.relationDistributor') },
|
{ value: 'distributeur', label: t('commercial.clients.form.main.relationDistributor') },
|
||||||
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
||||||
|
|||||||
@@ -23,6 +23,16 @@
|
|||||||
:required="true"
|
:required="true"
|
||||||
:readonly="mainLocked"
|
:readonly="mainLocked"
|
||||||
/>
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="main.lastName"
|
||||||
|
:label="t('commercial.clients.form.main.lastName')"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="main.firstName"
|
||||||
|
:label="t('commercial.clients.form.main.firstName')"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
/>
|
||||||
<MalioSelectCheckbox
|
<MalioSelectCheckbox
|
||||||
:model-value="main.categoryIris"
|
:model-value="main.categoryIris"
|
||||||
:options="referentials.categories.value"
|
:options="referentials.categories.value"
|
||||||
@@ -31,11 +41,30 @@
|
|||||||
:disabled="mainLocked"
|
:disabled="mainLocked"
|
||||||
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
||||||
/>
|
/>
|
||||||
|
<!-- Telephones : 1 par defaut, le bouton « + » revele le 2e (max 2, RG-1.02). -->
|
||||||
|
<MalioInputPhone
|
||||||
|
v-for="(_, index) in mainPhones"
|
||||||
|
:key="index"
|
||||||
|
v-model="mainPhones[index]"
|
||||||
|
:label="t('commercial.clients.form.main.phonePrimary')"
|
||||||
|
:mask="PHONE_MASK"
|
||||||
|
:required="index === 0"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
add-icon-name="mdi:plus"
|
||||||
|
:addable="mainPhones.length === 1 && !mainLocked"
|
||||||
|
:add-button-label="t('commercial.clients.form.main.addPhone')"
|
||||||
|
@add="addMainPhone"
|
||||||
|
/>
|
||||||
|
<MalioInputEmail
|
||||||
|
v-model="main.email"
|
||||||
|
:label="t('commercial.clients.form.main.email')"
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
:model-value="main.relationType"
|
:model-value="main.relationType"
|
||||||
:options="relationOptions"
|
:options="relationOptions"
|
||||||
:label="t('commercial.clients.form.main.relation')"
|
:label="t('commercial.clients.form.main.relation')"
|
||||||
:empty-option-label="t('commercial.clients.form.main.relationNone')"
|
|
||||||
:disabled="mainLocked"
|
:disabled="mainLocked"
|
||||||
@update:model-value="onRelationChange"
|
@update:model-value="onRelationChange"
|
||||||
/>
|
/>
|
||||||
@@ -204,7 +233,7 @@
|
|||||||
<template v-if="canAccountingView" #accounting>
|
<template v-if="canAccountingView" #accounting>
|
||||||
<div class="mt-12 flex flex-col gap-6">
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
<div class="grid grid-cols-3 gap-x-[80px] gap-y-5">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="accounting.siren"
|
v-model="accounting.siren"
|
||||||
:label="t('commercial.clients.form.accounting.siren')"
|
:label="t('commercial.clients.form.accounting.siren')"
|
||||||
@@ -272,7 +301,7 @@
|
|||||||
v-bind="{ ariaLabel: t('commercial.clients.form.accounting.removeRib') }"
|
v-bind="{ ariaLabel: t('commercial.clients.form.accounting.removeRib') }"
|
||||||
@click="askRemoveRib(index)"
|
@click="askRemoveRib(index)"
|
||||||
/>
|
/>
|
||||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
<div class="grid grid-cols-3 gap-x-[80px] gap-y-5">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="rib.label"
|
v-model="rib.label"
|
||||||
:label="t('commercial.clients.form.accounting.ribLabel')"
|
:label="t('commercial.clients.form.accounting.ribLabel')"
|
||||||
@@ -312,7 +341,7 @@
|
|||||||
<!-- Onglet non encore implemente : frame vide, passage automatique.
|
<!-- Onglet non encore implemente : frame vide, passage automatique.
|
||||||
Statistiques / Rapports / Echanges sont edit-only (absents a la
|
Statistiques / Rapports / Echanges sont edit-only (absents a la
|
||||||
creation) — cf. buildClientFormTabKeys. -->
|
creation) — cf. buildClientFormTabKeys. -->
|
||||||
<template #transport><ComingSoonPlaceholder /></template>
|
<template #transport><TabPlaceholderBlank /></template>
|
||||||
</MalioTabList>
|
</MalioTabList>
|
||||||
|
|
||||||
<!-- Modal de confirmation generique (suppression contact/adresse/RIB). -->
|
<!-- Modal de confirmation generique (suppression contact/adresse/RIB). -->
|
||||||
@@ -359,9 +388,11 @@ import {
|
|||||||
type ContactFormDraft,
|
type ContactFormDraft,
|
||||||
type RibFormDraft,
|
type RibFormDraft,
|
||||||
} from '~/modules/commercial/types/clientForm'
|
} from '~/modules/commercial/types/clientForm'
|
||||||
|
import { formatPhoneFR } from '~/shared/utils/phone'
|
||||||
import { extractApiErrorMessage } from '~/shared/utils/api'
|
import { extractApiErrorMessage } from '~/shared/utils/api'
|
||||||
|
|
||||||
// Masques de saisie (la normalisation finale reste serveur).
|
// Masques de saisie (la normalisation finale reste serveur).
|
||||||
|
const PHONE_MASK = '## ## ## ## ##'
|
||||||
const SIREN_MASK = '#########'
|
const SIREN_MASK = '#########'
|
||||||
// Masque « nombre » du champ Nombre de salaries : chiffres uniquement (max 7).
|
// Masque « nombre » du champ Nombre de salaries : chiffres uniquement (max 7).
|
||||||
const EMPLOYEES_MASK = '#######'
|
const EMPLOYEES_MASK = '#######'
|
||||||
@@ -413,6 +444,9 @@ const tabSubmitting = ref(false)
|
|||||||
// ── Formulaire principal ────────────────────────────────────────────────────
|
// ── Formulaire principal ────────────────────────────────────────────────────
|
||||||
const main = reactive({
|
const main = reactive({
|
||||||
companyName: null as string | null,
|
companyName: null as string | null,
|
||||||
|
firstName: null as string | null,
|
||||||
|
lastName: null as string | null,
|
||||||
|
email: null as string | null,
|
||||||
categoryIris: [] as string[],
|
categoryIris: [] as string[],
|
||||||
relationType: null as 'distributeur' | 'courtier' | null,
|
relationType: null as 'distributeur' | 'courtier' | null,
|
||||||
distributorIri: null as string | null,
|
distributorIri: null as string | null,
|
||||||
@@ -420,6 +454,17 @@ const main = reactive({
|
|||||||
triageService: false,
|
triageService: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Telephones du formulaire principal : 1 par defaut, 2 au maximum (RG-1.02).
|
||||||
|
// L'index 0 alimente phonePrimary, l'index 1 phoneSecondary au POST.
|
||||||
|
const mainPhones = ref<string[]>([''])
|
||||||
|
|
||||||
|
/** Revele le 2e numero (le bouton « + » disparait une fois a 2, RG-1.02). */
|
||||||
|
function addMainPhone(): void {
|
||||||
|
if (mainPhones.value.length === 1) {
|
||||||
|
mainPhones.value.push('')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pas d'option « Aucun » : le select est vide par defaut (relationType = null).
|
// Pas d'option « Aucun » : le select est vide par defaut (relationType = null).
|
||||||
const relationOptions = computed<RefOption[]>(() => [
|
const relationOptions = computed<RefOption[]>(() => [
|
||||||
{ value: 'distributeur', label: t('commercial.clients.form.main.relationDistributor') },
|
{ value: 'distributeur', label: t('commercial.clients.form.main.relationDistributor') },
|
||||||
@@ -427,11 +472,10 @@ const relationOptions = computed<RefOption[]>(() => [
|
|||||||
])
|
])
|
||||||
|
|
||||||
// Validation du formulaire principal (gate le bouton « Valider ») :
|
// Validation du formulaire principal (gate le bouton « Valider ») :
|
||||||
// - companyName / >= 1 categorie obligatoires ;
|
// - companyName / email / telephone principal / >= 1 categorie obligatoires ;
|
||||||
// - relation Distributeur/Courtier optionnelle, mais le nom correspondant
|
// - RG-1.01 : nom OU prenom du contact principal ;
|
||||||
// devient requis si l'un des deux est choisi (spec fonctionnelle).
|
// - relation Distributeur/Courtier obligatoire (un des deux), ET le nom
|
||||||
// Les coordonnees de contact ne sont plus saisies ici : elles vivent dans
|
// correspondant obligatoire selon le choix (spec fonctionnelle).
|
||||||
// l'onglet Contacts (RG-1.05/1.14 garantissent >= 1 contact valide).
|
|
||||||
const isMainValid = computed(() => {
|
const isMainValid = computed(() => {
|
||||||
const filled = (v: string | null | undefined) => v !== null && v !== undefined && v.trim() !== ''
|
const filled = (v: string | null | undefined) => v !== null && v !== undefined && v.trim() !== ''
|
||||||
// Relation Distributeur/Courtier OPTIONNELLE ; mais si « Depend du
|
// Relation Distributeur/Courtier OPTIONNELLE ; mais si « Depend du
|
||||||
@@ -441,6 +485,9 @@ const isMainValid = computed(() => {
|
|||||||
|| (main.relationType === 'distributeur' && filled(main.distributorIri))
|
|| (main.relationType === 'distributeur' && filled(main.distributorIri))
|
||||||
|| (main.relationType === 'courtier' && filled(main.brokerIri))
|
|| (main.relationType === 'courtier' && filled(main.brokerIri))
|
||||||
return filled(main.companyName)
|
return filled(main.companyName)
|
||||||
|
&& filled(main.email)
|
||||||
|
&& filled(mainPhones.value[0])
|
||||||
|
&& (filled(main.firstName) || filled(main.lastName))
|
||||||
&& main.categoryIris.length >= 1
|
&& main.categoryIris.length >= 1
|
||||||
&& relationValid
|
&& relationValid
|
||||||
})
|
})
|
||||||
@@ -465,6 +512,11 @@ async function submitMain(): Promise<void> {
|
|||||||
try {
|
try {
|
||||||
const payload: Record<string, unknown> = {
|
const payload: Record<string, unknown> = {
|
||||||
companyName: main.companyName,
|
companyName: main.companyName,
|
||||||
|
firstName: main.firstName || null,
|
||||||
|
lastName: main.lastName || null,
|
||||||
|
email: main.email,
|
||||||
|
phonePrimary: mainPhones.value[0] || null,
|
||||||
|
phoneSecondary: mainPhones.value[1] || null,
|
||||||
categories: main.categoryIris,
|
categories: main.categoryIris,
|
||||||
distributor: main.relationType === 'distributeur' ? main.distributorIri : null,
|
distributor: main.relationType === 'distributeur' ? main.distributorIri : null,
|
||||||
broker: main.relationType === 'courtier' ? main.brokerIri : null,
|
broker: main.relationType === 'courtier' ? main.brokerIri : null,
|
||||||
@@ -476,8 +528,18 @@ async function submitMain(): Promise<void> {
|
|||||||
})
|
})
|
||||||
|
|
||||||
clientId.value = created.id
|
clientId.value = created.id
|
||||||
// Reaffiche la valeur normalisee renvoyee par le serveur.
|
// Reaffiche les valeurs normalisees renvoyees par le serveur.
|
||||||
main.companyName = created.companyName ?? main.companyName
|
main.companyName = created.companyName ?? main.companyName
|
||||||
|
main.firstName = created.firstName ?? null
|
||||||
|
main.lastName = created.lastName ?? null
|
||||||
|
main.email = created.email ?? main.email
|
||||||
|
// Reaffiche les telephones normalises (reformates via formatPhoneFR).
|
||||||
|
const normalizedPhones = [formatPhoneFR(created.phonePrimary), formatPhoneFR(created.phoneSecondary)]
|
||||||
|
.filter(p => p !== '')
|
||||||
|
mainPhones.value = normalizedPhones.length > 0 ? normalizedPhones : ['']
|
||||||
|
|
||||||
|
// Pre-remplit le 1er contact a partir du formulaire principal (editable).
|
||||||
|
prefillFirstContact()
|
||||||
|
|
||||||
mainLocked.value = true
|
mainLocked.value = true
|
||||||
unlockedIndex.value = 0
|
unlockedIndex.value = 0
|
||||||
@@ -590,10 +652,18 @@ async function submitInformation(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Onglet Contact ──────────────────────────────────────────────────────────
|
// ── Onglet Contact ──────────────────────────────────────────────────────────
|
||||||
// Au moins un bloc Contact vide au depart : c'est desormais le seul point de
|
|
||||||
// saisie des coordonnees (le bloc principal ne porte plus de contact inline).
|
|
||||||
const contacts = ref<ContactFormDraft[]>([emptyContact()])
|
const contacts = ref<ContactFormDraft[]>([emptyContact()])
|
||||||
|
|
||||||
|
/** Pre-remplit le 1er contact depuis le formulaire principal (apres creation). */
|
||||||
|
function prefillFirstContact(): void {
|
||||||
|
const first = contacts.value[0]
|
||||||
|
if (!first) return
|
||||||
|
first.lastName = main.lastName
|
||||||
|
first.firstName = main.firstName
|
||||||
|
first.email = main.email
|
||||||
|
first.phonePrimary = mainPhones.value[0] ?? null
|
||||||
|
}
|
||||||
|
|
||||||
// « + Nouveau contact » desactive tant que le dernier bloc n'a ni nom ni prenom.
|
// « + Nouveau contact » desactive tant que le dernier bloc n'a ni nom ni prenom.
|
||||||
const canAddContact = computed(() => {
|
const canAddContact = computed(() => {
|
||||||
const last = contacts.value[contacts.value.length - 1]
|
const last = contacts.value[contacts.value.length - 1]
|
||||||
@@ -685,9 +755,7 @@ const canValidateAddresses = computed(() =>
|
|||||||
addresses.value.length > 0
|
addresses.value.length > 0
|
||||||
&& addresses.value.every((a) => {
|
&& addresses.value.every((a) => {
|
||||||
const filledBillingEmail = a.billingEmail !== null && a.billingEmail.trim() !== ''
|
const filledBillingEmail = a.billingEmail !== null && a.billingEmail.trim() !== ''
|
||||||
return a.siteIris.length >= 1
|
return a.siteIris.length >= 1 && (!isBillingEmailRequired(a) || filledBillingEmail)
|
||||||
&& a.categoryIris.length >= 1
|
|
||||||
&& (!isBillingEmailRequired(a) || filledBillingEmail)
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -802,8 +870,6 @@ function addRib(): void {
|
|||||||
function askRemoveRib(index: number): void {
|
function askRemoveRib(index: number): void {
|
||||||
askConfirm(t('commercial.clients.form.confirmDelete.rib'), () => {
|
askConfirm(t('commercial.clients.form.confirmDelete.rib'), () => {
|
||||||
ribs.value.splice(index, 1)
|
ribs.value.splice(index, 1)
|
||||||
// Garde au moins un bloc RIB visible (cf. amorce au montage).
|
|
||||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -875,6 +941,11 @@ function runConfirm(): void {
|
|||||||
interface ClientResponse {
|
interface ClientResponse {
|
||||||
id: number
|
id: number
|
||||||
companyName: string | null
|
companyName: string | null
|
||||||
|
firstName: string | null
|
||||||
|
lastName: string | null
|
||||||
|
email: string | null
|
||||||
|
phonePrimary: string | null
|
||||||
|
phoneSecondary: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContactResponse {
|
interface ContactResponse {
|
||||||
@@ -885,8 +956,5 @@ interface ContactResponse {
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// Echec du chargement des referentiels non bloquant : les selects restent vides.
|
// Echec du chargement des referentiels non bloquant : les selects restent vides.
|
||||||
referentials.loadCommon().catch(() => {})
|
referentials.loadCommon().catch(() => {})
|
||||||
// Au moins un bloc RIB toujours visible en creation : on amorce un bloc vide
|
|
||||||
// (non persiste tant qu'incomplet — RG-1.13).
|
|
||||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ import type { AddressFormDraft, ContactFormDraft, RibFormDraft } from '~/modules
|
|||||||
function mainDraft(overrides: Partial<MainFormDraft> = {}): MainFormDraft {
|
function mainDraft(overrides: Partial<MainFormDraft> = {}): MainFormDraft {
|
||||||
return {
|
return {
|
||||||
companyName: 'ACME',
|
companyName: 'ACME',
|
||||||
|
firstName: 'Jean',
|
||||||
|
lastName: 'Dupont',
|
||||||
|
email: 'jean@acme.fr',
|
||||||
|
phonePrimary: '05 49 11 22 33',
|
||||||
|
phoneSecondary: null,
|
||||||
|
hasSecondaryPhone: false,
|
||||||
categoryIris: ['/api/categories/1'],
|
categoryIris: ['/api/categories/1'],
|
||||||
relationType: null,
|
relationType: null,
|
||||||
distributorIri: null,
|
distributorIri: null,
|
||||||
@@ -58,10 +64,9 @@ function accountingDraft(overrides: Partial<AccountingFormDraft> = {}): Accounti
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Champs de chaque groupe de serialisation (miroir back ClientProcessor).
|
// Champs de chaque groupe de serialisation (miroir back ClientProcessor).
|
||||||
// Le contact inline (nom/prenom/telephones/email) ne fait plus partie du groupe
|
|
||||||
// main : les coordonnees vivent desormais sur la sous-ressource ClientContact.
|
|
||||||
const MAIN_KEYS = [
|
const MAIN_KEYS = [
|
||||||
'companyName', 'categories', 'distributor', 'broker', 'triageService',
|
'companyName', 'firstName', 'lastName', 'email', 'phonePrimary',
|
||||||
|
'phoneSecondary', 'categories', 'distributor', 'broker', 'triageService',
|
||||||
]
|
]
|
||||||
const INFORMATION_KEYS = [
|
const INFORMATION_KEYS = [
|
||||||
'description', 'competitors', 'foundedAt', 'employeesCount',
|
'description', 'competitors', 'foundedAt', 'employeesCount',
|
||||||
@@ -99,6 +104,11 @@ describe('buildMainPayload — scoping strict groupe client:write:main', () => {
|
|||||||
expect(payload.distributor).toBeNull()
|
expect(payload.distributor).toBeNull()
|
||||||
expect(payload.broker).toBeNull()
|
expect(payload.broker).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('telephone secondaire non revele : envoie null meme si une valeur traine', () => {
|
||||||
|
const payload = buildMainPayload(mainDraft({ hasSecondaryPhone: false, phoneSecondary: '06 00 00 00 00' }))
|
||||||
|
expect(payload.phoneSecondary).toBeNull()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('buildInformationPayload — scoping strict groupe client:write:information', () => {
|
describe('buildInformationPayload — scoping strict groupe client:write:information', () => {
|
||||||
@@ -158,16 +168,19 @@ describe('buildContactPayload / buildAddressPayload / buildRibPayload', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('mapMainDraft — pre-remplissage bloc principal', () => {
|
describe('mapMainDraft — pre-remplissage bloc principal', () => {
|
||||||
it('resout la relation et extrait les IRI (sans contact inline)', () => {
|
it('formate les telephones, resout la relation et extrait les IRI', () => {
|
||||||
const client = {
|
const client = {
|
||||||
'@id': '/api/clients/1', id: 1,
|
'@id': '/api/clients/1', id: 1,
|
||||||
companyName: 'ACME', triageService: true,
|
companyName: 'ACME', firstName: 'Jean', lastName: 'Dupont', email: 'jean@acme.fr',
|
||||||
|
phonePrimary: '0549112233', phoneSecondary: '0600000000', triageService: true,
|
||||||
categories: [{ '@id': '/api/categories/1', code: 'SECTEUR' }],
|
categories: [{ '@id': '/api/categories/1', code: 'SECTEUR' }],
|
||||||
distributor: { '@id': '/api/clients/9', companyName: 'DISTRIB' },
|
distributor: { '@id': '/api/clients/9', companyName: 'DISTRIB' },
|
||||||
} as ClientDetail
|
} as ClientDetail
|
||||||
|
|
||||||
const draft = mapMainDraft(client)
|
const draft = mapMainDraft(client)
|
||||||
expect(draft.companyName).toBe('ACME')
|
expect(draft.phonePrimary).toBe('05 49 11 22 33')
|
||||||
|
expect(draft.phoneSecondary).toBe('06 00 00 00 00')
|
||||||
|
expect(draft.hasSecondaryPhone).toBe(true)
|
||||||
expect(draft.categoryIris).toEqual(['/api/categories/1'])
|
expect(draft.categoryIris).toEqual(['/api/categories/1'])
|
||||||
expect(draft.relationType).toBe('distributeur')
|
expect(draft.relationType).toBe('distributeur')
|
||||||
expect(draft.distributorIri).toBe('/api/clients/9')
|
expect(draft.distributorIri).toBe('/api/clients/9')
|
||||||
@@ -178,6 +191,7 @@ describe('mapMainDraft — pre-remplissage bloc principal', () => {
|
|||||||
it('gere les cles omises (skip_null_values) sans planter', () => {
|
it('gere les cles omises (skip_null_values) sans planter', () => {
|
||||||
const draft = mapMainDraft({ '@id': '/api/clients/2', id: 2 } as ClientDetail)
|
const draft = mapMainDraft({ '@id': '/api/clients/2', id: 2 } as ClientDetail)
|
||||||
expect(draft.companyName).toBeNull()
|
expect(draft.companyName).toBeNull()
|
||||||
|
expect(draft.hasSecondaryPhone).toBe(false)
|
||||||
expect(draft.categoryIris).toEqual([])
|
expect(draft.categoryIris).toEqual([])
|
||||||
expect(draft.relationType).toBeNull()
|
expect(draft.relationType).toBeNull()
|
||||||
expect(draft.triageService).toBe(false)
|
expect(draft.triageService).toBe(false)
|
||||||
|
|||||||
@@ -93,6 +93,11 @@ export interface RelatedClientRead extends HydraRef {
|
|||||||
export interface ClientDetail extends HydraRef {
|
export interface ClientDetail extends HydraRef {
|
||||||
id: number
|
id: number
|
||||||
companyName?: string | null
|
companyName?: string | null
|
||||||
|
firstName?: string | null
|
||||||
|
lastName?: string | null
|
||||||
|
phonePrimary?: string | null
|
||||||
|
phoneSecondary?: string | null
|
||||||
|
email?: string | null
|
||||||
triageService?: boolean
|
triageService?: boolean
|
||||||
isArchived?: boolean
|
isArchived?: boolean
|
||||||
categories?: CategoryRead[]
|
categories?: CategoryRead[]
|
||||||
|
|||||||
@@ -24,16 +24,23 @@ import {
|
|||||||
type ClientDetail,
|
type ClientDetail,
|
||||||
} from '~/modules/commercial/utils/clientConsultation'
|
} from '~/modules/commercial/utils/clientConsultation'
|
||||||
import type { AddressFormDraft, ContactFormDraft, RibFormDraft } from '~/modules/commercial/types/clientForm'
|
import type { AddressFormDraft, ContactFormDraft, RibFormDraft } from '~/modules/commercial/types/clientForm'
|
||||||
|
import { formatPhoneFR } from '~/shared/utils/phone'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Etat « plat » du bloc principal (groupe client:write:main). Distinct des
|
* Etat « plat » du bloc principal (groupe client:write:main). Distinct des
|
||||||
* brouillons Contact : ces champs vivent sur le Client lui-meme (companyName,
|
* brouillons Contact : ces champs vivent sur le Client lui-meme (companyName,
|
||||||
* categories, relation, triage), pas sur une sous-ressource ClientContact. Les
|
* contact principal, telephones, email, categories, relation, triage), pas sur
|
||||||
* coordonnees de contact (nom, prenom, telephones, email) ne sont plus portees
|
* une sous-ressource ClientContact.
|
||||||
* par le Client : elles vivent exclusivement dans l'onglet Contacts.
|
|
||||||
*/
|
*/
|
||||||
export interface MainFormDraft {
|
export interface MainFormDraft {
|
||||||
companyName: string | null
|
companyName: string | null
|
||||||
|
firstName: string | null
|
||||||
|
lastName: string | null
|
||||||
|
email: string | null
|
||||||
|
phonePrimary: string | null
|
||||||
|
phoneSecondary: string | null
|
||||||
|
/** UI : le 2e numero a ete revele (ou existait deja au chargement). */
|
||||||
|
hasSecondaryPhone: boolean
|
||||||
/** IRI des categories rattachees (M2M). */
|
/** IRI des categories rattachees (M2M). */
|
||||||
categoryIris: string[]
|
categoryIris: string[]
|
||||||
relationType: 'distributeur' | 'courtier' | null
|
relationType: 'distributeur' | 'courtier' | null
|
||||||
@@ -89,15 +96,22 @@ export interface TabEditability {
|
|||||||
// ── Pre-remplissage (GET detail -> brouillons) ──────────────────────────────
|
// ── Pre-remplissage (GET detail -> brouillons) ──────────────────────────────
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mappe le detail client vers le brouillon du bloc principal. La relation
|
* Mappe le detail client vers le brouillon du bloc principal. Les telephones
|
||||||
* Distributeur/Courtier est resolue par exclusivite (RG-1.03) et son IRI extrait
|
* sont reformates XX XX XX XX XX (RG d'affichage). La relation Distributeur/
|
||||||
* de l'embed.
|
* Courtier est resolue par exclusivite (RG-1.03) et son IRI extrait de l'embed.
|
||||||
*/
|
*/
|
||||||
export function mapMainDraft(client: ClientDetail): MainFormDraft {
|
export function mapMainDraft(client: ClientDetail): MainFormDraft {
|
||||||
const relation = relationOf(client)
|
const relation = relationOf(client)
|
||||||
|
const phoneSecondary = client.phoneSecondary ?? null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
companyName: client.companyName ?? null,
|
companyName: client.companyName ?? null,
|
||||||
|
firstName: client.firstName ?? null,
|
||||||
|
lastName: client.lastName ?? null,
|
||||||
|
email: client.email ?? null,
|
||||||
|
phonePrimary: client.phonePrimary ? formatPhoneFR(client.phonePrimary) : null,
|
||||||
|
phoneSecondary: phoneSecondary ? formatPhoneFR(phoneSecondary) : null,
|
||||||
|
hasSecondaryPhone: phoneSecondary !== null && phoneSecondary !== '',
|
||||||
categoryIris: (client.categories ?? []).map(c => c['@id']),
|
categoryIris: (client.categories ?? []).map(c => c['@id']),
|
||||||
relationType: relation.type,
|
relationType: relation.type,
|
||||||
distributorIri: iriOf(client.distributor),
|
distributorIri: iriOf(client.distributor),
|
||||||
@@ -143,6 +157,11 @@ export function mapAccountingFormDraft(client: ClientDetail): AccountingFormDraf
|
|||||||
export function buildMainPayload(main: MainFormDraft): Record<string, unknown> {
|
export function buildMainPayload(main: MainFormDraft): Record<string, unknown> {
|
||||||
return {
|
return {
|
||||||
companyName: main.companyName,
|
companyName: main.companyName,
|
||||||
|
firstName: main.firstName || null,
|
||||||
|
lastName: main.lastName || null,
|
||||||
|
email: main.email,
|
||||||
|
phonePrimary: main.phonePrimary || null,
|
||||||
|
phoneSecondary: main.hasSecondaryPhone ? (main.phoneSecondary || null) : null,
|
||||||
categories: main.categoryIris,
|
categories: main.categoryIris,
|
||||||
distributor: main.relationType === 'distributeur' ? main.distributorIri : null,
|
distributor: main.relationType === 'distributeur' ? main.distributorIri : null,
|
||||||
broker: main.relationType === 'courtier' ? main.brokerIri : null,
|
broker: main.relationType === 'courtier' ? main.brokerIri : null,
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 MiB |
@@ -1,51 +0,0 @@
|
|||||||
<template>
|
|
||||||
<!--
|
|
||||||
Placeholder generique « En cours de dev » pour les ecrans / onglets non
|
|
||||||
encore implementes. Composant PARTAGE (shared/components) : auto-importe
|
|
||||||
sans prefixe (`<ComingSoonPlaceholder>`) et reutilisable depuis n'importe
|
|
||||||
quel module. Affiche un gif (asset local par defaut) + un message i18n.
|
|
||||||
-->
|
|
||||||
<div class="flex min-h-[240px] flex-col items-center justify-center gap-4 rounded-md bg-white py-10">
|
|
||||||
<img
|
|
||||||
v-if="!imageFailed"
|
|
||||||
:src="src"
|
|
||||||
:alt="resolvedTitle"
|
|
||||||
class="max-h-[220px] w-auto rounded-md"
|
|
||||||
@error="imageFailed = true"
|
|
||||||
>
|
|
||||||
<!-- Repli si le gif ne charge pas (offline, CSP, asset absent) :
|
|
||||||
illustration emoji, le message reste affiche. -->
|
|
||||||
<div v-else class="text-5xl" aria-hidden="true">🚧 👨💻 🚧</div>
|
|
||||||
|
|
||||||
<div class="text-center">
|
|
||||||
<p class="text-xl font-bold text-black">{{ resolvedTitle }}</p>
|
|
||||||
<p class="mt-1 text-black/60">{{ resolvedSubtitle }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
const props = withDefaults(
|
|
||||||
defineProps<{
|
|
||||||
/** Source de l'image/gif affichee. Defaut : asset local `/coming-soon.gif`. */
|
|
||||||
src?: string
|
|
||||||
/** Titre. Defaut : i18n `common.comingSoon.title`. */
|
|
||||||
title?: string
|
|
||||||
/** Sous-titre. Defaut : i18n `common.comingSoon.subtitle`. */
|
|
||||||
subtitle?: string
|
|
||||||
}>(),
|
|
||||||
{
|
|
||||||
src: '/coming-soon.gif',
|
|
||||||
title: '',
|
|
||||||
subtitle: '',
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
const { t } = useI18n()
|
|
||||||
const imageFailed = ref(false)
|
|
||||||
|
|
||||||
// Les props priment sur les libelles i18n par defaut (permet a un module
|
|
||||||
// d'override le texte sans toucher au composant).
|
|
||||||
const resolvedTitle = computed(() => props.title || t('common.comingSoon.title'))
|
|
||||||
const resolvedSubtitle = computed(() => props.subtitle || t('common.comingSoon.subtitle'))
|
|
||||||
</script>
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
||||||
import {
|
|
||||||
useAddressAutocomplete,
|
|
||||||
AddressAutocompleteUnavailableError,
|
|
||||||
} from '../useAddressAutocomplete'
|
|
||||||
|
|
||||||
// On mocke le helper d'appel externe : aucun vrai appel reseau a la BAN.
|
|
||||||
// vi.mock est hoiste par Vitest au-dessus des imports.
|
|
||||||
const mockHttp = vi.hoisted(() => vi.fn())
|
|
||||||
vi.mock('~/shared/utils/httpExternal', () => ({ httpExternal: mockHttp }))
|
|
||||||
|
|
||||||
const BAN_URL = 'https://api-adresse.data.gouv.fr/search/'
|
|
||||||
|
|
||||||
describe('useAddressAutocomplete', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
mockHttp.mockReset()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('searchCity', () => {
|
|
||||||
it('interroge la BAN en type=municipality et mappe { city, postalCode }', async () => {
|
|
||||||
mockHttp.mockResolvedValueOnce({
|
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: [
|
|
||||||
{ properties: { city: 'Amiens', postcode: '80000', name: 'Amiens', type: 'municipality' } },
|
|
||||||
{ properties: { city: 'Amiens', postcode: '80080', name: 'Amiens', type: 'municipality' } },
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
const { searchCity } = useAddressAutocomplete()
|
|
||||||
const res = await searchCity('80000')
|
|
||||||
|
|
||||||
expect(mockHttp).toHaveBeenCalledWith(
|
|
||||||
BAN_URL,
|
|
||||||
expect.objectContaining({ query: { q: '80000', type: 'municipality' } }),
|
|
||||||
)
|
|
||||||
expect(res).toEqual([
|
|
||||||
{ city: 'Amiens', postalCode: '80000' },
|
|
||||||
{ city: 'Amiens', postalCode: '80080' },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('throw une AddressAutocompleteUnavailableError sur erreur reseau / 5xx', async () => {
|
|
||||||
mockHttp.mockRejectedValueOnce(new Error('500 Server Error'))
|
|
||||||
|
|
||||||
const { searchCity } = useAddressAutocomplete()
|
|
||||||
|
|
||||||
await expect(searchCity('80000')).rejects.toBeInstanceOf(AddressAutocompleteUnavailableError)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('throw une AddressAutocompleteUnavailableError sur timeout', async () => {
|
|
||||||
mockHttp.mockRejectedValueOnce(new Error('The operation was aborted due to timeout'))
|
|
||||||
|
|
||||||
const { searchCity } = useAddressAutocomplete()
|
|
||||||
|
|
||||||
await expect(searchCity('80000')).rejects.toBeInstanceOf(AddressAutocompleteUnavailableError)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('searchAddress', () => {
|
|
||||||
it('interroge la BAN avec postcode et mappe la suggestion', async () => {
|
|
||||||
mockHttp.mockResolvedValueOnce({
|
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: [
|
|
||||||
{
|
|
||||||
properties: {
|
|
||||||
label: '8 Boulevard du Port 80000 Amiens',
|
|
||||||
name: '8 Boulevard du Port',
|
|
||||||
street: 'Boulevard du Port',
|
|
||||||
postcode: '80000',
|
|
||||||
city: 'Amiens',
|
|
||||||
type: 'housenumber',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
const { searchAddress } = useAddressAutocomplete()
|
|
||||||
const res = await searchAddress('8 boulevard du port', '80000')
|
|
||||||
|
|
||||||
expect(mockHttp).toHaveBeenCalledWith(
|
|
||||||
BAN_URL,
|
|
||||||
expect.objectContaining({
|
|
||||||
query: { q: '8 boulevard du port', postcode: '80000' },
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
expect(res).toEqual([
|
|
||||||
{
|
|
||||||
label: '8 Boulevard du Port 80000 Amiens',
|
|
||||||
street: '8 Boulevard du Port',
|
|
||||||
postalCode: '80000',
|
|
||||||
city: 'Amiens',
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('omet le parametre postcode quand aucun code postal n\'est fourni', async () => {
|
|
||||||
mockHttp.mockResolvedValueOnce({ type: 'FeatureCollection', features: [] })
|
|
||||||
|
|
||||||
const { searchAddress } = useAddressAutocomplete()
|
|
||||||
await searchAddress('8 boulevard du port')
|
|
||||||
|
|
||||||
expect(mockHttp).toHaveBeenCalledWith(
|
|
||||||
BAN_URL,
|
|
||||||
expect.objectContaining({
|
|
||||||
query: { q: '8 boulevard du port' },
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('ne restreint PAS la recherche a type=housenumber (sinon la BAN ne renvoie rien tant qu\'aucun numero n\'est saisi)', async () => {
|
|
||||||
// Regression : avec `type=housenumber`, une saisie de nom de rue sans
|
|
||||||
// numero (ex: « boulevard du port ») renvoie 0 resultat cote BAN.
|
|
||||||
mockHttp.mockResolvedValueOnce({ type: 'FeatureCollection', features: [] })
|
|
||||||
|
|
||||||
const { searchAddress } = useAddressAutocomplete()
|
|
||||||
await searchAddress('boulevard du port', '80000')
|
|
||||||
|
|
||||||
const sentQuery = mockHttp.mock.calls[0]?.[1]?.query as Record<string, string>
|
|
||||||
expect(sentQuery.type).toBeUndefined()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('throw une AddressAutocompleteUnavailableError sur erreur reseau', async () => {
|
|
||||||
mockHttp.mockRejectedValueOnce(new Error('network down'))
|
|
||||||
|
|
||||||
const { searchAddress } = useAddressAutocomplete()
|
|
||||||
|
|
||||||
await expect(searchAddress('8 boulevard du port', '80000')).rejects.toBeInstanceOf(
|
|
||||||
AddressAutocompleteUnavailableError,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,29 +1,27 @@
|
|||||||
import { httpExternal } from '~/shared/utils/httpExternal'
|
// STUB ERP-63 — remplacé par l'implémentation BAN d'ERP-66.
|
||||||
|
|
||||||
// Autocompletion d'adresse branchee sur la Base Adresse Nationale (BAN),
|
|
||||||
// `api-adresse.data.gouv.fr` — service public francais, gratuit, CORS ouvert.
|
|
||||||
//
|
//
|
||||||
// Appel HTTP DIRECT depuis le front (pas de proxy back), conformement a la spec
|
// Ce fichier appartient fonctionnellement à ERP-66 (#66). ERP-63 n'en livre
|
||||||
// M1 (§ API adresse postale). On passe par `httpExternal` et NON `useApi()` :
|
// qu'un STUB pour ne pas se bloquer : la vraie implémentation (appels
|
||||||
// la BAN est un domaine externe, sans cookie de session ni enveloppe Hydra.
|
// api-adresse.data.gouv.fr) viendra remplacer le CORPS des deux méthodes SANS
|
||||||
|
// changer leur signature ni l'usage côté composant.
|
||||||
//
|
//
|
||||||
// Contrat (fige) :
|
// Contrat figé par ERP-66 (c'est lui qui fait foi) :
|
||||||
// searchCity(postalCode) -> liste { city, postalCode }
|
// searchCity(postalCode) -> liste { city, postalCode }
|
||||||
// searchAddress(query, cp?) -> liste { label, street, postalCode, city }
|
// searchAddress(query, cp?) -> liste { label, street, postalCode, city }
|
||||||
// En cas d'erreur/timeout, la methode THROW une AddressAutocompleteUnavailableError.
|
// En cas d'erreur/timeout, la méthode THROW. Le composant catch l'erreur,
|
||||||
// Le composant consommateur catch, affiche un toast d'avertissement et bascule
|
// affiche un toast d'avertissement et bascule en saisie libre (MalioInputText).
|
||||||
// en saisie libre (MalioInputText).
|
//
|
||||||
|
// Comportement du stub : les deux méthodes throw systématiquement → l'onglet
|
||||||
|
// Adresse part directement en mode dégradé (Ville + Adresse en saisie libre,
|
||||||
|
// Code postal saisi manuellement). Aucun appel réseau n'est émis ici.
|
||||||
|
|
||||||
/** URL de l'endpoint de recherche BAN. */
|
/** Une suggestion de ville renvoyée à partir d'un code postal. */
|
||||||
const BAN_SEARCH_URL = 'https://api-adresse.data.gouv.fr/search/'
|
|
||||||
|
|
||||||
/** Une suggestion de ville renvoyee a partir d'un code postal. */
|
|
||||||
export interface CitySuggestion {
|
export interface CitySuggestion {
|
||||||
city: string
|
city: string
|
||||||
postalCode: string
|
postalCode: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Une suggestion d'adresse complete (saisie assistee du champ « Adresse »). */
|
/** Une suggestion d'adresse complète (saisie assistée du champ « Adresse »). */
|
||||||
export interface AddressSuggestion {
|
export interface AddressSuggestion {
|
||||||
label: string
|
label: string
|
||||||
street: string
|
street: string
|
||||||
@@ -36,82 +34,27 @@ export interface AddressAutocomplete {
|
|||||||
searchAddress(query: string, postalCode?: string): Promise<AddressSuggestion[]>
|
searchAddress(query: string, postalCode?: string): Promise<AddressSuggestion[]>
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Erreur signalant que le service d'autocompletion BAN n'est pas disponible. */
|
/** Erreur signalant que le service d'autocomplétion BAN n'est pas disponible. */
|
||||||
export class AddressAutocompleteUnavailableError extends Error {
|
export class AddressAutocompleteUnavailableError extends Error {
|
||||||
constructor() {
|
constructor() {
|
||||||
// Message technique (non affiche tel quel) : le composant remonte son
|
// Message technique (non affiché tel quel) : le composant remonte son
|
||||||
// propre libelle i18n. Sert au debug / aux logs uniquement.
|
// propre libellé i18n. Sert au debug / aux logs uniquement.
|
||||||
super('Address autocomplete (BAN) is not available.')
|
super('Address autocomplete (BAN) is not available yet — ERP-66 stub.')
|
||||||
this.name = 'AddressAutocompleteUnavailableError'
|
this.name = 'AddressAutocompleteUnavailableError'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Proprietes d'une « feature » GeoJSON renvoyee par la BAN (champs utilises). */
|
/**
|
||||||
interface BanFeatureProperties {
|
* STUB : renvoie un composable conforme au contrat ERP-66 dont les méthodes
|
||||||
label?: string
|
* échouent toujours, forçant le mode dégradé côté onglet Adresse.
|
||||||
name?: string
|
*/
|
||||||
street?: string
|
|
||||||
postcode?: string
|
|
||||||
city?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Reponse GeoJSON FeatureCollection de la BAN. */
|
|
||||||
interface BanResponse {
|
|
||||||
features?: { properties?: BanFeatureProperties }[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useAddressAutocomplete(): AddressAutocomplete {
|
export function useAddressAutocomplete(): AddressAutocomplete {
|
||||||
return {
|
return {
|
||||||
async searchCity(postalCode: string): Promise<CitySuggestion[]> {
|
async searchCity(_postalCode: string): Promise<CitySuggestion[]> {
|
||||||
let res: BanResponse
|
throw new AddressAutocompleteUnavailableError()
|
||||||
try {
|
|
||||||
res = await httpExternal<BanResponse>(BAN_SEARCH_URL, {
|
|
||||||
query: { q: postalCode, type: 'municipality' },
|
|
||||||
})
|
|
||||||
} catch {
|
|
||||||
// Reseau coupe, 5xx, timeout... -> mode degrade cote composant.
|
|
||||||
throw new AddressAutocompleteUnavailableError()
|
|
||||||
}
|
|
||||||
|
|
||||||
return (res.features ?? []).map((feature) => {
|
|
||||||
const props = feature.properties ?? {}
|
|
||||||
return {
|
|
||||||
city: props.city ?? props.name ?? '',
|
|
||||||
postalCode: props.postcode ?? '',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
async searchAddress(_query: string, _postalCode?: string): Promise<AddressSuggestion[]> {
|
||||||
async searchAddress(query: string, postalCode?: string): Promise<AddressSuggestion[]> {
|
throw new AddressAutocompleteUnavailableError()
|
||||||
// IMPORTANT : pas de `type=housenumber` ici. La BAN ne renvoie un
|
|
||||||
// resultat de ce type qu'une fois un numero saisi → une recherche par
|
|
||||||
// nom de rue (« boulevard du port ») renverrait 0 resultat pendant
|
|
||||||
// toute la frappe. Sans filtre `type`, la BAN classe rues + numeros
|
|
||||||
// par pertinence (comportement d'autocompletion attendu).
|
|
||||||
// On n'ajoute `postcode` que s'il est fourni (sinon recherche large).
|
|
||||||
const banQuery: Record<string, string> = { q: query }
|
|
||||||
if (postalCode) {
|
|
||||||
banQuery.postcode = postalCode
|
|
||||||
}
|
|
||||||
|
|
||||||
let res: BanResponse
|
|
||||||
try {
|
|
||||||
res = await httpExternal<BanResponse>(BAN_SEARCH_URL, { query: banQuery })
|
|
||||||
} catch {
|
|
||||||
throw new AddressAutocompleteUnavailableError()
|
|
||||||
}
|
|
||||||
|
|
||||||
return (res.features ?? []).map((feature) => {
|
|
||||||
const props = feature.properties ?? {}
|
|
||||||
return {
|
|
||||||
label: props.label ?? '',
|
|
||||||
// `name` porte la ligne d'adresse complete (numero + voie) ;
|
|
||||||
// `street` ne contient que la voie. On privilegie `name`.
|
|
||||||
street: props.name ?? props.street ?? '',
|
|
||||||
postalCode: props.postcode ?? '',
|
|
||||||
city: props.city ?? '',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
||||||
import { httpExternal } from '../httpExternal'
|
|
||||||
|
|
||||||
// On mocke ofetch : httpExternal s'appuie sur $fetch sans jamais toucher le
|
|
||||||
// reseau pendant les tests. vi.mock est hoiste par Vitest au-dessus des imports.
|
|
||||||
const mockFetch = vi.hoisted(() => vi.fn())
|
|
||||||
vi.mock('ofetch', () => ({ $fetch: mockFetch }))
|
|
||||||
|
|
||||||
describe('httpExternal', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
mockFetch.mockReset()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('retourne le JSON parse renvoye par $fetch', async () => {
|
|
||||||
mockFetch.mockResolvedValueOnce({ ok: true })
|
|
||||||
|
|
||||||
const res = await httpExternal<{ ok: boolean }>('https://example.test/api')
|
|
||||||
|
|
||||||
expect(res).toEqual({ ok: true })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('transmet la query, coupe le cookie (credentials omit) et pose un timeout par defaut', async () => {
|
|
||||||
mockFetch.mockResolvedValueOnce([])
|
|
||||||
|
|
||||||
await httpExternal('https://example.test/search', {
|
|
||||||
query: { q: '80000', type: 'municipality' },
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(mockFetch).toHaveBeenCalledWith(
|
|
||||||
'https://example.test/search',
|
|
||||||
expect.objectContaining({
|
|
||||||
query: { q: '80000', type: 'municipality' },
|
|
||||||
credentials: 'omit',
|
|
||||||
retry: 0,
|
|
||||||
timeout: 5000,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('permet de surcharger le timeout', async () => {
|
|
||||||
mockFetch.mockResolvedValueOnce(null)
|
|
||||||
|
|
||||||
await httpExternal('https://example.test', { timeoutMs: 1000 })
|
|
||||||
|
|
||||||
expect(mockFetch).toHaveBeenCalledWith(
|
|
||||||
'https://example.test',
|
|
||||||
expect.objectContaining({ timeout: 1000 }),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('propage l\'erreur reseau / timeout (throw)', async () => {
|
|
||||||
mockFetch.mockRejectedValueOnce(new Error('network down'))
|
|
||||||
|
|
||||||
await expect(httpExternal('https://example.test')).rejects.toThrow('network down')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -20,27 +20,4 @@ describe('formatPhoneFR', () => {
|
|||||||
it('groupe par 2 meme un nombre impair de chiffres (dernier groupe seul)', () => {
|
it('groupe par 2 meme un nombre impair de chiffres (dernier groupe seul)', () => {
|
||||||
expect(formatPhoneFR('123')).toBe('12 3')
|
expect(formatPhoneFR('123')).toBe('12 3')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('formate une saisie courte (<= 4 chiffres) sans planter', () => {
|
|
||||||
expect(formatPhoneFR('1')).toBe('1')
|
|
||||||
expect(formatPhoneFR('12')).toBe('12')
|
|
||||||
expect(formatPhoneFR('1234')).toBe('12 34')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('strip les caracteres non numeriques (lettres, espaces, ponctuation)', () => {
|
|
||||||
expect(formatPhoneFR('abc')).toBe('')
|
|
||||||
expect(formatPhoneFR('Tel : 06.12')).toBe('06 12')
|
|
||||||
expect(formatPhoneFR(' 06 12 ')).toBe('06 12')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('conserve l\'indicatif international (+33) sans le transformer', () => {
|
|
||||||
// Comportement fige : on retire seulement le `+`, on ne deduit pas le
|
|
||||||
// prefixe pays. Le `+33...` est donc groupe brut par paquets de 2.
|
|
||||||
expect(formatPhoneFR('+33612345678')).toBe('33 61 23 45 67 8')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('groupe sans tronquer une saisie plus longue que 10 chiffres', () => {
|
|
||||||
// Aucune troncature silencieuse : on figure tous les chiffres groupes par 2.
|
|
||||||
expect(formatPhoneFR('061234567899')).toBe('06 12 34 56 78 99')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
import { $fetch } from 'ofetch'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Options d'un appel HTTP externe.
|
|
||||||
*/
|
|
||||||
export interface HttpExternalOptions {
|
|
||||||
/** Parametres de query string (encodes par ofetch). */
|
|
||||||
query?: Record<string, string | number | undefined>
|
|
||||||
/** Timeout en millisecondes avant abandon (defaut 5000). */
|
|
||||||
timeoutMs?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Petit client HTTP pour les APIs PUBLIQUES EXTERNES (domaine tiers, hors `/api`).
|
|
||||||
*
|
|
||||||
* Pourquoi un helper dedie plutot que `useApi()` : `useApi()` est le client de
|
|
||||||
* l'API interne Starseed (baseURL `/api`, cookie JWT `credentials: 'include'`,
|
|
||||||
* parsing/erreurs Hydra, redirection `/login` sur 401, toasts i18n). Tout cela
|
|
||||||
* est inadapte — voire indesirable — pour un endpoint public externe comme la
|
|
||||||
* Base Adresse Nationale (`api-adresse.data.gouv.fr`).
|
|
||||||
*
|
|
||||||
* Ce helper est donc le SEUL point d'entree autorise pour un `$fetch` brut vers
|
|
||||||
* l'externe (cf. regle frontend n°4 : pas de `$fetch` eparpille dans les
|
|
||||||
* composants). Il :
|
|
||||||
* - cible une URL absolue (pas de baseURL `/api`) ;
|
|
||||||
* - n'envoie PAS le cookie de session (`credentials: 'omit'`) ;
|
|
||||||
* - ne retente pas (`retry: 0`) et applique un timeout ;
|
|
||||||
* - laisse remonter l'erreur (throw) — au consommateur de gerer le mode degrade.
|
|
||||||
*/
|
|
||||||
export async function httpExternal<T>(
|
|
||||||
url: string,
|
|
||||||
opts: HttpExternalOptions = {},
|
|
||||||
): Promise<T> {
|
|
||||||
return $fetch<T>(url, {
|
|
||||||
query: opts.query,
|
|
||||||
credentials: 'omit',
|
|
||||||
retry: 0,
|
|
||||||
timeout: opts.timeoutMs ?? 5000,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -177,14 +177,12 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
|||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private Collection $contacts;
|
private Collection $contacts;
|
||||||
|
|
||||||
// Au moins une categorie est obligatoire sur une adresse (spec-front § Adresse).
|
|
||||||
// RG-1.29 : categories de code DISTRIBUTEUR/COURTIER interdites (validateCategoryCodes).
|
// RG-1.29 : categories de code DISTRIBUTEUR/COURTIER interdites (validateCategoryCodes).
|
||||||
/** @var Collection<int, CategoryInterface> */
|
/** @var Collection<int, CategoryInterface> */
|
||||||
#[ORM\ManyToMany(targetEntity: CategoryInterface::class)]
|
#[ORM\ManyToMany(targetEntity: CategoryInterface::class)]
|
||||||
#[ORM\JoinTable(name: 'client_address_category')]
|
#[ORM\JoinTable(name: 'client_address_category')]
|
||||||
#[ORM\JoinColumn(name: 'client_address_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
#[ORM\JoinColumn(name: 'client_address_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||||
#[ORM\InverseJoinColumn(name: 'category_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
#[ORM\InverseJoinColumn(name: 'category_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
||||||
#[Assert\Count(min: 1, minMessage: 'Au moins une catégorie est obligatoire.')]
|
|
||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private Collection $categories;
|
private Collection $categories;
|
||||||
|
|
||||||
|
|||||||
@@ -167,9 +167,8 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
public function testNonBillingAddressAcceptsEmptyBillingEmail(): void
|
public function testNonBillingAddressAcceptsEmptyBillingEmail(): void
|
||||||
{
|
{
|
||||||
$this->skipIfSitesModuleDisabled();
|
$this->skipIfSitesModuleDisabled();
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$seed = $this->seedClient('Non Billing Empty Email');
|
$seed = $this->seedClient('Non Billing Empty Email');
|
||||||
$category = $this->createCategory('SECTEUR');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
@@ -180,7 +179,6 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
'sites' => [$this->firstSiteIri()],
|
'sites' => [$this->firstSiteIri()],
|
||||||
'categories' => ['/api/categories/'.$category->getId()],
|
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -288,29 +286,6 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Spec-front § Adresse : au moins une categorie est obligatoire sur une
|
|
||||||
* adresse. POST sans categorie (mais avec site) -> 422.
|
|
||||||
*/
|
|
||||||
public function testAddressRequiresAtLeastOneCategory(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Address No Cat');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'postalCode' => '86100',
|
|
||||||
'city' => 'Châtellerault',
|
|
||||||
'street' => '1 rue du Test',
|
|
||||||
'sites' => [$this->firstSiteIri()],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne l'IRI du premier site seede (fixtures Sites).
|
* Retourne l'IRI du premier site seede (fixtures Sites).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -110,10 +110,9 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
public function testPostAddressNormalizesBillingEmail(): void
|
public function testPostAddressNormalizesBillingEmail(): void
|
||||||
{
|
{
|
||||||
$this->skipIfSitesModuleDisabled();
|
$this->skipIfSitesModuleDisabled();
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$seed = $this->seedClient('Address Host');
|
$seed = $this->seedClient('Address Host');
|
||||||
$siteIri = $this->firstSiteIri();
|
$siteIri = $this->firstSiteIri();
|
||||||
$category = $this->createCategory('SECTEUR');
|
|
||||||
|
|
||||||
$data = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
$data = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
@@ -124,7 +123,6 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
'sites' => [$siteIri],
|
'sites' => [$siteIri],
|
||||||
'categories' => ['/api/categories/'.$category->getId()],
|
|
||||||
],
|
],
|
||||||
])->toArray();
|
])->toArray();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user