Skip to content

Commit

Permalink
feat: add endDate to users
Browse files Browse the repository at this point in the history
  • Loading branch information
pabenest committed Nov 14, 2023
1 parent 7d0ffba commit 3fd421c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/app/core/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export class User {
firstName: string;
lastName: string;

role: UserRole = UserRole.writer;
role = UserRole.writer;
createdAt: string;
disabled: boolean;
endDate = "9999-12-31";

This comment has been minimized.

Copy link
@vincentlaine

vincentlaine Nov 15, 2023

Collaborator

Ce serait mieux de rendre la date optionnelle : Si pas de date c'est que l'utilisateur n'a pas de date limite.

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
<form [formGroup]="userForm" *ngIf="userForm">
<mat-form-field appearance="outline">
<mat-label>Prénom</mat-label>
<input matInput
placeholder="Saisir..."
formControlName="firstName"
maxlength="50"
required>
<input matInput placeholder="Saisir..." formControlName="firstName" maxlength="50" required>
<mat-error *ngIf="controls.firstName.hasError('required')">
Vous n'avez pas saisi de prénom.
</mat-error>
Expand All @@ -17,11 +13,7 @@

<mat-form-field appearance="outline">
<mat-label>Nom</mat-label>
<input matInput
placeholder="Saisir..."
formControlName="lastName"
maxlength="50"
required>
<input matInput placeholder="Saisir..." formControlName="lastName" maxlength="50" required>
<mat-error *ngIf="controls.lastName.hasError('required')">
Vous n'avez pas saisi de nom.
</mat-error>
Expand All @@ -32,11 +24,7 @@

<mat-form-field appearance="outline">
<mat-label>Email</mat-label>
<input matInput
placeholder="Saisir..."
formControlName="email"
maxlength="255"
required>
<input matInput placeholder="Saisir..." formControlName="email" maxlength="255" required>
<mat-error *ngIf="controls.email.hasError('required')">
Vous n'avez pas saisi d'email.
</mat-error>
Expand All @@ -50,27 +38,30 @@

<mat-form-field appearance="outline">
<mat-label>Rôle</mat-label>
<mat-select formControlName="role"
placeholder="Choisir..."
required>
<mat-select formControlName="role" placeholder="Choisir..." required>
<mat-option *ngFor="let role of userRole" [value]="role">{{ userRole_Fr[role] }}</mat-option>
</mat-select>
<mat-error *ngIf="controls.role.hasError('required')">
Vous n'avez pas choisi de rôle.
</mat-error>
</mat-form-field>

<mat-form-field appearance="outline">
<mat-label>Date de fin de validité</mat-label>
<input matInput formControlName="endDate" [matDatepicker]="endDatePicker" required>

This comment has been minimized.

Copy link
@vincentlaine

vincentlaine Nov 15, 2023

Collaborator

Cf commentaire précédent, pas besoin du required

<mat-datepicker-toggle matSuffix [for]="endDatePicker"></mat-datepicker-toggle>
<mat-datepicker #endDatePicker></mat-datepicker>
<mat-error *ngIf="controls.endDate.hasError('required')">
La date de fin de validité est obligatoire.
</mat-error>
</mat-form-field>

</form>
<div class="actions">
<button mat-stroked-button
color="accent"
*ngIf="isNewUser"
(click)="onCancel()">
<button mat-stroked-button color="accent" *ngIf="isNewUser" (click)="onCancel()">
Annuler
</button>
<button mat-flat-button
color="accent"
[disabled]="!userForm.valid || !userForm.dirty"
(click)="addUser()">
<button mat-flat-button color="accent" [disabled]="!userForm.valid || !userForm.dirty" (click)="addUser()">
{{ isNewUser ? 'Ajouter' : 'Modifier' }}
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export class UserFormComponent implements OnInit {
userRole = Object.keys(UserRole);
userRole_Fr = UserRole_Fr;

@Input() user: User = new User();
@Input() user = new User();
@Output() cancel: EventEmitter<boolean> = new EventEmitter<boolean>();

constructor(private _fb: FormBuilder,
private _userService: UserService) {
private _userService: UserService) {
}

ngOnInit(): void {
Expand Down Expand Up @@ -50,8 +50,9 @@ export class UserFormComponent implements OnInit {
isNewUser: [!this.user.email],
firstName: [this.user.firstName, [Validators.required, Validators.maxLength(50)]],
lastName: [this.user.lastName, [Validators.required, Validators.maxLength(50)]],
email: [{value: this.user.email, disabled: !!this.user.email}, [Validators.required, Validators.maxLength(255), Validators.email]],
role: [this.user.role, [Validators.required]]
email: [{ value: this.user.email, disabled: !!this.user.email }, [Validators.required, Validators.maxLength(255), Validators.email]],
role: [this.user.role, [Validators.required]],
endDate: [this.user.endDate, [Validators.required]],

This comment has been minimized.

Copy link
@vincentlaine

vincentlaine Nov 15, 2023

Collaborator

Pareil ici :)

});
}

Expand Down
5 changes: 4 additions & 1 deletion src/app/modules/material/material.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { MatExpansionModule } from '@angular/material/expansion';
import { MatLegacyAutocompleteModule as MatAutocompleteModule } from '@angular/material/legacy-autocomplete';
import { MatBadgeModule } from '@angular/material/badge';
import { MatLegacyTableModule as MatTableModule } from '@angular/material/legacy-table';
import { MatMomentDateModule } from '@angular/material-moment-adapter';
import { MAT_MOMENT_DATE_ADAPTER_OPTIONS, MatMomentDateModule } from '@angular/material-moment-adapter';
import { MatLegacyMenuModule as MatMenuModule } from '@angular/material/legacy-menu';
import { MatLegacySlideToggleModule as MatSlideToggleModule } from '@angular/material/legacy-slide-toggle';
import { MatButtonToggleModule } from '@angular/material/button-toggle';
Expand All @@ -30,6 +30,9 @@ import { MatButtonToggleModule } from '@angular/material/button-toggle';
MatTooltipModule, MatDialogModule, MatExpansionModule, MatAutocompleteModule, MatBadgeModule, MatTableModule, MatMenuModule,
MatSlideToggleModule, MatButtonToggleModule
],
providers: [
{ provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } }
],
exports: [
MatFormFieldModule, MatSelectModule, MatInputModule, MatButtonModule, MatIconModule, MatCardModule, MatDividerModule, MatSidenavModule,
MatProgressSpinnerModule, MatRadioModule, MatProgressBarModule, MatCheckboxModule, MatDatepickerModule,
Expand Down

1 comment on commit 3fd421c

@vincentlaine
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dans l'ensemble c'est ok sauf la date à rendre optionnelle.

Faut juste que t'essaie de choper la même config pour le lint du code histoire de pas avoir des modifications de mise en forme tout le temps. Je regarde ça cette aprem.

Please sign in to comment.