diff --git a/src/app/form/form-view/form-view.component.ts b/src/app/form/form-view/form-view.component.ts index 54576b752e88a96428655713d91dd7c30d8726de..ec58518c16bb18cb1f7c9d0a24db80e1d3dab52d 100644 --- a/src/app/form/form-view/form-view.component.ts +++ b/src/app/form/form-view/form-view.component.ts @@ -24,7 +24,7 @@ type stepType = accountFormStep | profileFormStep | structureFormStep | personal @Component({ selector: 'app-form-view', templateUrl: './form-view.component.html', - styleUrls: ['./form-view.component.scss'], + styleUrls: ['./form-view.component.scss'] }) export class FormViewComponent implements OnInit { public routeParam: string; @@ -181,9 +181,9 @@ export class FormViewComponent implements OnInit { phone: new UntypedFormControl('', [Validators.required, Validators.pattern(CustomRegExp.PHONE)]), password: new UntypedFormControl('', [ Validators.required, - Validators.pattern(CustomRegExp.PASSWORD), //NOSONAR + Validators.pattern(CustomRegExp.PASSWORD) //NOSONAR ]), - confirmPassword: new UntypedFormControl(''), + confirmPassword: new UntypedFormControl('') }, [MustMatch('password', 'confirmPassword')] ); @@ -193,14 +193,14 @@ export class FormViewComponent implements OnInit { this.profileForm = new UntypedFormGroup({ employer: new UntypedFormGroup({ name: new UntypedFormControl('', [Validators.required]), - validated: new UntypedFormControl(false, [Validators.required]), + validated: new UntypedFormControl(false, [Validators.required]) }), job: new UntypedFormGroup({ name: new UntypedFormControl('', [Validators.required]), validated: new UntypedFormControl(true, [Validators.required]), - hasPersonalOffer: new UntypedFormControl(true, [Validators.required]), + hasPersonalOffer: new UntypedFormControl(true, [Validators.required]) }), - structure: new UntypedFormControl('', [Validators.required]), + structure: new UntypedFormControl('', [Validators.required]) }); } @@ -216,7 +216,7 @@ export class FormViewComponent implements OnInit { accessRight: new UntypedFormControl(personalOffer.accessRight), digitalCultureSecurity: new UntypedFormControl(personalOffer.digitalCultureSecurity), socialAndProfessional: new UntypedFormControl(personalOffer.socialAndProfessional), - parentingHelp: new UntypedFormControl(personalOffer.parentingHelp), + parentingHelp: new UntypedFormControl(personalOffer.parentingHelp) }); } @@ -318,7 +318,7 @@ export class FormViewComponent implements OnInit { .pipe( map((res) => res), catchError((_e) => of()) - ), + ) }).subscribe(() => { this.router.navigateByUrl('form/structure'); }); @@ -335,7 +335,9 @@ export class FormViewComponent implements OnInit { } public async saveStructureForm(): Promise<void> { const user = await this.profileService.getProfile(); - this.structureService.createStructure(this.structureForm.value, this.profile).subscribe((struct) => { + const newStructure = new Structure(this.structureForm.value); + newStructure.hours = this.hoursForm.value; + this.structureService.createStructure(newStructure, this.profile).subscribe((struct) => { if (user.job.hasPersonalOffer) { this.structure = struct; this.router.navigateByUrl('form/personaloffer'); diff --git a/src/app/form/form-view/structure-form/structure-form.component.ts b/src/app/form/form-view/structure-form/structure-form.component.ts index be120060210a28ad1dab0a961ffb98fd2aef51d3..dac57368eaa1224fe329a78ee8ee779e7e2a83ed 100644 --- a/src/app/form/form-view/structure-form/structure-form.component.ts +++ b/src/app/form/form-view/structure-form/structure-form.component.ts @@ -11,7 +11,7 @@ import { structureFormStep } from './structureFormStep.enum'; @Component({ selector: 'app-structure-form', - templateUrl: './structure-form.component.html', + templateUrl: './structure-form.component.html' }) export class StructureFormComponent implements OnChanges, OnInit { @Input() nbSteps: number; @@ -50,11 +50,7 @@ export class StructureFormComponent implements OnChanges, OnInit { public publicsAccompaniment: Category; public publics: Category; - constructor( - private searchService: SearchService, - private profileService: ProfileService, - private route: ActivatedRoute - ) {} + constructor(private searchService: SearchService, private profileService: ProfileService, private route: ActivatedRoute) {} ngOnChanges(changes: SimpleChanges): void { if (changes.currentStep) { @@ -145,38 +141,38 @@ export class StructureFormComponent implements OnChanges, OnInit { // this.updatePageValid(); } else { this.pagesValidation[structureFormStep.structureChoice] = { - valid: this.structureForm.get('_id').valid, + valid: this.structureForm.get('_id').valid }; this.pagesValidation[structureFormStep.structureNameAndAddress] = { - valid: this.structureForm.get('structureName').valid && this.structureForm.get('address').valid, + valid: this.structureForm.get('structureName').valid && this.structureForm.get('address').valid }; this.pagesValidation[structureFormStep.structureContact] = { - valid: this.structureForm.get('contactMail').valid && this.structureForm.get('contactPhone').valid, + valid: this.structureForm.get('contactMail').valid && this.structureForm.get('contactPhone').valid }; this.pagesValidation[structureFormStep.structureAccompanimentChoice] = { - valid: this.structureForm.get('placeOfReception').valid, + valid: this.structureForm.get('placeOfReception').valid }; this.pagesValidation[structureFormStep.structureChoiceCompletion] = { - valid: this.isEditMode ? true : this.structureForm.get('choiceCompletion').valid, + valid: this.isEditMode ? true : this.structureForm.get('choiceCompletion').valid }; this.pagesValidation[structureFormStep.structureContactCompletion] = { valid: this.isEditMode ? true : this.structureForm.get('contactPersonFirstname').valid && this.structureForm.get('contactPersonLastname').valid && - this.structureForm.get('contactPersonEmail').valid, + this.structureForm.get('contactPersonEmail').valid }; this.pagesValidation[structureFormStep.structureType] = { - valid: this.structureForm.get('structureType').valid, + valid: this.structureForm.get('structureType').valid }; this.pagesValidation[structureFormStep.structureAccessModality] = { - valid: this.structureForm.get('accessModality').valid, + valid: this.structureForm.get('accessModality').valid }; this.pagesValidation[structureFormStep.structureHours] = { - valid: this.hoursForm.valid && this.structureForm.get('exceptionalClosures').valid, + valid: this.hoursForm.valid && this.structureForm.get('exceptionalClosures').valid }; this.pagesValidation[structureFormStep.structurePmr] = { - valid: this.structureForm.get('pmrAccess').valid, + valid: this.structureForm.get('pmrAccess').valid }; this.pagesValidation[structureFormStep.structureWebAndSocialNetwork] = { valid: @@ -184,23 +180,23 @@ export class StructureFormComponent implements OnChanges, OnInit { ((this.structureForm.get('facebook').valid && this.structureForm.get('twitter').valid && this.structureForm.get('instagram').valid) || - !this.showSocialNetwork), + !this.showSocialNetwork) }; this.pagesValidation[structureFormStep.structurePublicTarget] = { - valid: this.structureForm.get('publics').valid, + valid: this.structureForm.get('publics').valid }; this.pagesValidation[structureFormStep.structureDigitalHelpingAccompaniment] = { - valid: this.structureForm.get('proceduresAccompaniment').valid, + valid: this.structureForm.get('proceduresAccompaniment').valid }; this.pagesValidation[structureFormStep.structureTrainingType] = { - valid: true, + valid: true }; this.pagesValidation[structureFormStep.structureTrainingPrice] = { - valid: this.structureForm.get('freeWorkShop').valid, + valid: this.structureForm.get('freeWorkShop').valid }; this.pagesValidation[structureFormStep.structureWifi] = { - valid: this.structureForm.get('equipmentsAndServices').valid, + valid: this.structureForm.get('equipmentsAndServices').valid }; this.pagesValidation[structureFormStep.structureEquipments] = { valid: @@ -209,23 +205,23 @@ export class StructureFormComponent implements OnChanges, OnInit { this.structureForm.get('nbTablets').valid && this.structureForm.get('nbNumericTerminal').valid && this.structureForm.get('nbScanners').valid, - name: 'Equipements mis à disposition', + name: 'Equipements mis à disposition' }; this.pagesValidation[structureFormStep.structureLabels] = { - valid: true, + valid: true }; this.pagesValidation[structureFormStep.structureOtherServices] = { - valid: this.structureForm.get('equipmentsAndServices').valid, + valid: this.structureForm.get('equipmentsAndServices').valid }; this.pagesValidation[structureFormStep.structureDescription] = { - valid: true, + valid: true }; this.pagesValidation[structureFormStep.structureCovidInfo] = { - valid: true, + valid: true }; this.pagesValidation[structureFormStep.structureConsent] = { - valid: !this.isEditMode ? this.userAcceptSavedDate : true, + valid: !this.isEditMode ? this.userAcceptSavedDate : true }; this.updatePageValid(); } @@ -268,15 +264,7 @@ export class StructureFormComponent implements OnChanges, OnInit { }); } - public onCheckChange({ - event, - formControlName, - value, - }: { - event: boolean; - formControlName: string; - value: string; - }): void { + public onCheckChange({ event, formControlName, value }: { event: boolean; formControlName: string; value: string }): void { const formArray: UntypedFormArray = this.structureForm.get(formControlName) as UntypedFormArray; if (event) { // Add a new control in the arrayForm diff --git a/src/app/shared/components/hour-picker/hour-picker.component.html b/src/app/shared/components/hour-picker/hour-picker.component.html index e96f43944941e86a2decb5098bf223932fb83752..0cf68ef0890a48bf378ec1f8a4de557057831cb0 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.html +++ b/src/app/shared/components/hour-picker/hour-picker.component.html @@ -48,7 +48,7 @@ </div> </div> </div> - <div class="add" *ngIf="day.hours.length === 1"> + <div class="extraAction" *ngIf="day.hours.length === 1"> <app-button (action)="addHours(day)" [text]="'Ajouter'" @@ -57,6 +57,9 @@ [style]="buttonTypeEnum.Secondary" ></app-button> </div> + <div class="extraAction" *ngIf="day.hours.length === 2"> + <a (click)="this.removeHours(day, 1)">Supprimer</a> + </div> </div> </div> </div> diff --git a/src/app/shared/components/hour-picker/hour-picker.component.scss b/src/app/shared/components/hour-picker/hour-picker.component.scss index b285bc182cb183f913a6c50ab689186a0cc8ca79..94e347ca70240b2543cfe8c5dce751293a3478d3 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.scss +++ b/src/app/shared/components/hour-picker/hour-picker.component.scss @@ -35,11 +35,8 @@ grid-row-gap: 20px; } } - .add { + .extraAction { display: grid; - grid-template-columns: 96px 40px; - column-gap: 10px; - // grid-template-columns: 80px 100px; align-items: center; } diff --git a/src/app/shared/components/hour-picker/hour-picker.component.ts b/src/app/shared/components/hour-picker/hour-picker.component.ts index a66f69e29d30c708ba11f77f8552b3d58dcc5ca3..a4b6a43bf13d19ff0473b3b42162790544fb7277 100644 --- a/src/app/shared/components/hour-picker/hour-picker.component.ts +++ b/src/app/shared/components/hour-picker/hour-picker.component.ts @@ -8,7 +8,7 @@ import { CheckHours } from '../../validator/form'; @Component({ selector: 'app-hour-picker', templateUrl: './hour-picker.component.html', - styleUrls: ['./hour-picker.component.scss'], + styleUrls: ['./hour-picker.component.scss'] }) export class HourPickerComponent implements OnChanges, OnDestroy { @Input() modifiedFields: any; @@ -23,7 +23,7 @@ export class HourPickerComponent implements OnChanges, OnDestroy { private isInputSelected = false; public copiedDayName = ''; public structure = { - hours: this.initHoursDefault(), + hours: this.initHoursDefault() }; public structureHoursDefault: any[] = this.initHoursDefault(); @@ -45,44 +45,44 @@ export class HourPickerComponent implements OnChanges, OnDestroy { name: 'Lundi', hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, + active: false }, { name: 'Mardi', hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, + active: false }, { name: 'Mercredi', hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, + active: false }, { name: 'Jeudi', hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, + active: false }, { name: 'Vendredi', hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, + active: false }, { name: 'Samedi', hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, + active: false }, { name: 'Dimanche', hours: [{ start: '', end: '', error: 'incomplete' }], open: false, - active: false, - }, + active: false + } ]; } @@ -100,20 +100,20 @@ export class HourPickerComponent implements OnChanges, OnDestroy { return { start: hour.opening, end: hour.closing, - error: null, + error: null }; } else { if (hour.opening) { return { start: hour.opening, end: '', - error: 'incomplete', + error: 'incomplete' }; } else { return { start: '', end: hour.closing, - error: 'incomplete', + error: 'incomplete' }; } } @@ -125,21 +125,16 @@ export class HourPickerComponent implements OnChanges, OnDestroy { this.structure.hours = this.structureHoursDefault; } - private parseToDay(data: { - name: string; - hours: { start: string; end: string }[]; - open: boolean; - active: boolean; - }): Day { + private parseToDay(data: { name: string; hours: { start: string; end: string }[]; open: boolean; active: boolean }): Day { return new Day({ open: data.open, time: data.hours.map( (hour) => new Time({ opening: hour.start, - closing: hour.end, + closing: hour.end }) - ), + ) }); } @@ -151,7 +146,7 @@ export class HourPickerComponent implements OnChanges, OnDestroy { thursday: this.createDay(this.parseToDay(this.structure.hours[3])), friday: this.createDay(this.parseToDay(this.structure.hours[4])), saturday: this.createDay(this.parseToDay(this.structure.hours[5])), - sunday: this.createDay(this.parseToDay(this.structure.hours[6])), + sunday: this.createDay(this.parseToDay(this.structure.hours[6])) }); } @@ -214,7 +209,7 @@ export class HourPickerComponent implements OnChanges, OnDestroy { day.hours.push({ start: '', end: '', - error: 'incomplete', + error: 'incomplete' }); this.submitForm(); } @@ -225,6 +220,7 @@ export class HourPickerComponent implements OnChanges, OnDestroy { public removeHours(day: any, index: number): void { if (index > -1) { day.hours.splice(index, 1); + this.submitForm(); } } @@ -302,14 +298,14 @@ export class HourPickerComponent implements OnChanges, OnDestroy { private createDay(day: Day): UntypedFormGroup { return new UntypedFormGroup({ open: new UntypedFormControl(day.open, Validators.required), - time: new UntypedFormArray(day.time.map((oneTime) => this.createTime(oneTime))) as UntypedFormArray, + time: new UntypedFormArray(day.time.map((oneTime) => this.createTime(oneTime))) as UntypedFormArray }); } private createTime(time: Time): UntypedFormGroup { return new UntypedFormGroup({ opening: new UntypedFormControl(time.opening, Validators.required), - closing: new UntypedFormControl(time.closing, [Validators.required, CheckHours(time.opening)]), + closing: new UntypedFormControl(time.closing, [Validators.required, CheckHours(time.opening)]) }); } }