Skip to content

Commit

Permalink
refactor(frontend): add format phone in a standalone component
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Feb 15, 2024
1 parent 69fcabf commit a0c3259
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class UsagersController {

@UseGuards(UsagerAccessGuard)
@AllowUserStructureRoles("simple", "responsable", "admin", "facteur")
@Post("contact-details/:usagerRef")
@Patch("contact-details/:usagerRef")
public async patchMailAndPhone(
@Body() contactDetails: ContactDetailsDto,
@CurrentUser() _user: UserStructureAuthenticated,
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"extractLicenses": false,
"buildOptimizer": false,
"sourceMap": true,
"optimization": true,
"optimization": false,
"namedChunks": true
},
"configurations": {
Expand All @@ -49,7 +49,7 @@
"buildOptimizer": false
},
"analyze": {
"optimization": true,
"optimization": false,
"outputHashing": "all",
"sourceMap": true,
"namedChunks": true,
Expand All @@ -72,7 +72,7 @@
"with": "./src/environments/environment.prod.ts"
}
],
"optimization": true,
"optimization": false,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<p class="my-2">
<b>Téléphone:</b>
<span class="valeur" *ngIf="usager.telephone.numero">{{
usager.telephone | formatInternationalPhoneNumber
}}</span>
<span class="valeur" *ngIf="!usager.telephone.numero">Non renseigné</span>
</p>
<p class="my-2">
<b>Adresse e-mail:</b>
<span *ngIf="usager.email">
{{ usager.email }}
</span>
<span *ngIf="!usager.email">Non renseigné</span>
</p>
<p class="my-2">
<b>Notifications par SMS activés: </b>
<span>
{{ usager.contactByPhone ? "oui" : "non" }}
</span>
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { DisplayContactDetailsDecisionComponent } from "./display-contact-details-decision.component";
import { USAGER_ACTIF_MOCK } from "../../../../../_common/mocks";
import { UsagerFormModel } from "../../../usager-shared/interfaces";
import { FormatInternationalPhoneNumberPipe } from "../../../usager-shared/formatInternationalPhoneNumber.pipe";

describe("DisplayContactDetailsDecisionComponent", () => {
let component: DisplayContactDetailsDecisionComponent;
let fixture: ComponentFixture<DisplayContactDetailsDecisionComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [DisplayContactDetailsDecisionComponent],
imports: [FormatInternationalPhoneNumberPipe],
}).compileComponents();

fixture = TestBed.createComponent(DisplayContactDetailsDecisionComponent);
component = fixture.componentInstance;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
fixture.detectChanges();
});

it("should create", () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component, Input } from "@angular/core";
import { UsagerFormModel } from "../../../usager-shared/interfaces";

@Component({
selector: "app-display-contact-details-decision",
templateUrl: "./display-contact-details-decision.component.html",
})
export class DisplayContactDetailsDecisionComponent {
@Input() public usager!: UsagerFormModel;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,6 @@
{{ usager.numeroDistribution || "Non renseigné" }}
</span>
</p>

<div class="my-4">
<div class="py-2 text-primary fw-bold">Contact</div>
<p class="my-2">
<b>Téléphone:</b>
<span class="valeur" *ngIf="usager.telephone.numero">{{
usager.telephone | formatInternationalPhoneNumber
}}</span>
<span class="valeur" *ngIf="!usager.telephone.numero">Non renseigné</span>
</p>
<p class="my-2">
<b>Adresse e-mail:</b>
<span *ngIf="usager.email">
{{ usager.email }}
</span>
<span *ngIf="!usager.email">Non renseigné</span>
</p>
<p class="my-2">
<b>Notifications par SMS activés: </b>
<span>
{{ usager.contactByPhone ? "oui" : "non" }}
</span>
</p>
</div>
</ng-container>

<ng-container *ngIf="section === 'AYANTS_DROIT'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { NO_ERRORS_SCHEMA } from "@angular/core";

import { DisplayEtatCivilDecisionComponent } from "./display-etat-civil-decision.component";
import { FormatInternationalPhoneNumberPipe } from "../../../usager-shared/formatInternationalPhoneNumber.pipe";
import { USAGER_ACTIF_MOCK } from "../../../../../_common/mocks";
import { UsagerFormModel } from "../../../usager-shared/interfaces";

describe("DisplayEtatCivilDecisionComponent", () => {
let component: DisplayEtatCivilDecisionComponent;
Expand All @@ -16,6 +18,7 @@ describe("DisplayEtatCivilDecisionComponent", () => {
});
fixture = TestBed.createComponent(DisplayEtatCivilDecisionComponent);
component = fixture.componentInstance;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
});

it("can load instance", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ <h3 *ngIf="!editInfos">Ayants-droits</h3>
>l'état-civil et et ayant-droits</span
>
</button>

<button
class="btn btn-outline-primary d-print-none"
*ngIf="editInfos"
Expand All @@ -82,6 +81,50 @@ <h3 *ngIf="!editInfos">Ayants-droits</h3>
[usager]="usager"
[(editInfos)]="editInfos"
></app-profil-etat-civil-form>
<div class="row">
<div class="col"><h3>Informations de contact</h3></div>
<div class="col text-end">
<button
class="btn btn-outline-primary d-print-none"
*ngIf="!editContactDetails"
type="button"
(click)="editContactDetails = true"
>
<fa-icon
[icon]="['far', 'edit']"
aria-hidden="true"
class="me-2"
></fa-icon>
Modifier
<span class="visually-hidden">les informatiosn de contact</span>
</button>
<button
class="btn btn-outline-primary d-print-none"
*ngIf="editContactDetails"
type="button"
(click)="editContactDetails = false"
>
<fa-icon
[icon]="['fas', 'times']"
aria-hidden="true"
class="me-2"
></fa-icon>
Annuler
</button>
</div>
<div class="col-12">
<app-display-contact-details-decision
[usager]="usager"
*ngIf="!editContactDetails"
></app-display-contact-details-decision>
<app-form-contact-details
[usager]="usager"
*ngIf="editContactDetails"
[(editContactDetails)]="editContactDetails"
></app-form-contact-details>
</div>
</div>

<hr />
<div class="row">
<div class="col-md-12">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class StepDecisionComponent
{
public isAdmin: boolean;
public editInfos: boolean;
public editContactDetails = false;
public editEntretien: boolean;
public editPJ: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { DecisionValideFormComponent } from "./components/decision-valide-form/d
import { UsagerNotesModule } from "../usager-notes/usager-notes.module";
import { BaseUsagerDossierPageComponent } from "./components/base-usager-dossier-page/base-usager-dossier-page.component";
import { FormatInternationalPhoneNumberPipe } from "../usager-shared/formatInternationalPhoneNumber.pipe";
import { DisplayContactDetailsDecisionComponent } from "./components/display-contact-details-decision/display-contact-details-decision.component";

@NgModule({
declarations: [
Expand All @@ -43,6 +44,7 @@ import { FormatInternationalPhoneNumberPipe } from "../usager-shared/formatInter
DecisionValideFormComponent,
DecisionRefusFormComponent,
BaseUsagerDossierPageComponent,
DisplayContactDetailsDecisionComponent,
],
imports: [
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
} from "../shared/services";
import { ProfilHistoriqueLoginPortailComponent } from "./components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component";
import { SetNpaiComponent } from "./components/_general-section/set-npai/set-npai.component";
import { FormContactDetailsComponent } from "./components/_general-section/form-contact-details/form-contact-details.component";

import { DisplayContactDetailsComponent } from "./components/_general-section/display-contact-details/display-contact-details.component";
import { NgxIntlTelInputModule } from "@khazii/ngx-intl-tel-input";
import { FormatInternationalPhoneNumberPipe } from "../usager-shared/formatInternationalPhoneNumber.pipe";
Expand Down Expand Up @@ -66,7 +66,6 @@ import { FormatInternationalPhoneNumberPipe } from "../usager-shared/formatInter
ProfilHistoriqueDecisionsComponent,
ProfilHistoriqueLoginPortailComponent,
SetNpaiComponent,
FormContactDetailsComponent,
DisplayContactDetailsComponent,
],
imports: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { ComponentFixture, TestBed } from "@angular/core/testing";
import { FormContactDetailsComponent } from "./form-contact-details.component";
import { ReactiveFormsModule, FormsModule } from "@angular/forms";
import { RouterTestingModule } from "@angular/router/testing";
import { SharedModule } from "../../../../shared/shared.module";
import { SharedModule } from "../../../shared/shared.module";
import { APP_BASE_HREF } from "@angular/common";
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { StoreModule } from "@ngrx/store";
import { _usagerReducer } from "../../../../../shared";
import { NGRX_PROVIDERS_TESTING } from "../../../../../shared/store/tests";
import { UsagerFormModel } from "../../../../usager-shared/interfaces";
import { USAGER_ACTIF_MOCK } from "../../../../../../_common/mocks";
import { _usagerReducer } from "../../../../shared";
import { NGRX_PROVIDERS_TESTING } from "../../../../shared/store/tests";
import { UsagerFormModel } from "../../interfaces";
import { USAGER_ACTIF_MOCK } from "../../../../../_common/mocks";

describe("FormContactDetailsComponent", () => {
let component: FormContactDetailsComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ import {
Telephone,
UsagerEtatCivilFormData,
UserStructure,
} from "../../../../../../_common/model";
} from "../../../../../_common/model";

import {
setFormPhone,
mobilePhoneValidator,
getFormPhone,
} from "../../../../shared/phone";
import { AuthService, CustomToastService } from "../../../../shared/services";
import { UsagerFormModel } from "../../../../usager-shared/interfaces";
import { UsagerService } from "../../../../usager-shared/services";
} from "../../../shared/phone";
import { AuthService, CustomToastService } from "../../../shared/services";
import { UsagerFormModel } from "../../interfaces";
import { UsagerService } from "../../services";
import {
CountryISO,
PhoneNumberFormat,
SearchCountryField,
} from "@khazii/ngx-intl-tel-input";

import { Observable, Subscription } from "rxjs";
import { PREFERRED_COUNTRIES, EmailValidator } from "../../../../../shared";
import { PREFERRED_COUNTRIES, EmailValidator } from "../../../../shared";

@Component({
selector: "app-form-contact-details",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class UsagerService {
): Observable<UsagerLight> {
return this.http
.patch<UsagerLight>(
`${this.endPointUsagers}/contact-detail/${ref}`,
`${this.endPointUsagers}/contact-details/${ref}`,
formData
)
.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
CustomDatepickerI18n,
} from "../shared/services";
import { DisplayAyantsDroitsComponent } from "./components/display-ayants-droits/display-ayants-droits.component";
import { FormContactDetailsComponent } from "./components/form-contact-details/form-contact-details.component";

@NgModule({
declarations: [
Expand All @@ -47,6 +48,7 @@ import { DisplayAyantsDroitsComponent } from "./components/display-ayants-droits
DecisionRadiationFormComponent,
DeleteUsagerComponent,
DisplayAyantsDroitsComponent,
FormContactDetailsComponent,
],
imports: [
CommonModule,
Expand All @@ -73,6 +75,7 @@ import { DisplayAyantsDroitsComponent } from "./components/display-ayants-droits
DisplayDuplicatesUsagerComponent,
DeleteUsagerComponent,
DecisionRadiationFormComponent,
FormContactDetailsComponent,
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/assets/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ caption {
.step-form {
background-color: white;
padding: 1.4rem 1rem;
max-width: 940px;
max-width: 1040px;
margin: 1rem auto;
border: 1px solid #d1d1d1;
border-radius: 5px;
border-radius: 4px;
}

.tooltip.show {
Expand Down

0 comments on commit a0c3259

Please sign in to comment.