Skip to content

Commit

Permalink
fix(history): fix date displayed on history
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Oct 25, 2023
1 parent d2b44be commit 9926b65
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,10 @@
</p>
<div>
<a
[routerLink]="['/usager/' + usager.ref + '/edit']"
[routerLink]="['/usager/' + usager.ref + '/edit/decision']"
class="btn btn-light"
ariaCurrentWhenActive="page"
>
<fa-icon
[icon]="['fas', 'redo']"
aria-hidden="true"
class="me-2"
></fa-icon>
Voir le récapitulatif
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ <h2>Historique des décisions</h2>
</thead>
<tbody>
<tr
*ngFor="let histo of usager.historique; let i = index"
*ngFor="
let histo of usager.historique | orderByDate : 'desc';
let i = index
"
[attr.aria-rowindex]="i + 1"
>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import { USER_STRUCTURE_MOCK } from "../../../../../../_common/mocks/USER_STRUCT
import { UsagerFormModel } from "../../../../usager-shared/interfaces";
import { StoreModule } from "@ngrx/store";
import { _usagerReducer } from "../../../../../shared";
import { OrderByDatePipe } from "../../../pipes/order-by-date.pipe";

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

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ProfilHistoriqueComponent],
declarations: [ProfilHistoriqueComponent, OrderByDatePipe],
imports: [
FormsModule,
HttpClientTestingModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Pipe, PipeTransform } from "@angular/core";

@Pipe({
name: "orderByDate",
})
export class OrderByDatePipe implements PipeTransform {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
transform(array: any[], sortOrder: string): any[] {
if (!array || array.length <= 1) {
return array;
}

return array.sort((a, b) => {
const dateA = new Date(a.dateDecision);
const dateB = new Date(b.dateDecision);

if (sortOrder === "asc") {
return dateA.getTime() - dateB.getTime();
} else {
return dateB.getTime() - dateA.getTime();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { ProfilHistoriqueComponent } from "./components/pages/profil-historique/
import { ProfilHistoriqueSmsComponent } from "./components/historiques/profil-historique-sms/profil-historique-sms.component";
import { ProfilHistoriqueProcurationsComponent } from "./components/historiques/profil-historique-procurations/profil-historique-procurations.component";
import { ProfilHistoriqueTransfertsComponent } from "./components/historiques/profil-historique-transferts/profil-historique-transferts.component";
import { OrderByDatePipe } from "./pipes/order-by-date.pipe";

@NgModule({
declarations: [
Expand All @@ -53,11 +54,10 @@ import { ProfilHistoriqueTransfertsComponent } from "./components/historiques/pr
ProfilDocumentsSectionComponent,
ProfilGeneralHistoriqueCourriersComponent,
DisplayEtatCivilComponent,

BaseUsagerProfilPageComponent,
ProfilHistoriqueProcurationsComponent,

ProfilHistoriqueTransfertsComponent,
OrderByDatePipe,
],
imports: [
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ export class DeleteUsagerMenuComponent implements OnInit, OnDestroy {
}

public getPreviousStatus(): void {
// On tri du plus récent au plus ancien
const historique: Decision[] = Object.assign([], this.usager.historique);

historique.sort((a, b) => {
return a.dateDecision.getTime() - b.dateDecision.getTime();
});

const statut = historique[historique.length - 2].statut;

this.previousStatus = USAGER_DECISION_STATUT_LABELS[statut];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { fadeInOut } from "../../../../shared";
import { UsagerLight } from "./../../../../../_common/model/usager/UsagerLight.type";
import { Component, Input } from "@angular/core";

@Component({
selector: "app-display-duplicates-usager",
templateUrl: "./display-duplicates-usager.component.html",
styleUrls: ["./display-duplicates-usager.component.css"],
animations: [fadeInOut],
})
export class DisplayDuplicatesUsagerComponent {
@Input() public duplicates: UsagerLight[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export class UsagerFormModel {

this.etapeDemande = usager?.etapeDemande || ETAPE_ETAT_CIVIL;
this.ayantsDroits = usager?.ayantsDroits || [];

this.typeDom = usager?.typeDom || "PREMIERE_DOM";

this.datePremiereDom = usager?.datePremiereDom
Expand All @@ -119,10 +118,6 @@ export class UsagerFormModel {
})
: [];

this.historique.sort((a, b) => {
return b.dateDecision.getTime() - a.dateDecision.getTime();
});

this.lastInteraction = {
dateInteraction: usager?.lastInteraction?.dateInteraction
? new Date(usager.lastInteraction.dateInteraction)
Expand Down

0 comments on commit 9926b65

Please sign in to comment.