Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
471a62ddb7 | ||
|
|
59afeb0a8d | ||
|
|
d2172eafdb | ||
|
|
d247867fa0 | ||
|
|
93912d1374 |
@@ -89,6 +89,9 @@
|
|||||||
"transform": {
|
"transform": {
|
||||||
"^.+\\.(t|j)s$": "ts-jest"
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
},
|
},
|
||||||
|
"moduleNameMapper": {
|
||||||
|
"^src/(.*)$": "<rootDir>/$1"
|
||||||
|
},
|
||||||
"collectCoverageFrom": [
|
"collectCoverageFrom": [
|
||||||
"**/*.(t|j)s"
|
"**/*.(t|j)s"
|
||||||
],
|
],
|
||||||
|
|||||||
+51
-2
@@ -1,20 +1,69 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { AssistantesMaternellesController } from './assistantes_maternelles.controller';
|
import { AssistantesMaternellesController } from './assistantes_maternelles.controller';
|
||||||
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
||||||
|
import { AuthService } from '../auth/auth.service';
|
||||||
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||||
|
import { RolesGuard } from 'src/common/guards/roles.guard';
|
||||||
|
|
||||||
describe('AssistantesMaternellesController', () => {
|
describe('AssistantesMaternellesController', () => {
|
||||||
let controller: AssistantesMaternellesController;
|
let controller: AssistantesMaternellesController;
|
||||||
|
const authServiceMock = {
|
||||||
|
createAmDossierStaff: jest.fn(),
|
||||||
|
};
|
||||||
|
const amServiceMock = {};
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
controllers: [AssistantesMaternellesController],
|
controllers: [AssistantesMaternellesController],
|
||||||
providers: [AssistantesMaternellesService],
|
providers: [
|
||||||
}).compile();
|
{ provide: AssistantesMaternellesService, useValue: amServiceMock },
|
||||||
|
{ provide: AuthService, useValue: authServiceMock },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.overrideGuard(AuthGuard)
|
||||||
|
.useValue({ canActivate: () => true })
|
||||||
|
.overrideGuard(RolesGuard)
|
||||||
|
.useValue({ canActivate: () => true })
|
||||||
|
.compile();
|
||||||
|
|
||||||
controller = module.get<AssistantesMaternellesController>(AssistantesMaternellesController);
|
controller = module.get<AssistantesMaternellesController>(AssistantesMaternellesController);
|
||||||
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
expect(controller).toBeDefined();
|
expect(controller).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('createDossier delegates to authService.createAmDossierStaff with CGU accepted', async () => {
|
||||||
|
authServiceMock.createAmDossierStaff.mockResolvedValue({
|
||||||
|
message: 'ok',
|
||||||
|
user_id: 'u1',
|
||||||
|
statut: 'actif',
|
||||||
|
numero_dossier: '2026-000001',
|
||||||
|
});
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
email: 'am.staff@test.fr',
|
||||||
|
prenom: 'Marie',
|
||||||
|
nom: 'TEST',
|
||||||
|
telephone: '0689567890',
|
||||||
|
consentement_photo: false,
|
||||||
|
lieu_naissance_ville: 'Paris',
|
||||||
|
lieu_naissance_pays: 'France',
|
||||||
|
nir: '285017512345678',
|
||||||
|
numero_agrement: 'AGR-TEST-001',
|
||||||
|
capacite_accueil: 3,
|
||||||
|
places_disponibles: 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
const res = await controller.createDossier(body as any);
|
||||||
|
expect(authServiceMock.createAmDossierStaff).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
email: body.email,
|
||||||
|
acceptation_cgu: true,
|
||||||
|
acceptation_privacy: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(res.numero_dossier).toBe('2026-000001');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import {
|
|||||||
Param,
|
Param,
|
||||||
Delete,
|
Delete,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
|
HttpCode,
|
||||||
|
HttpStatus,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
||||||
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
@@ -16,17 +18,49 @@ import { RoleType, Users } from 'src/entities/users.entity';
|
|||||||
import { CreateAssistanteDto } from '../user/dto/create_assistante.dto';
|
import { CreateAssistanteDto } from '../user/dto/create_assistante.dto';
|
||||||
import { UpdateAssistanteDto } from '../user/dto/update_assistante.dto';
|
import { UpdateAssistanteDto } from '../user/dto/update_assistante.dto';
|
||||||
import { UpdateAmFicheAdminDto } from './dto/update-am-fiche-admin.dto';
|
import { UpdateAmFicheAdminDto } from './dto/update-am-fiche-admin.dto';
|
||||||
|
import { StaffCreateAmDossierDto } from './dto/staff-create-am-dossier.dto';
|
||||||
|
import { StaffCreateAmDossierResponseDto } from './dto/staff-create-am-dossier-response.dto';
|
||||||
import { RolesGuard } from 'src/common/guards/roles.guard';
|
import { RolesGuard } from 'src/common/guards/roles.guard';
|
||||||
import { AuthGuard } from 'src/common/guards/auth.guard';
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||||
import { User } from 'src/common/decorators/user.decorator';
|
import { User } from 'src/common/decorators/user.decorator';
|
||||||
import { mapAmForApi, mapAmsForApi } from './assistantes_maternelles.mapper';
|
import { mapAmForApi, mapAmsForApi } from './assistantes_maternelles.mapper';
|
||||||
|
import { AuthService } from '../auth/auth.service';
|
||||||
|
import { RegisterAMCompletDto } from '../auth/dto/register-am-complet.dto';
|
||||||
|
|
||||||
@ApiTags("Assistantes Maternelles")
|
@ApiTags("Assistantes Maternelles")
|
||||||
@ApiBearerAuth('access-token')
|
@ApiBearerAuth('access-token')
|
||||||
@UseGuards(AuthGuard, RolesGuard)
|
@UseGuards(AuthGuard, RolesGuard)
|
||||||
@Controller('assistantes-maternelles')
|
@Controller('assistantes-maternelles')
|
||||||
export class AssistantesMaternellesController {
|
export class AssistantesMaternellesController {
|
||||||
constructor(private readonly assistantesMaternellesService: AssistantesMaternellesService) { }
|
constructor(
|
||||||
|
private readonly assistantesMaternellesService: AssistantesMaternellesService,
|
||||||
|
private readonly authService: AuthService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE, RoleType.ADMINISTRATEUR)
|
||||||
|
@Post('dossier')
|
||||||
|
@HttpCode(HttpStatus.CREATED)
|
||||||
|
@ApiOperation({
|
||||||
|
summary: 'Créer un dossier AM complet (staff) — ticket #156',
|
||||||
|
description:
|
||||||
|
'Crée user + fiche AM avec statut actif, n° dossier, et envoie l’e-mail de création de mot de passe. ' +
|
||||||
|
'Ne pas utiliser POST /auth/register/am depuis le dashboard.',
|
||||||
|
})
|
||||||
|
@ApiBody({ type: StaffCreateAmDossierDto })
|
||||||
|
@ApiResponse({ status: 201, type: StaffCreateAmDossierResponseDto })
|
||||||
|
@ApiResponse({ status: 400, description: 'Validation métier / NIR' })
|
||||||
|
@ApiResponse({ status: 403, description: 'Rôle non autorisé' })
|
||||||
|
@ApiResponse({ status: 409, description: 'Email / NIR / agrément déjà pris' })
|
||||||
|
async createDossier(
|
||||||
|
@Body() dto: StaffCreateAmDossierDto,
|
||||||
|
): Promise<StaffCreateAmDossierResponseDto> {
|
||||||
|
const registerDto = {
|
||||||
|
...dto,
|
||||||
|
acceptation_cgu: true,
|
||||||
|
acceptation_privacy: true,
|
||||||
|
} as RegisterAMCompletDto;
|
||||||
|
return this.authService.createAmDossierStaff(registerDto);
|
||||||
|
}
|
||||||
|
|
||||||
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
@Roles(RoleType.SUPER_ADMIN, RoleType.GESTIONNAIRE)
|
||||||
@ApiOperation({ summary: 'Créer nounou' })
|
@ApiOperation({ summary: 'Créer nounou' })
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { StatutUtilisateurType } from 'src/entities/users.entity';
|
||||||
|
|
||||||
|
/** Réponse 201 POST /assistantes-maternelles/dossier (#156). */
|
||||||
|
export class StaffCreateAmDossierResponseDto {
|
||||||
|
@ApiProperty()
|
||||||
|
message: string;
|
||||||
|
|
||||||
|
@ApiProperty({ format: 'uuid' })
|
||||||
|
user_id: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
enum: StatutUtilisateurType,
|
||||||
|
example: StatutUtilisateurType.ACTIF,
|
||||||
|
})
|
||||||
|
statut: StatutUtilisateurType;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
example: '2026-000042',
|
||||||
|
description: 'Numéro de dossier attribué',
|
||||||
|
})
|
||||||
|
numero_dossier: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { ApiPropertyOptional, OmitType } from '@nestjs/swagger';
|
||||||
|
import { IsBoolean, IsOptional } from 'class-validator';
|
||||||
|
import { RegisterAMCompletDto } from 'src/routes/auth/dto/register-am-complet.dto';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Création dossier AM par staff (#156).
|
||||||
|
* Mêmes champs que l'inscription publique, sans CGU/privacy obligatoires
|
||||||
|
* (acceptées côté serveur pour le compte du gestionnaire).
|
||||||
|
*/
|
||||||
|
export class StaffCreateAmDossierDto extends OmitType(RegisterAMCompletDto, [
|
||||||
|
'acceptation_cgu',
|
||||||
|
'acceptation_privacy',
|
||||||
|
] as const) {
|
||||||
|
@ApiPropertyOptional({
|
||||||
|
description: 'Ignoré côté staff (CGU acceptées serveur). Conservé pour compat éventuelle.',
|
||||||
|
default: true,
|
||||||
|
})
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
acceptation_cgu?: boolean;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({
|
||||||
|
description: 'Ignoré côté staff (privacy acceptée serveur).',
|
||||||
|
default: true,
|
||||||
|
})
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
acceptation_privacy?: boolean;
|
||||||
|
}
|
||||||
@@ -645,11 +645,28 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inscription Assistante Maternelle COMPLÈTE - Un seul endpoint (identité + pro + photo + CGU)
|
* Cœur partagé création dossier AM (#156).
|
||||||
* Crée User (role AM) + entrée assistantes_maternelles, token création MDP
|
* - public : statut en_attente + mail pending
|
||||||
|
* - staff : statut actif + mail création MDP
|
||||||
*/
|
*/
|
||||||
async inscrireAMComplet(dto: RegisterAMCompletDto) {
|
async createAmDossier(
|
||||||
if (!dto.acceptation_cgu || !dto.acceptation_privacy) {
|
dto: RegisterAMCompletDto,
|
||||||
|
options: {
|
||||||
|
statut: StatutUtilisateurType;
|
||||||
|
sendPendingEmail: boolean;
|
||||||
|
sendPasswordSetupEmail: boolean;
|
||||||
|
requireCgu: boolean;
|
||||||
|
logContext?: string;
|
||||||
|
},
|
||||||
|
): Promise<{
|
||||||
|
message: string;
|
||||||
|
user_id: string;
|
||||||
|
statut: StatutUtilisateurType;
|
||||||
|
numero_dossier: string;
|
||||||
|
}> {
|
||||||
|
const logCtx = options.logContext ?? 'createAmDossier';
|
||||||
|
|
||||||
|
if (options.requireCgu && (!dto.acceptation_cgu || !dto.acceptation_privacy)) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
"L'acceptation des CGU et de la politique de confidentialité est obligatoire",
|
"L'acceptation des CGU et de la politique de confidentialité est obligatoire",
|
||||||
);
|
);
|
||||||
@@ -669,8 +686,7 @@ export class AuthService {
|
|||||||
throw new BadRequestException(nirValidation.error || 'NIR invalide');
|
throw new BadRequestException(nirValidation.error || 'NIR invalide');
|
||||||
}
|
}
|
||||||
if (nirValidation.warning) {
|
if (nirValidation.warning) {
|
||||||
// Warning uniquement : on ne bloque pas (AM souvent étrangères, DOM-TOM, Corse)
|
console.warn(`[${logCtx}] NIR warning:`, nirValidation.warning, 'email=', dto.email);
|
||||||
console.warn('[inscrireAMComplet] NIR warning:', nirValidation.warning, 'email=', dto.email);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const existe = await this.usersService.findByEmailOrNull(dto.email);
|
const existe = await this.usersService.findByEmailOrNull(dto.email);
|
||||||
@@ -721,14 +737,15 @@ export class AuthService {
|
|||||||
let resultat: { user: Users };
|
let resultat: { user: Users };
|
||||||
try {
|
try {
|
||||||
resultat = await this.usersRepo.manager.transaction(async (manager) => {
|
resultat = await this.usersRepo.manager.transaction(async (manager) => {
|
||||||
const { numero: numeroDossier } = await this.numeroDossierService.getNextNumeroDossier(manager);
|
const { numero: numeroDossier } =
|
||||||
|
await this.numeroDossierService.getNextNumeroDossier(manager);
|
||||||
|
|
||||||
const user = manager.create(Users, {
|
const user = manager.create(Users, {
|
||||||
email: dto.email,
|
email: dto.email,
|
||||||
prenom: dto.prenom,
|
prenom: dto.prenom,
|
||||||
nom: dto.nom,
|
nom: dto.nom,
|
||||||
role: RoleType.ASSISTANTE_MATERNELLE,
|
role: RoleType.ASSISTANTE_MATERNELLE,
|
||||||
statut: StatutUtilisateurType.EN_ATTENTE,
|
statut: options.statut,
|
||||||
telephone: dto.telephone,
|
telephone: dto.telephone,
|
||||||
adresse: dto.adresse,
|
adresse: dto.adresse,
|
||||||
code_postal: dto.code_postal,
|
code_postal: dto.code_postal,
|
||||||
@@ -738,7 +755,9 @@ export class AuthService {
|
|||||||
photo_url: urlPhoto ?? undefined,
|
photo_url: urlPhoto ?? undefined,
|
||||||
consentement_photo: dto.consentement_photo,
|
consentement_photo: dto.consentement_photo,
|
||||||
date_consentement_photo: dateConsentementPhoto,
|
date_consentement_photo: dateConsentementPhoto,
|
||||||
date_naissance: dto.date_naissance ? new Date(dto.date_naissance) : undefined,
|
date_naissance: dto.date_naissance
|
||||||
|
? new Date(dto.date_naissance)
|
||||||
|
: undefined,
|
||||||
lieu_naissance_ville: dto.lieu_naissance_ville,
|
lieu_naissance_ville: dto.lieu_naissance_ville,
|
||||||
lieu_naissance_pays: dto.lieu_naissance_pays,
|
lieu_naissance_pays: dto.lieu_naissance_pays,
|
||||||
numero_dossier: numeroDossier,
|
numero_dossier: numeroDossier,
|
||||||
@@ -754,7 +773,9 @@ export class AuthService {
|
|||||||
places_available: dto.places_disponibles,
|
places_available: dto.places_disponibles,
|
||||||
biography: dto.biographie,
|
biography: dto.biographie,
|
||||||
residence_city: dto.ville ?? undefined,
|
residence_city: dto.ville ?? undefined,
|
||||||
agreement_date: dto.date_agrement ? new Date(dto.date_agrement) : undefined,
|
agreement_date: dto.date_agrement
|
||||||
|
? new Date(dto.date_agrement)
|
||||||
|
: undefined,
|
||||||
available: true,
|
available: true,
|
||||||
numero_dossier: numeroDossier,
|
numero_dossier: numeroDossier,
|
||||||
});
|
});
|
||||||
@@ -764,13 +785,16 @@ export class AuthService {
|
|||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (this.isPostgresUniqueViolation(err)) {
|
if (this.isPostgresUniqueViolation(err)) {
|
||||||
throw new ConflictException('Un compte avec cet email existe déjà (contrainte unique en base).');
|
throw new ConflictException(
|
||||||
|
'Un compte avec cet email existe déjà (contrainte unique en base).',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
const numeroDossier = resultat.user.numero_dossier ?? '';
|
const numeroDossier = resultat.user.numero_dossier ?? '';
|
||||||
|
|
||||||
|
if (options.sendPendingEmail) {
|
||||||
try {
|
try {
|
||||||
await this.mailService.sendRegistrationPendingEmail(
|
await this.mailService.sendRegistrationPendingEmail(
|
||||||
resultat.user.email,
|
resultat.user.email,
|
||||||
@@ -780,20 +804,75 @@ export class AuthService {
|
|||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
"[inscrireAMComplet] Échec envoi email d'accusé de réception (inscription conservée)",
|
`[${logCtx}] Échec envoi email d'accusé de réception (inscription conservée)`,
|
||||||
err instanceof Error ? err.stack : String(err),
|
err instanceof Error ? err.stack : String(err),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.sendPasswordSetupEmail) {
|
||||||
|
try {
|
||||||
|
await this.mailService.sendValidatedAccountPasswordSetupEmail(
|
||||||
|
{
|
||||||
|
email: resultat.user.email,
|
||||||
|
prenom: resultat.user.prenom ?? '',
|
||||||
|
nom: resultat.user.nom ?? '',
|
||||||
|
token: tokenCreationMdp,
|
||||||
|
numeroDossier,
|
||||||
|
},
|
||||||
|
'am',
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error(
|
||||||
|
`[${logCtx}] Échec envoi email création MDP (dossier conservé)`,
|
||||||
|
err instanceof Error ? err.stack : String(err),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const message =
|
||||||
|
options.statut === StatutUtilisateurType.ACTIF
|
||||||
|
? 'Dossier AM créé et validé. Un e-mail de création de mot de passe a été envoyé.'
|
||||||
|
: 'Inscription réussie. Votre dossier est en attente de validation par un gestionnaire.';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message:
|
message,
|
||||||
'Inscription réussie. Votre dossier est en attente de validation par un gestionnaire.',
|
|
||||||
user_id: resultat.user.id,
|
user_id: resultat.user.id,
|
||||||
statut: StatutUtilisateurType.EN_ATTENTE,
|
statut: options.statut,
|
||||||
numero_dossier: numeroDossier,
|
numero_dossier: numeroDossier,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inscription Assistante Maternelle COMPLÈTE - Un seul endpoint (identité + pro + photo + CGU)
|
||||||
|
* Crée User (role AM) + entrée assistantes_maternelles, token création MDP
|
||||||
|
*/
|
||||||
|
async inscrireAMComplet(dto: RegisterAMCompletDto) {
|
||||||
|
return this.createAmDossier(dto, {
|
||||||
|
statut: StatutUtilisateurType.EN_ATTENTE,
|
||||||
|
sendPendingEmail: true,
|
||||||
|
sendPasswordSetupEmail: false,
|
||||||
|
requireCgu: true,
|
||||||
|
logContext: 'inscrireAMComplet',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Création dossier AM par staff (#156) — statut actif + e-mail création MDP.
|
||||||
|
*/
|
||||||
|
async createAmDossierStaff(dto: RegisterAMCompletDto) {
|
||||||
|
return this.createAmDossier(dto, {
|
||||||
|
statut: StatutUtilisateurType.ACTIF,
|
||||||
|
sendPendingEmail: false,
|
||||||
|
sendPasswordSetupEmail: true,
|
||||||
|
requireCgu: false,
|
||||||
|
logContext: 'createAmDossierStaff',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sauvegarde une photo depuis base64 vers le système de fichiers
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* Sauvegarde une photo depuis base64 vers le système de fichiers
|
* Sauvegarde une photo depuis base64 vers le système de fichiers
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -114,36 +114,86 @@ export class ParentsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rattacher un enfant existant à un parent (enfants_parents). Ticket #115 / doc 28 §6.2.
|
* Membres du foyer (user ids) pour affiliation enfant.
|
||||||
|
* Pivot + co-parent (A→B et B→A) + même numero_dossier. Ticket #158.
|
||||||
*/
|
*/
|
||||||
async attachEnfant(parentUserId: string, enfantId: string): Promise<Parents> {
|
private async resolveFoyerParentUserIds(parent: Parents): Promise<string[]> {
|
||||||
await this.findOne(parentUserId);
|
const ids = new Set<string>([parent.user_id]);
|
||||||
|
|
||||||
const existing = await this.parentsChildrenRepository.findOne({
|
if (parent.co_parent?.id) {
|
||||||
where: { parentId: parentUserId, enfantId },
|
ids.add(parent.co_parent.id);
|
||||||
});
|
|
||||||
if (existing) {
|
|
||||||
throw new ConflictException('Cet enfant est déjà rattaché à ce parent');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const child = await this.parentsRepository.manager.findOne(Children, { where: { id: enfantId } });
|
// Sens inverse : parents qui déclarent ce user comme co-parent
|
||||||
|
const reverseLinks = await this.parentsRepository.find({
|
||||||
|
where: { co_parent: { id: parent.user_id } },
|
||||||
|
relations: ['co_parent'],
|
||||||
|
});
|
||||||
|
for (const p of reverseLinks) {
|
||||||
|
ids.add(p.user_id);
|
||||||
|
if (p.co_parent?.id) ids.add(p.co_parent.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dossier = parent.numero_dossier?.trim();
|
||||||
|
if (dossier) {
|
||||||
|
const sameDossier = await this.parentsRepository.find({
|
||||||
|
where: { numero_dossier: dossier },
|
||||||
|
relations: ['co_parent'],
|
||||||
|
});
|
||||||
|
for (const p of sameDossier) {
|
||||||
|
ids.add(p.user_id);
|
||||||
|
if (p.co_parent?.id) ids.add(p.co_parent.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...ids];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rattacher un enfant au foyer du parent (tous les responsables). Ticket #158.
|
||||||
|
* Un seul POST suffit : liens créés pour pivot + co-parent / même dossier.
|
||||||
|
*/
|
||||||
|
async attachEnfant(parentUserId: string, enfantId: string): Promise<Parents> {
|
||||||
|
const parent = await this.findOne(parentUserId);
|
||||||
|
|
||||||
|
const child = await this.parentsRepository.manager.findOne(Children, {
|
||||||
|
where: { id: enfantId },
|
||||||
|
});
|
||||||
if (!child) {
|
if (!child) {
|
||||||
throw new NotFoundException('Enfant introuvable');
|
throw new NotFoundException('Enfant introuvable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const foyerIds = await this.resolveFoyerParentUserIds(parent);
|
||||||
|
let created = 0;
|
||||||
|
|
||||||
|
for (const memberId of foyerIds) {
|
||||||
|
const existing = await this.parentsChildrenRepository.findOne({
|
||||||
|
where: { parentId: memberId, enfantId },
|
||||||
|
});
|
||||||
|
if (existing) continue;
|
||||||
|
|
||||||
await this.parentsChildrenRepository.save(
|
await this.parentsChildrenRepository.save(
|
||||||
this.parentsChildrenRepository.create({ parentId: parentUserId, enfantId }),
|
this.parentsChildrenRepository.create({
|
||||||
|
parentId: memberId,
|
||||||
|
enfantId,
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
created += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (created === 0) {
|
||||||
|
throw new ConflictException('Cet enfant est déjà rattaché à ce foyer');
|
||||||
|
}
|
||||||
|
|
||||||
return this.findOne(parentUserId);
|
return this.findOne(parentUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Détacher un enfant d'un parent sans supprimer l'enfant.
|
* Détacher un enfant du foyer du parent (tous les responsables). Ticket #158.
|
||||||
* Autorise le détachement du dernier responsable (#157) — l'enfant reste listé
|
* Si plus aucun lien ensuite → enfant orphelin (#157).
|
||||||
* via GET /enfants avec parentLinks vides (alerte front).
|
|
||||||
*/
|
*/
|
||||||
async detachEnfant(parentUserId: string, enfantId: string): Promise<Parents> {
|
async detachEnfant(parentUserId: string, enfantId: string): Promise<Parents> {
|
||||||
await this.findOne(parentUserId);
|
const parent = await this.findOne(parentUserId);
|
||||||
|
|
||||||
const link = await this.parentsChildrenRepository.findOne({
|
const link = await this.parentsChildrenRepository.findOne({
|
||||||
where: { parentId: parentUserId, enfantId },
|
where: { parentId: parentUserId, enfantId },
|
||||||
@@ -152,7 +202,12 @@ export class ParentsService {
|
|||||||
throw new NotFoundException('Lien parent-enfant introuvable');
|
throw new NotFoundException('Lien parent-enfant introuvable');
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.parentsChildrenRepository.delete({ parentId: parentUserId, enfantId });
|
const foyerIds = await this.resolveFoyerParentUserIds(parent);
|
||||||
|
await this.parentsChildrenRepository.delete({
|
||||||
|
parentId: In(foyerIds),
|
||||||
|
enfantId,
|
||||||
|
});
|
||||||
|
|
||||||
return this.findOne(parentUserId);
|
return this.findOne(parentUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
# Analyse d’empreinte — P'titsPas
|
||||||
|
|
||||||
|
**Date :** 2026-07-22
|
||||||
|
**Contexte :** snapshot pour mémoire (après alerte disque plein + purge cache Gitea)
|
||||||
|
**Périmètre :** application `jmartin/petitspas` déployée sur le VPS (`/home/deploy/dev/ptitspas-app`)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Lignes de code
|
||||||
|
|
||||||
|
Comptage brut (`wc -l`), hors `node_modules` / builds / `.dart_tool`.
|
||||||
|
|
||||||
|
| Zone | Lignes | Fichiers |
|
||||||
|
|------|--------|----------|
|
||||||
|
| **Frontend** (Dart `frontend/lib/`) | ~29 800 | 141 |
|
||||||
|
| **Backend** (TypeScript `backend/src/`) | ~10 000 | 141 |
|
||||||
|
| **BDD** (SQL sous `database/`) | ~1 250 | ~15 |
|
||||||
|
| **Total** | **~41 000** | |
|
||||||
|
|
||||||
|
### Frontend (détail)
|
||||||
|
|
||||||
|
| Dossier | Lignes |
|
||||||
|
|---------|--------|
|
||||||
|
| `widgets/` | ~18 400 |
|
||||||
|
| `screens/` | ~5 000 |
|
||||||
|
| `services/` | ~2 300 |
|
||||||
|
| `models/` | ~2 200 |
|
||||||
|
| `utils/` | ~1 400 |
|
||||||
|
| reste | ~500 |
|
||||||
|
|
||||||
|
### Backend (détail)
|
||||||
|
|
||||||
|
| Dossier | Lignes |
|
||||||
|
|---------|--------|
|
||||||
|
| `routes/` | ~6 500 |
|
||||||
|
| `modules/` | ~1 700 |
|
||||||
|
| `entities/` | ~1 000 |
|
||||||
|
| `common/` + `config/` | ~400 |
|
||||||
|
|
||||||
|
### BDD (détail)
|
||||||
|
|
||||||
|
| Élément | Lignes |
|
||||||
|
|---------|--------|
|
||||||
|
| `BDD.sql` (schéma) | ~470 |
|
||||||
|
| seeds | ~300 |
|
||||||
|
| migrations / patches | ~280 |
|
||||||
|
| tests SQL | ~205 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Empreinte disque — runtime (Docker)
|
||||||
|
|
||||||
|
| Composant | Taille | Notes |
|
||||||
|
|-----------|--------|--------|
|
||||||
|
| Image `ptitspas-app-backend` | ~300 Mo | NestJS |
|
||||||
|
| Image `ptitspas-app-frontend` | ~122 Mo | Flutter web + Nginx |
|
||||||
|
| Image `postgres:17` | ~454 Mo | |
|
||||||
|
| Image `dpage/pgadmin4` | ~534 Mo | optionnel |
|
||||||
|
| Volume `postgres_data` | ~49 Mo | données BDD live |
|
||||||
|
| Volume `backend_uploads` | ~20 Mo | photos |
|
||||||
|
| Volume `backend_documents_legaux` | ~0 | |
|
||||||
|
| **Stack complète (avec pgAdmin)** | **~1,5 Go** | |
|
||||||
|
| **Stack prod sans pgAdmin** | **~945 Mo** | |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Empreinte disque — code source
|
||||||
|
|
||||||
|
| Élément | Taille |
|
||||||
|
|---------|--------|
|
||||||
|
| Clone `/home/deploy/dev/ptitspas-app` | ~701 Mo |
|
||||||
|
| dont `backend/node_modules` | ~354 Mo |
|
||||||
|
| dont `frontend` (+ `.dart_tool`) | ~114 Mo |
|
||||||
|
| **Code utile** (hors deps / `.git` / builds) | **~51 Mo** |
|
||||||
|
| Repo Gitea `petitspas.git` | ~109 Mo |
|
||||||
|
| Dump `database/BDD.sql` | ~19 Ko |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Pour (re)déployer
|
||||||
|
|
||||||
|
Minimum requis :
|
||||||
|
|
||||||
|
1. Images custom backend + frontend (~422 Mo), ou code + build Docker
|
||||||
|
2. Image `postgres:17` (~454 Mo)
|
||||||
|
3. Volumes persistants (~70 Mo au snapshot)
|
||||||
|
4. Optionnel : pgAdmin (~534 Mo)
|
||||||
|
|
||||||
|
**Ordre de grandeur :** ~1 Go pour faire tourner l’app en prod (sans pgAdmin).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Notes infra du jour (lié)
|
||||||
|
|
||||||
|
- Disque VPS passé de **100 %** à ~**44 %** après :
|
||||||
|
- purge cache Docker / journals
|
||||||
|
- purge officielle Gitea `delete_repo_archives` (~24 Go de zip/bundle `petitspas`)
|
||||||
|
- Crons Gitea activés :
|
||||||
|
- `archive_cleanup` @midnight (`OLDER_THAN = 24h`)
|
||||||
|
- `delete_repo_archives` @weekly
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*Fichier généré pour historique projet — ne pas considérer comme métrique CI automatisée.*
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
# Mini-spec API — POST /assistantes-maternelles/dossier (#156)
|
||||||
|
|
||||||
|
Contrat pour le **plan front** (wizard création AM staff).
|
||||||
|
|
||||||
|
## Endpoint
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|--|--|
|
||||||
|
| **Méthode** | `POST` |
|
||||||
|
| **URL** | `{base}/assistantes-maternelles/dossier` |
|
||||||
|
| **Auth** | Bearer JWT |
|
||||||
|
| **Rôles** | `gestionnaire`, `administrateur`, `super_admin` |
|
||||||
|
| **Content-Type** | `application/json` |
|
||||||
|
|
||||||
|
Ne **pas** appeler `POST /auth/register/am` depuis le dashboard.
|
||||||
|
|
||||||
|
## Body (JSON)
|
||||||
|
|
||||||
|
Aligné inscription AM publique, **sans** CGU/privacy obligatoires (acceptées serveur).
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Notes |
|
||||||
|
|-------|------|-------------|--------|
|
||||||
|
| `email` | string | oui | unique |
|
||||||
|
| `prenom` | string | oui | |
|
||||||
|
| `nom` | string | oui | |
|
||||||
|
| `telephone` | string | oui | `0X…` ou `+33…` |
|
||||||
|
| `adresse` | string | non | |
|
||||||
|
| `code_postal` | string | non | |
|
||||||
|
| `ville` | string | non | |
|
||||||
|
| `photo_base64` | string | non | data-URL `data:image/…;base64,…` |
|
||||||
|
| `photo_filename` | string | non | hint nom fichier |
|
||||||
|
| `consentement_photo` | bool | oui | |
|
||||||
|
| `date_naissance` | date ISO | non | `YYYY-MM-DD` |
|
||||||
|
| `lieu_naissance_ville` | string | oui | |
|
||||||
|
| `lieu_naissance_pays` | string | oui | |
|
||||||
|
| `nir` | string | oui | 15 car. (Corse 2A/2B OK) |
|
||||||
|
| `numero_agrement` | string | oui | unique |
|
||||||
|
| `date_agrement` | date ISO | non | |
|
||||||
|
| `capacite_accueil` | int | oui | 1–10 |
|
||||||
|
| `places_disponibles` | int | oui | 0–10, ≤ capacité |
|
||||||
|
| `biographie` | string | non | max 2000 |
|
||||||
|
|
||||||
|
## Réponses
|
||||||
|
|
||||||
|
### 201 Created
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Dossier AM créé et validé. Un e-mail de création de mot de passe a été envoyé.",
|
||||||
|
"user_id": "uuid",
|
||||||
|
"statut": "actif",
|
||||||
|
"numero_dossier": "2026-000042"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Effets serveur : user AM **actif**, fiche `assistantes_maternelles`, n° dossier, **e-mail création MDP** (pas d’accusé « en attente »).
|
||||||
|
|
||||||
|
### Erreurs
|
||||||
|
|
||||||
|
| Code | Cas |
|
||||||
|
|------|-----|
|
||||||
|
| 400 | Validation / NIR / places > capacité |
|
||||||
|
| 403 | Rôle non staff |
|
||||||
|
| 409 | Email, NIR ou agrément déjà pris |
|
||||||
|
| 401 | Token manquant / invalide |
|
||||||
|
|
||||||
|
## Front
|
||||||
|
|
||||||
|
- `UserService.createAmDossier(body)` → cet endpoint
|
||||||
|
- Après 201 : refresh liste AM ; snackbar OK
|
||||||
|
- Wizard create : ne pas envoyer `acceptation_cgu` / `acceptation_privacy` (optionnels)
|
||||||
|
|
||||||
|
## Branche
|
||||||
|
|
||||||
|
`feature/156-creation-dossier-am`
|
||||||
@@ -61,6 +61,9 @@ class ApiConfig {
|
|||||||
static const String gestionnaires = '/gestionnaires';
|
static const String gestionnaires = '/gestionnaires';
|
||||||
static const String parents = '/parents';
|
static const String parents = '/parents';
|
||||||
static const String assistantesMaternelles = '/assistantes-maternelles';
|
static const String assistantesMaternelles = '/assistantes-maternelles';
|
||||||
|
/// Création dossier AM actif par le staff (#156) — body type register AM.
|
||||||
|
static const String assistantesMaternellesDossier =
|
||||||
|
'/assistantes-maternelles/dossier';
|
||||||
static const String enfants = '/enfants';
|
static const String enfants = '/enfants';
|
||||||
static const String relais = '/relais';
|
static const String relais = '/relais';
|
||||||
static const String dossiers = '/dossiers';
|
static const String dossiers = '/dossiers';
|
||||||
|
|||||||
@@ -645,6 +645,56 @@ class UserService {
|
|||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Création dossier AM actif côté staff (#156).
|
||||||
|
/// `POST /assistantes-maternelles/dossier` — body aligné sur register AM.
|
||||||
|
/// Succès 201 : dossier actif + `numero_dossier` (mail MDP côté serveur).
|
||||||
|
/// Ne pas utiliser `POST /auth/register/am` (public / en_attente).
|
||||||
|
static Future<Map<String, dynamic>> createAmDossier(
|
||||||
|
Map<String, dynamic> body,
|
||||||
|
) async {
|
||||||
|
final http.Response response;
|
||||||
|
try {
|
||||||
|
response = await http.post(
|
||||||
|
Uri.parse(
|
||||||
|
'${ApiConfig.baseUrl}${ApiConfig.assistantesMaternellesDossier}',
|
||||||
|
),
|
||||||
|
headers: await _headers(),
|
||||||
|
body: jsonEncode(body),
|
||||||
|
);
|
||||||
|
} on http.ClientException {
|
||||||
|
throw Exception(
|
||||||
|
'Connexion au serveur impossible. Vérifiez votre réseau puis réessayez.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
|
if (response.body.trim().isEmpty) return <String, dynamic>{};
|
||||||
|
try {
|
||||||
|
final decoded = jsonDecode(response.body);
|
||||||
|
if (decoded is Map) {
|
||||||
|
return Map<String, dynamic>.from(decoded);
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
return <String, dynamic>{};
|
||||||
|
}
|
||||||
|
|
||||||
|
final message = _extractErrorMessage(
|
||||||
|
response.body,
|
||||||
|
'Erreur création dossier AM',
|
||||||
|
);
|
||||||
|
if (response.statusCode == 409) {
|
||||||
|
throw Exception(message.isNotEmpty
|
||||||
|
? message
|
||||||
|
: 'Conflit : e-mail, NIR ou agrément déjà utilisé.');
|
||||||
|
}
|
||||||
|
if (response.statusCode == 400) {
|
||||||
|
throw Exception(
|
||||||
|
message.isNotEmpty ? message : 'Données invalides (400).',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw Exception(message);
|
||||||
|
}
|
||||||
|
|
||||||
// Récupérer la liste des assistantes maternelles
|
// Récupérer la liste des assistantes maternelles
|
||||||
static Future<List<AssistanteMaternelleModel>>
|
static Future<List<AssistanteMaternelleModel>>
|
||||||
getAssistantesMaternelles() async {
|
getAssistantesMaternelles() async {
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/admin/am_dossier_wizard.dart';
|
||||||
|
|
||||||
|
/// Modale de création dossier AM (#156) — même shell que [ValidationDossierModal].
|
||||||
|
class AmDossierCreateModal extends StatefulWidget {
|
||||||
|
final VoidCallback onClose;
|
||||||
|
final VoidCallback? onSuccess;
|
||||||
|
|
||||||
|
const AmDossierCreateModal({
|
||||||
|
super.key,
|
||||||
|
required this.onClose,
|
||||||
|
this.onSuccess,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AmDossierCreateModal> createState() => _AmDossierCreateModalState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AmDossierCreateModalState extends State<AmDossierCreateModal> {
|
||||||
|
int? _stepIndex;
|
||||||
|
int? _stepTotal;
|
||||||
|
|
||||||
|
void _onStepChanged(int step, int total) {
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_stepIndex = step;
|
||||||
|
_stepTotal = total;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSuccess() {
|
||||||
|
widget.onSuccess?.call();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const double _modalWidth = 930;
|
||||||
|
static const double _bodyHeight = 435;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final maxH = MediaQuery.of(context).size.height * 0.85;
|
||||||
|
final showStep =
|
||||||
|
_stepIndex != null && _stepTotal != null && (_stepTotal ?? 0) > 0;
|
||||||
|
return Dialog(
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(maxWidth: _modalWidth, maxHeight: maxH),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(18, 18, 0, 12),
|
||||||
|
child: Text(
|
||||||
|
'Nouvelle assistante maternelle',
|
||||||
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
if (showStep) ...[
|
||||||
|
Text(
|
||||||
|
'Étape ${(_stepIndex ?? 0) + 1}/${_stepTotal ?? 1}',
|
||||||
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||||
|
color: Colors.black54,
|
||||||
|
fontStyle: FontStyle.italic,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.close),
|
||||||
|
onPressed: widget.onClose,
|
||||||
|
tooltip: 'Fermer',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const Divider(height: 1),
|
||||||
|
SizedBox(
|
||||||
|
height: _bodyHeight,
|
||||||
|
child: AmDossierWizard.create(
|
||||||
|
onClose: widget.onClose,
|
||||||
|
onSuccess: _onSuccess,
|
||||||
|
onStepChanged: _onStepChanged,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,981 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
import 'package:p_tits_pas/models/am_registration_data.dart';
|
||||||
|
import 'package:p_tits_pas/models/dossier_unifie.dart';
|
||||||
|
import 'package:p_tits_pas/models/user.dart';
|
||||||
|
import 'package:p_tits_pas/services/api/api_config.dart';
|
||||||
|
import 'package:p_tits_pas/services/user_service.dart';
|
||||||
|
import 'package:p_tits_pas/utils/date_display_utils.dart';
|
||||||
|
import 'package:p_tits_pas/utils/email_utils.dart';
|
||||||
|
import 'package:p_tits_pas/utils/nir_utils.dart';
|
||||||
|
import 'package:p_tits_pas/utils/phone_utils.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/admin/common/admin_am_photo_frame.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/admin/common/admin_detail_modal.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/admin/common/validation_detail_section.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/admin/validation_modal_theme.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/admin/validation_refus_form.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/admin/validation_valider_confirm_dialog.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/common/auth_network_image.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/common/identity_block.dart';
|
||||||
|
|
||||||
|
enum AmDossierWizardMode { review, create }
|
||||||
|
|
||||||
|
/// Wizard dossier AM — modes [review] (validation pending) et [create] (staff #156).
|
||||||
|
class AmDossierWizard extends StatefulWidget {
|
||||||
|
final AmDossierWizardMode mode;
|
||||||
|
final DossierAM? dossier;
|
||||||
|
final VoidCallback onClose;
|
||||||
|
final VoidCallback onSuccess;
|
||||||
|
final void Function(int step, int total)? onStepChanged;
|
||||||
|
|
||||||
|
const AmDossierWizard._({
|
||||||
|
super.key,
|
||||||
|
required this.mode,
|
||||||
|
this.dossier,
|
||||||
|
required this.onClose,
|
||||||
|
required this.onSuccess,
|
||||||
|
this.onStepChanged,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory AmDossierWizard.review({
|
||||||
|
Key? key,
|
||||||
|
required DossierAM dossier,
|
||||||
|
required VoidCallback onClose,
|
||||||
|
required VoidCallback onSuccess,
|
||||||
|
void Function(int step, int total)? onStepChanged,
|
||||||
|
}) {
|
||||||
|
return AmDossierWizard._(
|
||||||
|
key: key,
|
||||||
|
mode: AmDossierWizardMode.review,
|
||||||
|
dossier: dossier,
|
||||||
|
onClose: onClose,
|
||||||
|
onSuccess: onSuccess,
|
||||||
|
onStepChanged: onStepChanged,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
factory AmDossierWizard.create({
|
||||||
|
Key? key,
|
||||||
|
required VoidCallback onClose,
|
||||||
|
required VoidCallback onSuccess,
|
||||||
|
void Function(int step, int total)? onStepChanged,
|
||||||
|
}) {
|
||||||
|
return AmDossierWizard._(
|
||||||
|
key: key,
|
||||||
|
mode: AmDossierWizardMode.create,
|
||||||
|
onClose: onClose,
|
||||||
|
onSuccess: onSuccess,
|
||||||
|
onStepChanged: onStepChanged,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get isCreate => mode == AmDossierWizardMode.create;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AmDossierWizard> createState() => _AmDossierWizardState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AmDossierWizardState extends State<AmDossierWizard> {
|
||||||
|
int _step = 0;
|
||||||
|
bool _showRefusForm = false;
|
||||||
|
bool _submitting = false;
|
||||||
|
|
||||||
|
static const int _stepCount = 3;
|
||||||
|
static const List<int> _photoProRowLayout = [2, 2, 2, 2];
|
||||||
|
static const double _idPhotoAspectRatio = 35 / 45;
|
||||||
|
static const double _photoProGap = 24;
|
||||||
|
static const double _proColumnMinWidth = 260;
|
||||||
|
static const double _photoColumnMinWidth = 160;
|
||||||
|
|
||||||
|
// --- Create mode controllers / state ---
|
||||||
|
late final TextEditingController _nomCtrl;
|
||||||
|
late final TextEditingController _prenomCtrl;
|
||||||
|
late final TextEditingController _telCtrl;
|
||||||
|
late final TextEditingController _emailCtrl;
|
||||||
|
late final TextEditingController _adresseCtrl;
|
||||||
|
late final TextEditingController _cpCtrl;
|
||||||
|
late final TextEditingController _villeCtrl;
|
||||||
|
late final TextEditingController _nirCtrl;
|
||||||
|
late final TextEditingController _dateNaissanceCtrl;
|
||||||
|
late final TextEditingController _lieuNaissanceVilleCtrl;
|
||||||
|
late final TextEditingController _lieuNaissancePaysCtrl;
|
||||||
|
late final TextEditingController _agrementCtrl;
|
||||||
|
late final TextEditingController _dateAgrementCtrl;
|
||||||
|
late final TextEditingController _capaciteCtrl;
|
||||||
|
late final TextEditingController _placesCtrl;
|
||||||
|
late final TextEditingController _presentationCtrl;
|
||||||
|
|
||||||
|
Uint8List? _photoBytes;
|
||||||
|
String? _photoFilename;
|
||||||
|
|
||||||
|
bool get _isCreate => widget.isCreate;
|
||||||
|
DossierAM get _dossier => widget.dossier!;
|
||||||
|
bool get _isEnAttente =>
|
||||||
|
!_isCreate && _dossier.user.statut == 'en_attente';
|
||||||
|
|
||||||
|
static String _v(String? s) =>
|
||||||
|
(s != null && s.trim().isNotEmpty) ? s.trim() : '–';
|
||||||
|
|
||||||
|
static String _formatNirForDisplay(String? nir) {
|
||||||
|
final v = _v(nir);
|
||||||
|
if (v == '–') return v;
|
||||||
|
final raw = nirToRaw(v).toUpperCase();
|
||||||
|
return raw.length == 15 ? formatNir(raw) : v;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_nomCtrl = TextEditingController();
|
||||||
|
_prenomCtrl = TextEditingController();
|
||||||
|
_telCtrl = TextEditingController();
|
||||||
|
_emailCtrl = TextEditingController();
|
||||||
|
_adresseCtrl = TextEditingController();
|
||||||
|
_cpCtrl = TextEditingController();
|
||||||
|
_villeCtrl = TextEditingController();
|
||||||
|
_nirCtrl = TextEditingController();
|
||||||
|
_dateNaissanceCtrl = TextEditingController();
|
||||||
|
_lieuNaissanceVilleCtrl = TextEditingController();
|
||||||
|
_lieuNaissancePaysCtrl = TextEditingController(text: 'France');
|
||||||
|
_agrementCtrl = TextEditingController();
|
||||||
|
_dateAgrementCtrl = TextEditingController();
|
||||||
|
_capaciteCtrl = TextEditingController(text: '1');
|
||||||
|
_placesCtrl = TextEditingController(text: '1');
|
||||||
|
_presentationCtrl = TextEditingController();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) => _emitStep());
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_nomCtrl.dispose();
|
||||||
|
_prenomCtrl.dispose();
|
||||||
|
_telCtrl.dispose();
|
||||||
|
_emailCtrl.dispose();
|
||||||
|
_adresseCtrl.dispose();
|
||||||
|
_cpCtrl.dispose();
|
||||||
|
_villeCtrl.dispose();
|
||||||
|
_nirCtrl.dispose();
|
||||||
|
_dateNaissanceCtrl.dispose();
|
||||||
|
_lieuNaissanceVilleCtrl.dispose();
|
||||||
|
_lieuNaissancePaysCtrl.dispose();
|
||||||
|
_agrementCtrl.dispose();
|
||||||
|
_dateAgrementCtrl.dispose();
|
||||||
|
_capaciteCtrl.dispose();
|
||||||
|
_placesCtrl.dispose();
|
||||||
|
_presentationCtrl.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _emitStep() => widget.onStepChanged?.call(_step, _stepCount);
|
||||||
|
|
||||||
|
List<AdminDetailField> _photoProFields(DossierAM d) {
|
||||||
|
final u = d.user;
|
||||||
|
return [
|
||||||
|
AdminDetailField(label: 'NIR', value: _formatNirForDisplay(d.nir)),
|
||||||
|
AdminDetailField(
|
||||||
|
label: 'Date de naissance',
|
||||||
|
value: formatIsoDateFr(u.dateNaissance),
|
||||||
|
),
|
||||||
|
AdminDetailField(
|
||||||
|
label: 'Ville de naissance',
|
||||||
|
value: _v(u.lieuNaissanceVille),
|
||||||
|
),
|
||||||
|
AdminDetailField(
|
||||||
|
label: 'Pays de naissance',
|
||||||
|
value: _v(u.lieuNaissancePays),
|
||||||
|
),
|
||||||
|
AdminDetailField(label: 'N° Agrément', value: _v(d.numeroAgrement)),
|
||||||
|
AdminDetailField(
|
||||||
|
label: 'Date d’agrément',
|
||||||
|
value: formatIsoDateFr(d.dateAgrement),
|
||||||
|
),
|
||||||
|
AdminDetailField(
|
||||||
|
label: 'Capacité max (enfants)',
|
||||||
|
value: d.nbMaxEnfants != null ? d.nbMaxEnfants.toString() : '–',
|
||||||
|
),
|
||||||
|
AdminDetailField(
|
||||||
|
label: 'Places disponibles',
|
||||||
|
value: d.placesDisponibles != null
|
||||||
|
? d.placesDisponibles.toString()
|
||||||
|
: '–',
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static String _fullPhotoUrl(String? url) => ApiConfig.absoluteMediaUrl(url);
|
||||||
|
|
||||||
|
Widget _buildPhotoSectionReview(AppUser u) {
|
||||||
|
final photoUrl = _fullPhotoUrl(u.photoUrl);
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 8),
|
||||||
|
child: LayoutBuilder(
|
||||||
|
builder: (context, c) {
|
||||||
|
const uniformFrame = 8.0;
|
||||||
|
final maxPhotoW =
|
||||||
|
(c.maxWidth - 2 * uniformFrame).clamp(0.0, double.infinity);
|
||||||
|
final maxPhotoH =
|
||||||
|
(c.maxHeight - 2 * uniformFrame).clamp(0.0, double.infinity);
|
||||||
|
const ar = _idPhotoAspectRatio;
|
||||||
|
double ph = maxPhotoH;
|
||||||
|
double pw = ph * ar;
|
||||||
|
if (pw > maxPhotoW) {
|
||||||
|
pw = maxPhotoW;
|
||||||
|
ph = pw / ar;
|
||||||
|
}
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade100,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
|
),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(uniformFrame),
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
child: SizedBox(
|
||||||
|
width: pw,
|
||||||
|
height: ph,
|
||||||
|
child: photoUrl.isEmpty
|
||||||
|
? ColoredBox(
|
||||||
|
color: Colors.grey.shade200,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.person_off_outlined,
|
||||||
|
size: 40,
|
||||||
|
color: Colors.grey.shade400),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'Aucune photo fournie',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey.shade600,
|
||||||
|
fontSize: 12),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: AuthNetworkImage(
|
||||||
|
url: photoUrl,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
width: pw,
|
||||||
|
height: ph,
|
||||||
|
loadingBuilder: (_, child, progress) {
|
||||||
|
if (progress == null) return child;
|
||||||
|
return ColoredBox(
|
||||||
|
color: Colors.grey.shade200,
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
value: progress.expectedTotalBytes !=
|
||||||
|
null
|
||||||
|
? progress.cumulativeBytesLoaded /
|
||||||
|
(progress.expectedTotalBytes!)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
errorBuilder: (_, __, ___) => ColoredBox(
|
||||||
|
color: Colors.grey.shade200,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.broken_image_outlined,
|
||||||
|
size: 40,
|
||||||
|
color: Colors.grey.shade400),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'Impossible de charger la photo',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey.shade600,
|
||||||
|
fontSize: 12),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _pickPhoto() async {
|
||||||
|
try {
|
||||||
|
final picked = await ImagePicker().pickImage(
|
||||||
|
source: ImageSource.gallery,
|
||||||
|
maxWidth: 1200,
|
||||||
|
imageQuality: 85,
|
||||||
|
);
|
||||||
|
if (picked == null) return;
|
||||||
|
final bytes = await picked.readAsBytes();
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_photoBytes = bytes;
|
||||||
|
_photoFilename = picked.name;
|
||||||
|
});
|
||||||
|
} catch (_) {
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: const Text('Impossible de charger la photo'),
|
||||||
|
backgroundColor: Colors.red.shade700,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _clearPhoto() => setState(() {
|
||||||
|
_photoBytes = null;
|
||||||
|
_photoFilename = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
String? _validateStep0() {
|
||||||
|
final nom = _nomCtrl.text.trim();
|
||||||
|
final prenom = _prenomCtrl.text.trim();
|
||||||
|
if (nom.length < 2) return 'Le nom doit contenir au moins 2 caractères.';
|
||||||
|
if (prenom.length < 2) {
|
||||||
|
return 'Le prénom doit contenir au moins 2 caractères.';
|
||||||
|
}
|
||||||
|
final phoneErr = validateFrenchNationalPhone(_telCtrl.text);
|
||||||
|
if (phoneErr != null) return phoneErr;
|
||||||
|
final emailErr = validateEmail(_emailCtrl.text);
|
||||||
|
if (emailErr != null) return emailErr;
|
||||||
|
if (_adresseCtrl.text.trim().isEmpty) {
|
||||||
|
return 'L’adresse est requise.';
|
||||||
|
}
|
||||||
|
if (_cpCtrl.text.trim().isEmpty) return 'Le code postal est requis.';
|
||||||
|
if (_villeCtrl.text.trim().isEmpty) return 'La ville est requise.';
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String? _validateStep1() {
|
||||||
|
if (_photoBytes == null || _photoBytes!.isEmpty) {
|
||||||
|
return 'Une photo de profil est requise.';
|
||||||
|
}
|
||||||
|
final birthIso = parseFrDateToIso(_dateNaissanceCtrl.text);
|
||||||
|
if (birthIso == null) {
|
||||||
|
return 'La date de naissance est invalide (jj/mm/aaaa).';
|
||||||
|
}
|
||||||
|
final ville = _lieuNaissanceVilleCtrl.text.trim();
|
||||||
|
final pays = _lieuNaissancePaysCtrl.text.trim();
|
||||||
|
if (ville.length < 2 || pays.length < 2) {
|
||||||
|
return 'La ville et le pays de naissance sont requis (au moins 2 caractères).';
|
||||||
|
}
|
||||||
|
final nirErr = validateNir(_nirCtrl.text);
|
||||||
|
if (nirErr != null) return nirErr;
|
||||||
|
if (_agrementCtrl.text.trim().isEmpty) {
|
||||||
|
return 'Le numéro d’agrément est requis.';
|
||||||
|
}
|
||||||
|
final agrementIso = parseFrDateToIso(_dateAgrementCtrl.text);
|
||||||
|
if (agrementIso == null) {
|
||||||
|
return 'La date d’agrément est invalide (jj/mm/aaaa).';
|
||||||
|
}
|
||||||
|
final capa = int.tryParse(_capaciteCtrl.text.trim());
|
||||||
|
if (capa == null || capa < 1 || capa > kAmCapaciteAccueilMax) {
|
||||||
|
return 'La capacité doit être entre 1 et $kAmCapaciteAccueilMax.';
|
||||||
|
}
|
||||||
|
final places = int.tryParse(_placesCtrl.text.trim());
|
||||||
|
if (places == null || places < 0 || places > capa) {
|
||||||
|
return 'Les places disponibles doivent être entre 0 et la capacité.';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String? _validateCurrentStep() {
|
||||||
|
if (!_isCreate) return null;
|
||||||
|
switch (_step) {
|
||||||
|
case 0:
|
||||||
|
return _validateStep0();
|
||||||
|
case 1:
|
||||||
|
return _validateStep1();
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _goNext() {
|
||||||
|
final err = _validateCurrentStep();
|
||||||
|
if (err != null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(err), backgroundColor: Colors.red.shade700),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() => _step++);
|
||||||
|
_emitStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
static String _imageMimeForBytes(Uint8List bytes) {
|
||||||
|
if (bytes.length >= 8 &&
|
||||||
|
bytes[0] == 0x89 &&
|
||||||
|
bytes[1] == 0x50 &&
|
||||||
|
bytes[2] == 0x4E &&
|
||||||
|
bytes[3] == 0x47) {
|
||||||
|
return 'image/png';
|
||||||
|
}
|
||||||
|
if (bytes.length >= 3 &&
|
||||||
|
bytes[0] == 0xFF &&
|
||||||
|
bytes[1] == 0xD8 &&
|
||||||
|
bytes[2] == 0xFF) {
|
||||||
|
return 'image/jpeg';
|
||||||
|
}
|
||||||
|
if (bytes.length >= 6 &&
|
||||||
|
bytes[0] == 0x47 &&
|
||||||
|
bytes[1] == 0x49 &&
|
||||||
|
bytes[2] == 0x46) {
|
||||||
|
return 'image/gif';
|
||||||
|
}
|
||||||
|
if (bytes.length >= 12 &&
|
||||||
|
bytes[0] == 0x52 &&
|
||||||
|
bytes[1] == 0x49 &&
|
||||||
|
bytes[2] == 0x46 &&
|
||||||
|
bytes[3] == 0x46) {
|
||||||
|
return 'image/webp';
|
||||||
|
}
|
||||||
|
return 'image/jpeg';
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _buildCreateBody() {
|
||||||
|
final bytes = _photoBytes!;
|
||||||
|
final mime = _imageMimeForBytes(bytes);
|
||||||
|
final photoBase64 = 'data:$mime;base64,${base64Encode(bytes)}';
|
||||||
|
final fn = (_photoFilename ?? '').trim();
|
||||||
|
final birthIso = parseFrDateToIso(_dateNaissanceCtrl.text)!;
|
||||||
|
final agrementIso = parseFrDateToIso(_dateAgrementCtrl.text)!;
|
||||||
|
final capa = int.parse(_capaciteCtrl.text.trim());
|
||||||
|
final places = int.parse(_placesCtrl.text.trim());
|
||||||
|
final presentation = _presentationCtrl.text.trim();
|
||||||
|
|
||||||
|
return <String, dynamic>{
|
||||||
|
'email': normalizeEmailText(_emailCtrl.text),
|
||||||
|
'prenom': _prenomCtrl.text.trim(),
|
||||||
|
'nom': _nomCtrl.text.trim(),
|
||||||
|
'telephone': normalizePhone(_telCtrl.text),
|
||||||
|
'adresse':
|
||||||
|
_adresseCtrl.text.trim().isNotEmpty ? _adresseCtrl.text.trim() : null,
|
||||||
|
'code_postal':
|
||||||
|
_cpCtrl.text.trim().isNotEmpty ? _cpCtrl.text.trim() : null,
|
||||||
|
'ville':
|
||||||
|
_villeCtrl.text.trim().isNotEmpty ? _villeCtrl.text.trim() : null,
|
||||||
|
'photo_base64': photoBase64,
|
||||||
|
'photo_filename': fn.isNotEmpty ? fn : 'photo_am.jpg',
|
||||||
|
'consentement_photo': true,
|
||||||
|
'date_naissance': birthIso,
|
||||||
|
'lieu_naissance_ville': _lieuNaissanceVilleCtrl.text.trim(),
|
||||||
|
'lieu_naissance_pays': _lieuNaissancePaysCtrl.text.trim(),
|
||||||
|
'nir': normalizeNir(_nirCtrl.text),
|
||||||
|
'numero_agrement': _agrementCtrl.text.trim(),
|
||||||
|
'date_agrement': agrementIso,
|
||||||
|
'capacite_accueil': capa,
|
||||||
|
'places_disponibles': places,
|
||||||
|
'biographie': presentation.isNotEmpty ? presentation : null,
|
||||||
|
'acceptation_cgu': true,
|
||||||
|
'acceptation_privacy': true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _createAndValidate() async {
|
||||||
|
if (_submitting) return;
|
||||||
|
final err0 = _validateStep0();
|
||||||
|
if (err0 != null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(err0), backgroundColor: Colors.red.shade700),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final err1 = _validateStep1();
|
||||||
|
if (err1 != null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(err1), backgroundColor: Colors.red.shade700),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ok = await showValidationValiderConfirmDialog(
|
||||||
|
context,
|
||||||
|
body:
|
||||||
|
'Créer et activer le dossier de cette assistante maternelle ? Un e-mail de création de mot de passe sera envoyé.',
|
||||||
|
);
|
||||||
|
if (!mounted || !ok) return;
|
||||||
|
|
||||||
|
setState(() => _submitting = true);
|
||||||
|
try {
|
||||||
|
await UserService.createAmDossier(_buildCreateBody());
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'Dossier créé et validé. L’assistante maternelle est active.',
|
||||||
|
),
|
||||||
|
duration: Duration(seconds: 4),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
widget.onSuccess();
|
||||||
|
} catch (e) {
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(e is Exception
|
||||||
|
? e.toString().replaceFirst('Exception: ', '')
|
||||||
|
: 'Erreur'),
|
||||||
|
backgroundColor: Colors.red.shade700,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
if (mounted) setState(() => _submitting = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (_showRefusForm) {
|
||||||
|
return _buildRefusPage();
|
||||||
|
}
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Expanded(child: _buildStepContent()),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
_buildNavigation(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildStepContent() {
|
||||||
|
switch (_step) {
|
||||||
|
case 0:
|
||||||
|
return _buildStep0();
|
||||||
|
case 1:
|
||||||
|
return _buildStep1();
|
||||||
|
case 2:
|
||||||
|
return _buildStep2();
|
||||||
|
default:
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildStep0() {
|
||||||
|
if (_isCreate) {
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
return SingleChildScrollView(
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(minWidth: constraints.maxWidth),
|
||||||
|
child: IdentityBlock.editable(
|
||||||
|
title: 'Identité et coordonnées',
|
||||||
|
nomController: _nomCtrl,
|
||||||
|
prenomController: _prenomCtrl,
|
||||||
|
telephoneController: _telCtrl,
|
||||||
|
emailController: _emailCtrl,
|
||||||
|
adresseController: _adresseCtrl,
|
||||||
|
codePostalController: _cpCtrl,
|
||||||
|
villeController: _villeCtrl,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final u = _dossier.user;
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
return SingleChildScrollView(
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(minWidth: constraints.maxWidth),
|
||||||
|
child: IdentityBlock.readOnlyFromUser(
|
||||||
|
u,
|
||||||
|
title: 'Identité et coordonnées',
|
||||||
|
emptyLabel: '–',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildStep1() {
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, c) {
|
||||||
|
final maxRowW = c.maxWidth;
|
||||||
|
final maxRowH = c.maxHeight;
|
||||||
|
const photoHeaderH = 0.0;
|
||||||
|
final bodyH = (maxRowH - photoHeaderH).clamp(0.0, double.infinity);
|
||||||
|
final idealPhotoW = bodyH * _idPhotoAspectRatio + 16;
|
||||||
|
final maxPhotoW = (maxRowW - _photoProGap - _proColumnMinWidth)
|
||||||
|
.clamp(0.0, double.infinity);
|
||||||
|
var photoW = idealPhotoW.clamp(_photoColumnMinWidth, 360.0);
|
||||||
|
if (photoW > maxPhotoW) photoW = maxPhotoW;
|
||||||
|
photoW = photoW.clamp(0.0, maxRowW - _photoProGap);
|
||||||
|
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: photoW,
|
||||||
|
child: _isCreate
|
||||||
|
? AdminAmPhotoFrame(
|
||||||
|
imageBytes: _photoBytes,
|
||||||
|
onTap: _pickPhoto,
|
||||||
|
onClear: _photoBytes != null ? _clearPhoto : null,
|
||||||
|
emptyLabel: 'Ajouter une photo',
|
||||||
|
)
|
||||||
|
: _buildPhotoSectionReview(_dossier.user),
|
||||||
|
),
|
||||||
|
const SizedBox(width: _photoProGap),
|
||||||
|
Expanded(
|
||||||
|
child: LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
return SingleChildScrollView(
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints:
|
||||||
|
BoxConstraints(minWidth: constraints.maxWidth),
|
||||||
|
child: _isCreate
|
||||||
|
? _buildCreateProFields()
|
||||||
|
: ValidationDetailSection(
|
||||||
|
title: 'Dossier professionnel',
|
||||||
|
fields: _photoProFields(_dossier),
|
||||||
|
rowLayout: _photoProRowLayout,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildCreateProFields() {
|
||||||
|
return ValidationFormGrid(
|
||||||
|
title: 'Dossier professionnel',
|
||||||
|
rowLayout: _photoProRowLayout,
|
||||||
|
fields: [
|
||||||
|
ValidationLabeledField(
|
||||||
|
label: 'NIR',
|
||||||
|
field: ValidationEditableField(
|
||||||
|
controller: _nirCtrl,
|
||||||
|
hintText: '15 caractères',
|
||||||
|
inputFormatters: [NirInputFormatter()],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ValidationLabeledField(
|
||||||
|
label: 'Date de naissance',
|
||||||
|
field: ValidationEditableField(
|
||||||
|
controller: _dateNaissanceCtrl,
|
||||||
|
hintText: 'jj / mm / aaaa',
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
inputFormatters: const [FrenchDateInputFormatter()],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ValidationLabeledField(
|
||||||
|
label: 'Ville de naissance',
|
||||||
|
field: ValidationEditableField(
|
||||||
|
controller: _lieuNaissanceVilleCtrl,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ValidationLabeledField(
|
||||||
|
label: 'Pays de naissance',
|
||||||
|
field: ValidationEditableField(
|
||||||
|
controller: _lieuNaissancePaysCtrl,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ValidationLabeledField(
|
||||||
|
label: 'N° Agrément',
|
||||||
|
field: ValidationEditableField(controller: _agrementCtrl),
|
||||||
|
),
|
||||||
|
ValidationLabeledField(
|
||||||
|
label: 'Date d’agrément',
|
||||||
|
field: ValidationEditableField(
|
||||||
|
controller: _dateAgrementCtrl,
|
||||||
|
hintText: 'jj / mm / aaaa',
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
inputFormatters: const [FrenchDateInputFormatter()],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ValidationLabeledField(
|
||||||
|
label: 'Capacité max (enfants)',
|
||||||
|
field: ValidationEditableField(
|
||||||
|
controller: _capaciteCtrl,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ValidationLabeledField(
|
||||||
|
label: 'Places disponibles',
|
||||||
|
field: ValidationEditableField(
|
||||||
|
controller: _placesCtrl,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildStep2() {
|
||||||
|
if (_isCreate) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
'Présentation',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
|
controller: _presentationCtrl,
|
||||||
|
maxLines: null,
|
||||||
|
expands: true,
|
||||||
|
maxLength: 2000,
|
||||||
|
textAlignVertical: TextAlignVertical.top,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Présentation (optionnel, max 2000 caractères)',
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.grey.shade50,
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||||
|
),
|
||||||
|
enabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||||
|
),
|
||||||
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 12,
|
||||||
|
vertical: 10,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final presentation =
|
||||||
|
(_dossier.presentation != null && _dossier.presentation!.trim().isNotEmpty)
|
||||||
|
? _dossier.presentation!
|
||||||
|
: '–';
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
'Présentation',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Expanded(
|
||||||
|
child: LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
return SingleChildScrollView(
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(minHeight: constraints.maxHeight),
|
||||||
|
child: Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 12, vertical: 10),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade50,
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
|
),
|
||||||
|
child: SelectableText(
|
||||||
|
presentation,
|
||||||
|
style: const TextStyle(color: Colors.black87, fontSize: 14),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildNavigation() {
|
||||||
|
if (_step == 2) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
TextButton(onPressed: widget.onClose, child: const Text('Annuler')),
|
||||||
|
const Spacer(),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() => _step = 1);
|
||||||
|
_emitStep();
|
||||||
|
},
|
||||||
|
child: const Text('Précédent'),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
if (_isCreate) ...[
|
||||||
|
ElevatedButton(
|
||||||
|
style: ValidationModalTheme.primaryElevatedStyle,
|
||||||
|
onPressed: _submitting ? null : _createAndValidate,
|
||||||
|
child: Text(_submitting ? 'Envoi...' : 'Créer et valider'),
|
||||||
|
),
|
||||||
|
] else if (_isEnAttente) ...[
|
||||||
|
OutlinedButton(
|
||||||
|
onPressed: _submitting ? null : _refuser,
|
||||||
|
child: const Text('Refuser')),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ValidationModalTheme.primaryElevatedStyle,
|
||||||
|
onPressed: _submitting ? null : _onValiderPressed,
|
||||||
|
child: Text(_submitting ? 'Envoi...' : 'Valider'),
|
||||||
|
),
|
||||||
|
] else
|
||||||
|
ElevatedButton(
|
||||||
|
style: ValidationModalTheme.primaryElevatedStyle,
|
||||||
|
onPressed: widget.onClose,
|
||||||
|
child: const Text('Fermer'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
TextButton(onPressed: widget.onClose, child: const Text('Annuler')),
|
||||||
|
const Spacer(),
|
||||||
|
if (_step > 0) ...[
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() => _step--);
|
||||||
|
_emitStep();
|
||||||
|
},
|
||||||
|
child: const Text('Précédent'),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
|
ElevatedButton(
|
||||||
|
style: ValidationModalTheme.primaryElevatedStyle,
|
||||||
|
onPressed: _goNext,
|
||||||
|
child: const Text('Suivant'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onValiderPressed() async {
|
||||||
|
if (_submitting) return;
|
||||||
|
final ok = await showValidationValiderConfirmDialog(
|
||||||
|
context,
|
||||||
|
body:
|
||||||
|
'Voulez-vous valider le dossier de cette assistante maternelle ? Cette action confirme le compte.',
|
||||||
|
);
|
||||||
|
if (!mounted || !ok) return;
|
||||||
|
await _valider();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _valider() async {
|
||||||
|
if (_submitting) return;
|
||||||
|
setState(() => _submitting = true);
|
||||||
|
try {
|
||||||
|
await UserService.validateUser(_dossier.user.id);
|
||||||
|
if (!mounted) return;
|
||||||
|
widget.onSuccess();
|
||||||
|
} catch (e) {
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(e is Exception
|
||||||
|
? e.toString().replaceFirst('Exception: ', '')
|
||||||
|
: 'Erreur'),
|
||||||
|
backgroundColor: Colors.red.shade700,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
if (mounted) setState(() => _submitting = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _refuser() => setState(() => _showRefusForm = true);
|
||||||
|
|
||||||
|
Widget _buildRefusPage() {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: ValidationRefusForm(
|
||||||
|
isSubmitting: _submitting,
|
||||||
|
onCancel: widget.onClose,
|
||||||
|
onPrevious: () => setState(() => _showRefusForm = false),
|
||||||
|
onSubmit: (comment) {
|
||||||
|
if (comment == null || comment.trim().isEmpty) return;
|
||||||
|
_refuserEnvoyer(comment.trim());
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _refuserEnvoyer(String comment) async {
|
||||||
|
if (_submitting) return;
|
||||||
|
setState(() => _submitting = true);
|
||||||
|
try {
|
||||||
|
await UserService.refuseUser(_dossier.user.id, comment: comment);
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'Refus enregistré. Un e-mail avec le lien de reprise a été envoyé.',
|
||||||
|
),
|
||||||
|
duration: Duration(seconds: 4),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
widget.onSuccess();
|
||||||
|
} catch (e) {
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(e is Exception
|
||||||
|
? e.toString().replaceFirst('Exception: ', '')
|
||||||
|
: 'Erreur'),
|
||||||
|
backgroundColor: Colors.red.shade700,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
if (mounted) setState(() => _submitting = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1277,18 +1277,16 @@ class _AdminChildDetailModalState extends State<AdminChildDetailModal> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Édition orphelin (#157) : rattache immédiatement au foyer.
|
// Édition orphelin (#157/#158) : un seul attach — le back propage au foyer.
|
||||||
final enfantId = widget.enfant?.id;
|
final enfantId = widget.enfant?.id;
|
||||||
if (enfantId == null || enfantId.isEmpty) return;
|
if (enfantId == null || enfantId.isEmpty) return;
|
||||||
|
|
||||||
setState(() => _saving = true);
|
setState(() => _saving = true);
|
||||||
try {
|
try {
|
||||||
for (final parentId in selected.parentUserIds) {
|
|
||||||
await UserService.attachEnfantToParent(
|
await UserService.attachEnfantToParent(
|
||||||
parentUserId: parentId,
|
parentUserId: selected.pivotParentUserId,
|
||||||
enfantId: enfantId,
|
enfantId: enfantId,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
final refreshed = await UserService.getEnfant(enfantId);
|
final refreshed = await UserService.getEnfant(enfantId);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
|||||||
builder: (ctx) => AlertDialog(
|
builder: (ctx) => AlertDialog(
|
||||||
title: const Text('Détacher l\'enfant'),
|
title: const Text('Détacher l\'enfant'),
|
||||||
content: Text(
|
content: Text(
|
||||||
'Retirer ${child.fullName} de la fiche de ce parent ?',
|
'Retirer ${child.fullName} du foyer (tous les responsables) ?',
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
@@ -308,8 +308,9 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
|||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
await _reloadChildren();
|
await _reloadChildren();
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
widget.onSaved?.call();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('Enfant détaché')),
|
const SnackBar(content: Text('Enfant détaché du foyer')),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
@@ -336,8 +337,9 @@ class _AdminParentEditModalState extends State<AdminParentEditModal> {
|
|||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
await _reloadChildren();
|
await _reloadChildren();
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
widget.onSaved?.call();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('Enfant rattaché')),
|
const SnackBar(content: Text('Enfant rattaché au foyer')),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:p_tits_pas/screens/administrateurs/creation/gestionnaires_create.dart';
|
import 'package:p_tits_pas/screens/administrateurs/creation/gestionnaires_create.dart';
|
||||||
import 'package:p_tits_pas/services/user_service.dart';
|
import 'package:p_tits_pas/services/user_service.dart';
|
||||||
import 'package:p_tits_pas/widgets/admin/admin_management_widget.dart';
|
import 'package:p_tits_pas/widgets/admin/admin_management_widget.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/admin/am_dossier_create_modal.dart';
|
||||||
import 'package:p_tits_pas/widgets/admin/assistante_maternelle_management_widget.dart';
|
import 'package:p_tits_pas/widgets/admin/assistante_maternelle_management_widget.dart';
|
||||||
import 'package:p_tits_pas/widgets/admin/common/admin_child_detail_modal.dart';
|
import 'package:p_tits_pas/widgets/admin/common/admin_child_detail_modal.dart';
|
||||||
import 'package:p_tits_pas/widgets/admin/dashboard_admin.dart';
|
import 'package:p_tits_pas/widgets/admin/dashboard_admin.dart';
|
||||||
@@ -28,6 +29,7 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
|||||||
int _gestionnaireRefreshTick = 0;
|
int _gestionnaireRefreshTick = 0;
|
||||||
int _adminRefreshTick = 0;
|
int _adminRefreshTick = 0;
|
||||||
int _enfantRefreshTick = 0;
|
int _enfantRefreshTick = 0;
|
||||||
|
int _amRefreshTick = 0;
|
||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
final TextEditingController _amCapacityController = TextEditingController();
|
final TextEditingController _amCapacityController = TextEditingController();
|
||||||
String? _parentStatus;
|
String? _parentStatus;
|
||||||
@@ -272,6 +274,7 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
|||||||
);
|
);
|
||||||
case 2:
|
case 2:
|
||||||
return AssistanteMaternelleManagementWidget(
|
return AssistanteMaternelleManagementWidget(
|
||||||
|
key: ValueKey('ams-$_amRefreshTick'),
|
||||||
searchQuery: _searchController.text,
|
searchQuery: _searchController.text,
|
||||||
capacityMin: int.tryParse(_amCapacityController.text),
|
capacityMin: int.tryParse(_amCapacityController.text),
|
||||||
);
|
);
|
||||||
@@ -331,6 +334,24 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (contentIndex == 2) {
|
||||||
|
await showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (dialogContext) {
|
||||||
|
return AmDossierCreateModal(
|
||||||
|
onClose: () => Navigator.of(dialogContext).pop(),
|
||||||
|
onSuccess: () {
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() => _amRefreshTick++);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (contentIndex == 3) {
|
if (contentIndex == 3) {
|
||||||
final created = await showDialog<bool>(
|
final created = await showDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -374,7 +395,7 @@ class _UserManagementPanelState extends State<UserManagementPanel> {
|
|||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
'La création parent / enfant / AM sera disponible avec le ticket #129.',
|
'La création parent sera disponible avec le ticket #129.',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,20 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:p_tits_pas/models/dossier_unifie.dart';
|
import 'package:p_tits_pas/models/dossier_unifie.dart';
|
||||||
import 'package:p_tits_pas/utils/date_display_utils.dart';
|
import 'package:p_tits_pas/widgets/admin/am_dossier_wizard.dart';
|
||||||
import 'package:p_tits_pas/utils/nir_utils.dart';
|
|
||||||
import 'package:p_tits_pas/models/user.dart';
|
|
||||||
import 'package:p_tits_pas/services/user_service.dart';
|
|
||||||
import 'package:p_tits_pas/services/api/api_config.dart';
|
|
||||||
import 'package:p_tits_pas/widgets/admin/common/admin_detail_modal.dart';
|
|
||||||
import 'package:p_tits_pas/widgets/admin/common/validation_detail_section.dart';
|
|
||||||
import 'package:p_tits_pas/widgets/common/identity_block.dart';
|
|
||||||
import 'package:p_tits_pas/widgets/common/auth_network_image.dart';
|
|
||||||
import 'validation_modal_theme.dart';
|
|
||||||
import 'validation_refus_form.dart';
|
|
||||||
import 'validation_valider_confirm_dialog.dart';
|
|
||||||
|
|
||||||
/// Wizard de validation dossier AM : étapes sobres (label/valeur), récap, Valider/Refuser/Annuler, page refus. Ticket #107.
|
/// Wrapper historique (#107) — délègue à [AmDossierWizard.review].
|
||||||
class ValidationAmWizard extends StatefulWidget {
|
class ValidationAmWizard extends StatelessWidget {
|
||||||
final DossierAM dossier;
|
final DossierAM dossier;
|
||||||
final VoidCallback onClose;
|
final VoidCallback onClose;
|
||||||
final VoidCallback onSuccess;
|
final VoidCallback onSuccess;
|
||||||
@@ -28,480 +17,13 @@ class ValidationAmWizard extends StatefulWidget {
|
|||||||
this.onStepChanged,
|
this.onStepChanged,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
|
||||||
State<ValidationAmWizard> createState() => _ValidationAmWizardState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ValidationAmWizardState extends State<ValidationAmWizard> {
|
|
||||||
int _step = 0;
|
|
||||||
bool _showRefusForm = false;
|
|
||||||
bool _submitting = false;
|
|
||||||
|
|
||||||
static const int _stepCount = 3;
|
|
||||||
|
|
||||||
bool get _isEnAttente => widget.dossier.user.statut == 'en_attente';
|
|
||||||
|
|
||||||
static String _v(String? s) =>
|
|
||||||
(s != null && s.trim().isNotEmpty) ? s.trim() : '–';
|
|
||||||
|
|
||||||
/// Présentation lisible : `1 12 34 56 789 012 - 34` (15 caractères utiles requis).
|
|
||||||
static String _formatNirForDisplay(String? nir) {
|
|
||||||
final v = _v(nir);
|
|
||||||
if (v == '–') return v;
|
|
||||||
final raw = nirToRaw(v).toUpperCase();
|
|
||||||
return raw.length == 15 ? formatNir(raw) : v;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => _emitStep());
|
|
||||||
}
|
|
||||||
|
|
||||||
void _emitStep() => widget.onStepChanged?.call(_step, _stepCount);
|
|
||||||
|
|
||||||
/// Panneau photo + grille droite : NIR|naissance, ville|pays, agrément|date, capa|places.
|
|
||||||
List<AdminDetailField> _photoProFields(DossierAM d) {
|
|
||||||
final u = d.user;
|
|
||||||
return [
|
|
||||||
AdminDetailField(label: 'NIR', value: _formatNirForDisplay(d.nir)),
|
|
||||||
AdminDetailField(
|
|
||||||
label: 'Date de naissance',
|
|
||||||
value: formatIsoDateFr(u.dateNaissance),
|
|
||||||
),
|
|
||||||
AdminDetailField(
|
|
||||||
label: 'Ville de naissance',
|
|
||||||
value: _v(u.lieuNaissanceVille),
|
|
||||||
),
|
|
||||||
AdminDetailField(
|
|
||||||
label: 'Pays de naissance',
|
|
||||||
value: _v(u.lieuNaissancePays),
|
|
||||||
),
|
|
||||||
AdminDetailField(label: 'N° Agrément', value: _v(d.numeroAgrement)),
|
|
||||||
AdminDetailField(
|
|
||||||
label: 'Date d’agrément',
|
|
||||||
value: formatIsoDateFr(d.dateAgrement),
|
|
||||||
),
|
|
||||||
AdminDetailField(
|
|
||||||
label: 'Capacité max (enfants)',
|
|
||||||
value: d.nbMaxEnfants != null ? d.nbMaxEnfants.toString() : '–',
|
|
||||||
),
|
|
||||||
AdminDetailField(
|
|
||||||
label: 'Places disponibles',
|
|
||||||
value: d.placesDisponibles != null
|
|
||||||
? d.placesDisponibles.toString()
|
|
||||||
: '–',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
static const List<int> _photoProRowLayout = [2, 2, 2, 2];
|
|
||||||
|
|
||||||
/// Proportion photo d’identité (35×45 mm).
|
|
||||||
static const double _idPhotoAspectRatio = 35 / 45;
|
|
||||||
|
|
||||||
static const double _photoProGap = 24;
|
|
||||||
/// Largeur mini réservée aux champs (évite une colonne photo trop gourmande).
|
|
||||||
static const double _proColumnMinWidth = 260;
|
|
||||||
static const double _photoColumnMinWidth = 160;
|
|
||||||
|
|
||||||
/// URL complète pour la photo : si relatif, préfixe [ApiConfig.baseUrl] (ex. `/api/v1/uploads/...`).
|
|
||||||
static String _fullPhotoUrl(String? url) => ApiConfig.absoluteMediaUrl(url);
|
|
||||||
|
|
||||||
Widget _buildPhotoSection(AppUser u) {
|
|
||||||
final photoUrl = _fullPhotoUrl(u.photoUrl);
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(right: 8),
|
|
||||||
child: LayoutBuilder(
|
|
||||||
builder: (context, c) {
|
|
||||||
// Cadre clair : une seule épaisseur partout (photo + padding identique haut/bas/gauche/droite).
|
|
||||||
const uniformFrame = 8.0;
|
|
||||||
final maxPhotoW =
|
|
||||||
(c.maxWidth - 2 * uniformFrame).clamp(0.0, double.infinity);
|
|
||||||
final maxPhotoH =
|
|
||||||
(c.maxHeight - 2 * uniformFrame).clamp(0.0, double.infinity);
|
|
||||||
const ar = _idPhotoAspectRatio;
|
|
||||||
double ph = maxPhotoH;
|
|
||||||
double pw = ph * ar;
|
|
||||||
if (pw > maxPhotoW) {
|
|
||||||
pw = maxPhotoW;
|
|
||||||
ph = pw / ar;
|
|
||||||
}
|
|
||||||
return Align(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.grey.shade100,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: Border.all(color: Colors.grey.shade300),
|
|
||||||
),
|
|
||||||
clipBehavior: Clip.antiAlias,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(uniformFrame),
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(6),
|
|
||||||
child: SizedBox(
|
|
||||||
width: pw,
|
|
||||||
height: ph,
|
|
||||||
child: photoUrl.isEmpty
|
|
||||||
? ColoredBox(
|
|
||||||
color: Colors.grey.shade200,
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.person_off_outlined,
|
|
||||||
size: 40,
|
|
||||||
color: Colors.grey.shade400),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
'Aucune photo fournie',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.grey.shade600,
|
|
||||||
fontSize: 12),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: AuthNetworkImage(
|
|
||||||
url: photoUrl,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
width: pw,
|
|
||||||
height: ph,
|
|
||||||
loadingBuilder: (_, child, progress) {
|
|
||||||
if (progress == null) return child;
|
|
||||||
return ColoredBox(
|
|
||||||
color: Colors.grey.shade200,
|
|
||||||
child: Center(
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
value: progress.expectedTotalBytes !=
|
|
||||||
null
|
|
||||||
? progress.cumulativeBytesLoaded /
|
|
||||||
(progress.expectedTotalBytes!)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
errorBuilder: (_, __, ___) => ColoredBox(
|
|
||||||
color: Colors.grey.shade200,
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.broken_image_outlined,
|
|
||||||
size: 40,
|
|
||||||
color: Colors.grey.shade400),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
'Impossible de charger la photo',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.grey.shade600,
|
|
||||||
fontSize: 12),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (_showRefusForm) {
|
return AmDossierWizard.review(
|
||||||
return _buildRefusPage();
|
dossier: dossier,
|
||||||
}
|
onClose: onClose,
|
||||||
return Padding(
|
onSuccess: onSuccess,
|
||||||
padding: const EdgeInsets.all(20),
|
onStepChanged: onStepChanged,
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Expanded(child: _buildStepContent()),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
_buildNavigation(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildStepContent() {
|
|
||||||
final d = widget.dossier;
|
|
||||||
final u = d.user;
|
|
||||||
switch (_step) {
|
|
||||||
case 0:
|
|
||||||
return LayoutBuilder(
|
|
||||||
builder: (context, constraints) {
|
|
||||||
return SingleChildScrollView(
|
|
||||||
child: ConstrainedBox(
|
|
||||||
constraints: BoxConstraints(minWidth: constraints.maxWidth),
|
|
||||||
child: IdentityBlock.readOnlyFromUser(
|
|
||||||
u,
|
|
||||||
title: 'Identité et coordonnées',
|
|
||||||
emptyLabel: '–',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
case 1:
|
|
||||||
// Pas de SingleChildScrollView sur la Row (hauteur non bornée). Défilement à droite.
|
|
||||||
// Largeur photo ≈ ratio × hauteur utile, plafonnée pour laisser au moins [_proColumnMinWidth] aux champs.
|
|
||||||
return LayoutBuilder(
|
|
||||||
builder: (context, c) {
|
|
||||||
final maxRowW = c.maxWidth;
|
|
||||||
final maxRowH = c.maxHeight;
|
|
||||||
const photoHeaderH = 0.0;
|
|
||||||
final bodyH = (maxRowH - photoHeaderH).clamp(0.0, double.infinity);
|
|
||||||
final idealPhotoW =
|
|
||||||
bodyH * _idPhotoAspectRatio + 16; // marge approx. cadre clair
|
|
||||||
final maxPhotoW = (maxRowW - _photoProGap - _proColumnMinWidth)
|
|
||||||
.clamp(0.0, double.infinity);
|
|
||||||
var photoW = idealPhotoW.clamp(_photoColumnMinWidth, 360.0);
|
|
||||||
if (photoW > maxPhotoW) photoW = maxPhotoW;
|
|
||||||
photoW = photoW.clamp(0.0, maxRowW - _photoProGap);
|
|
||||||
|
|
||||||
return Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: photoW,
|
|
||||||
child: _buildPhotoSection(u),
|
|
||||||
),
|
|
||||||
const SizedBox(width: _photoProGap),
|
|
||||||
Expanded(
|
|
||||||
child: LayoutBuilder(
|
|
||||||
builder: (context, constraints) {
|
|
||||||
return SingleChildScrollView(
|
|
||||||
child: ConstrainedBox(
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
minWidth: constraints.maxWidth),
|
|
||||||
child: ValidationDetailSection(
|
|
||||||
title: 'Dossier professionnel',
|
|
||||||
fields: _photoProFields(d),
|
|
||||||
rowLayout: _photoProRowLayout,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
case 2:
|
|
||||||
final presentation =
|
|
||||||
(d.presentation != null && d.presentation!.trim().isNotEmpty)
|
|
||||||
? d.presentation!
|
|
||||||
: '–';
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
|
||||||
const Text(
|
|
||||||
'Présentation',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Expanded(
|
|
||||||
child: LayoutBuilder(
|
|
||||||
builder: (context, constraints) {
|
|
||||||
return SingleChildScrollView(
|
|
||||||
child: ConstrainedBox(
|
|
||||||
constraints:
|
|
||||||
BoxConstraints(minHeight: constraints.maxHeight),
|
|
||||||
child: Container(
|
|
||||||
width: double.infinity,
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 12, vertical: 10),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.grey.shade50,
|
|
||||||
borderRadius: BorderRadius.circular(6),
|
|
||||||
border: Border.all(color: Colors.grey.shade300),
|
|
||||||
),
|
|
||||||
child: SelectableText(
|
|
||||||
presentation,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.black87, fontSize: 14),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildNavigation() {
|
|
||||||
if (_step == 2) {
|
|
||||||
return Row(
|
|
||||||
children: [
|
|
||||||
TextButton(onPressed: widget.onClose, child: const Text('Annuler')),
|
|
||||||
const Spacer(),
|
|
||||||
Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
setState(() => _step = 1);
|
|
||||||
_emitStep();
|
|
||||||
},
|
|
||||||
child: const Text('Précédent'),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
if (_isEnAttente) ...[
|
|
||||||
OutlinedButton(
|
|
||||||
onPressed: _submitting ? null : _refuser,
|
|
||||||
child: const Text('Refuser')),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
ElevatedButton(
|
|
||||||
style: ValidationModalTheme.primaryElevatedStyle,
|
|
||||||
onPressed: _submitting ? null : _onValiderPressed,
|
|
||||||
child: Text(_submitting ? 'Envoi...' : 'Valider'),
|
|
||||||
),
|
|
||||||
] else
|
|
||||||
ElevatedButton(
|
|
||||||
style: ValidationModalTheme.primaryElevatedStyle,
|
|
||||||
onPressed: widget.onClose,
|
|
||||||
child: const Text('Fermer'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Row(
|
|
||||||
children: [
|
|
||||||
TextButton(onPressed: widget.onClose, child: const Text('Annuler')),
|
|
||||||
const Spacer(),
|
|
||||||
if (_step > 0) ...[
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
setState(() => _step--);
|
|
||||||
_emitStep();
|
|
||||||
},
|
|
||||||
child: const Text('Précédent'),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
],
|
|
||||||
ElevatedButton(
|
|
||||||
style: ValidationModalTheme.primaryElevatedStyle,
|
|
||||||
onPressed: () {
|
|
||||||
setState(() => _step++);
|
|
||||||
_emitStep();
|
|
||||||
},
|
|
||||||
child: const Text('Suivant'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _onValiderPressed() async {
|
|
||||||
if (_submitting) return;
|
|
||||||
final ok = await showValidationValiderConfirmDialog(
|
|
||||||
context,
|
|
||||||
body:
|
|
||||||
'Voulez-vous valider le dossier de cette assistante maternelle ? Cette action confirme le compte.',
|
|
||||||
);
|
|
||||||
if (!mounted || !ok) return;
|
|
||||||
await _valider();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _valider() async {
|
|
||||||
if (_submitting) return;
|
|
||||||
setState(() => _submitting = true);
|
|
||||||
try {
|
|
||||||
await UserService.validateUser(widget.dossier.user.id);
|
|
||||||
if (!mounted) return;
|
|
||||||
widget.onSuccess();
|
|
||||||
} catch (e) {
|
|
||||||
if (!mounted) return;
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(e is Exception
|
|
||||||
? e.toString().replaceFirst('Exception: ', '')
|
|
||||||
: 'Erreur'),
|
|
||||||
backgroundColor: Colors.red.shade700,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
if (mounted) setState(() => _submitting = false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _refuser() => setState(() => _showRefusForm = true);
|
|
||||||
|
|
||||||
Widget _buildRefusPage() {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(20),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: ValidationRefusForm(
|
|
||||||
isSubmitting: _submitting,
|
|
||||||
onCancel: widget.onClose,
|
|
||||||
onPrevious: () => setState(() => _showRefusForm = false),
|
|
||||||
onSubmit: (comment) {
|
|
||||||
if (comment == null || comment.trim().isEmpty) return;
|
|
||||||
_refuserEnvoyer(comment.trim());
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _refuserEnvoyer(String comment) async {
|
|
||||||
if (_submitting) return;
|
|
||||||
setState(() => _submitting = true);
|
|
||||||
try {
|
|
||||||
await UserService.refuseUser(widget.dossier.user.id, comment: comment);
|
|
||||||
if (!mounted) return;
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: const Text(
|
|
||||||
'Refus enregistré. Un e-mail avec le lien de reprise a été envoyé.',
|
|
||||||
),
|
|
||||||
duration: const Duration(seconds: 4),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
widget.onSuccess();
|
|
||||||
} catch (e) {
|
|
||||||
if (!mounted) return;
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(e is Exception
|
|
||||||
? e.toString().replaceFirst('Exception: ', '')
|
|
||||||
: 'Erreur'),
|
|
||||||
backgroundColor: Colors.red.shade700,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
if (mounted) setState(() => _submitting = false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user