Skip to content

Commit

Permalink
feat(frontend): add sort by rdv date
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Jan 9, 2025
1 parent dd24461 commit 05ad965
Show file tree
Hide file tree
Showing 24 changed files with 103 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
import { StructureTable } from "../structure/StructureTable.typeorm";
import { AppTypeormTable } from "../_core/AppTypeormTable.typeorm";
import { UsagerTable } from "./UsagerTable.typeorm";
import { UsagerRdv } from "@domifa/common/dist/usager/interfaces/UsagerRdv.interface";
import {
UsagerAyantDroit,
UsagerDecision,
UsagerEntretien,
UsagerRdv,
UsagerSexe,
UsagerTypeDom,
} from "@domifa/common";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import fr from "date-fns/locale/fr";
import { format } from "date-fns";
import { ETAPE_ENTRETIEN, type UsagerRdv, type UsagerRdvInfos } from "../..";
import { ETAPE_ENTRETIEN, type UsagerRdv, type UsagerRdvInfo } from "../..";

export const getRdvInfos = (usager?: {
export const getRdvInfo = (usager?: {
etapeDemande: number;
rdv: UsagerRdv | null;
}): UsagerRdvInfos => {
const rdvDisplay: UsagerRdvInfos = {
display: false,
}): UsagerRdvInfo => {
const rdvDisplay: UsagerRdvInfo = {
class: "",
content: "",
};

if (!usager?.rdv?.dateRdv) {
return rdvDisplay;
}

if (usager.etapeDemande && usager.etapeDemande < ETAPE_ENTRETIEN) {
if (
usager?.etapeDemande &&
usager?.etapeDemande < ETAPE_ENTRETIEN &&
usager?.rdv?.dateRdv
) {
const dateRdv = new Date(usager.rdv.dateRdv);

rdvDisplay.display = true;
rdvDisplay.content = `${format(dateRdv, "dd MMMM yyyy", {
locale: fr,
})} à ${format(dateRdv, "HH:mm")}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/usager/functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @index('./*.ts', f => `export * from '${f.path}'`)
export * from "./generateMotifLabel.service";
export * from "./getRdvInfos.service";
export * from "./getRdvInfo.service";
export * from "./getUsagerNomComplet";
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
ETAPE_DOSSIER_COMPLET,
ETAPE_DECISION,
} from "../../constants";

import { getRdvInfos } from "../getRdvInfos.service";
import { getRdvInfo } from "../getRdvInfo.service";

beforeAll(() => {
jest.useFakeTimers();
Expand All @@ -26,14 +25,14 @@ describe("Création des rendez-vous", () => {
};

usager.etapeDemande = ETAPE_RENDEZ_VOUS;
expect(getRdvInfos(usager)).toEqual({
expect(getRdvInfo(usager)).toEqual({
class: "warning",
content: "20 mars 2021 à 19:20",
display: true,
});

usager.etapeDemande = ETAPE_DOSSIER_COMPLET;
expect(getRdvInfos(usager)).toEqual({
expect(getRdvInfo(usager)).toEqual({
class: "",
content: "",
display: false,
Expand All @@ -53,14 +52,14 @@ describe("Création des rendez-vous", () => {
};

usager.etapeDemande = ETAPE_RENDEZ_VOUS;
expect(getRdvInfos(usager)).toEqual({
expect(getRdvInfo(usager)).toEqual({
class: "danger",
content: "20 juillet 2020 à 19:20",
display: true,
});

usager.etapeDemande = ETAPE_DECISION;
expect(getRdvInfos(usager)).toEqual({
expect(getRdvInfo(usager)).toEqual({
class: "",
content: "",
display: false,
Expand All @@ -70,28 +69,28 @@ describe("Création des rendez-vous", () => {
it("Rendez-vous de base", () => {
const usager = USAGER_VALIDE_MOCK;
usager.rdv = { dateRdv: null, userId: 0, userName: "" };
expect(getRdvInfos(usager)).toEqual({
expect(getRdvInfo(usager)).toEqual({
class: "",
content: "",
display: false,
});

usager.rdv.dateRdv = null;
expect(getRdvInfos(usager)).toEqual({
expect(getRdvInfo(usager)).toEqual({
class: "",
content: "",
display: false,
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
usager.rdv = null as any;
expect(getRdvInfos(usager)).toEqual({
expect(getRdvInfo(usager)).toEqual({
class: "",
content: "",
display: false,
});

expect(getRdvInfos()).toEqual({
expect(getRdvInfo()).toEqual({
class: "",
content: "",
display: false,
Expand Down
5 changes: 3 additions & 2 deletions packages/common/src/usager/interfaces/Usager.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { type UsagerAyantDroit } from "./UsagerAyantDroit.interface";
import { type UsagerDecision } from "./UsagerDecision.interface";
import { type UsagerEntretien } from "./UsagerEntretien.interface";
import { type UsagerLastInteraction } from "./UsagerLastInteraction.interface";
import { type UsagerRdv } from "./UsagerRdv.interface";
import { UsagerRdvInfo } from "./rdv";
import { type UsagerRdv } from "./rdv/UsagerRdv.interface";

export interface Usager extends AppEntity {
ref: number; // unique par structure
Expand Down Expand Up @@ -58,6 +59,6 @@ export interface Usager extends AppEntity {
nbNotes?: number;
statusInfos?: any;
echeanceInfos?: any;
rdvInfos?: any;
rdvInfo?: UsagerRdvInfo;
migrated?: boolean;
}
3 changes: 1 addition & 2 deletions packages/common/src/usager/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./rdv";
export * from "./Usager.interface";
export * from "./UsagerAyantDroit.interface";
export * from "./UsagerDecision.interface";
export * from "./UsagerDoc.interface";
export * from "./UsagerEntretien.interface";
export * from "./UsagerLastInteraction.interface";
export * from "./UsagerNote.interface";
export * from "./UsagerRdv.interface";
export * from "./UsagerRdvInfos.interface";
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface UsagerRdvInfos {
display: boolean;
export interface UsagerRdvInfo {
class: "danger" | "warning" | "";
content: string;
}
3 changes: 3 additions & 0 deletions packages/common/src/usager/interfaces/rdv/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./UsagerRdv.interface";
export * from "./UsagerRdvInfo.interface";
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type UsagerLight = AppEntity &
| "contactByPhone"
| "import"
| "echeanceInfos"
| "rdvInfos"
| "rdvInfo"
| "pinnedNote"
| "datePremiereDom"
| "nbNotes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
[id]="'distribution-' + usager.ref"
[attr.aria-label]="
'Distribuer ' +
usager.totalInteractionsEnAttente +
usager.standByInteractions +
' courriers de ' +
(usager | usagerNomComplet)
"
Expand All @@ -111,7 +111,7 @@
>
<span class="icon-distribution list-icon"></span>
<strong class="notification">
{{ usager.totalInteractionsEnAttente }}
{{ usager.standByInteractions }}
</strong>
</button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,22 @@
scope="col"
role="columnheader"
*ngIf="filters.statut === 'INSTRUCTION'"
class="clickable"
>
Rendez-vous le
<button
type="button"
[ngClass]="filters.sortKey === 'RDV' ? 'fw-bold text-primary' : ''"
[attr.aria-sort]="filters.sortKey ==='RDV' ? ARIA_SORT[filters.sortValue] : 'none'"
(click)="updateFilters.emit({element: 'sortKey', value: 'RDV'})"
>
<span class="visually-hidden">Trier par</span>
Rendez-vous le
<app-table-head-sort-icon
[sortKey]="filters.sortKey"
[sortValue]="filters.sortValue"
currentKey="RDV"
></app-table-head-sort-icon>
</button>
</th>
<th class="clickable" role="columnheader" scope="col">
<button
Expand Down Expand Up @@ -283,7 +297,7 @@
</p>
</td>
<td class="clickable" *ngIf="filters.statut === 'INSTRUCTION'">
{{ usager.rdvInfos.content }}
{{ usager.rdvInfo.content }}
</td>
<td
*ngIf="filters.statut === 'VALIDE' || filters.statut === 'TOUS'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type UsagersFilterCriteriaSortKey =
| "PASSAGE"
| "NOM"
| "ECHEANCE"
| "RDV"
| "ID";

export type UsagersFilterCriteriaEntretien = "COMING" | "OVERDUE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ function sortBy(
return sortMultiple(usagers, asc, (usager) => {
const sortAttributes: SortableValue[] = [];

if (sortKey === "ECHEANCE") {
if (sortKey === "RDV" && usager?.rdv?.dateRdv) {
sortAttributes.push(new Date(usager?.rdv?.dateRdv));
} else if (sortKey === "ECHEANCE") {
sortAttributes.push(usager?.echeanceInfos?.dateToDisplay ?? null);
} else if (sortKey === "PASSAGE") {
sortAttributes.push(usager?.lastInteraction?.dateInteraction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class SortLabelPipe implements PipeTransform {
| ((statut?: string) => string);
} = {
NOM: "nom",
RDV: "date de rendez-vous",
ECHEANCE: (statut?: string) => {
if (statut === "RADIE") return "radiation";
if (statut === "REFUS") return "refus";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@
<div aria-hidden="true" class="svg-icon icon-danger"></div>
<p class="text-danger">
<b
>Demande refusée
<ng-container *ngIf="usager?.echeanceInfos?.dateToDisplay">
le
{{
usager?.echeanceInfos?.dateToDisplay | date : "dd MMMM yyyy"
}}</ng-container
></b
>
>Demande refusée le
{{ usager.decision.dateDecision | date : "dd MMMM yyyy" }}
</b>
<br />
{{ usager.decision.motifString }}
</p>
Expand All @@ -63,8 +58,8 @@
<div
class="alert"
[ngClass]="
usager.rdvInfos.class
? 'alert-' + usager.rdvInfos.class
usager.rdvInfo.class
? 'alert-' + usager.rdvInfo.class
: 'alert-info'
"
*ngIf="
Expand All @@ -80,8 +75,8 @@
}}
actuellement en cours
{{
usager.rdvInfos.display
? ": rendez-vous le " + usager.rdvInfos.content
usager.rdvInfo.content
? ": rendez-vous le " + usager.rdvInfo.content
: ""
}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { CountryISO } from "@khazii/ngx-intl-tel-input";
import { Entretien, Rdv, Decision, Options } from ".";
import { UsagerEcheanceInfos, Telephone } from "../../../../_common/model";

import { getEcheanceInfos } from "../utils";
import { countStandByInteractions, getEcheanceInfos } from "../utils";
import {
ETAPE_ETAT_CIVIL,
USAGER_DECISION_STATUT_COLORS,
USAGER_DECISION_STATUT_LABELS,
UsagerSexe,
UsagerTypeDom,
UsagerAyantDroit,
INTERACTIONS_IN,
getRdvInfos,
getRdvInfo,
UsagerDecision,
UsagerRdvInfos,
UsagerRdvInfo,
UsagerNote,
Usager,
UsagerDecisionStatut,
Expand Down Expand Up @@ -52,12 +51,12 @@ export class UsagerFormModel implements Usager {
recommandeIn: number;
colisIn: number;
};
public totalInteractionsEnAttente: number;
public standByInteractions: number;

public options: Options;

public echeanceInfos: UsagerEcheanceInfos;
public rdvInfos: UsagerRdvInfos;
public rdvInfo: UsagerRdvInfo;

public statusInfo: {
text: string;
Expand Down Expand Up @@ -148,14 +147,11 @@ export class UsagerFormModel implements Usager {
color: USAGER_DECISION_STATUT_COLORS[this.decision.statut],
};
this.echeanceInfos = getEcheanceInfos(usager);
this.rdvInfos = getRdvInfos({
this.rdvInfo = getRdvInfo({
rdv: this.rdv,
etapeDemande: this.etapeDemande,
});

this.totalInteractionsEnAttente = 0;
INTERACTIONS_IN.forEach((interaction) => {
this.totalInteractionsEnAttente += this.lastInteraction[interaction];
});
this.standByInteractions = countStandByInteractions(this.lastInteraction);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { INTERACTIONS_IN, UsagerLastInteraction } from "@domifa/common";

export const countStandByInteractions = (
lastInteraction: UsagerLastInteraction
): number => {
let standByInteractions = 0;
INTERACTIONS_IN.forEach((interaction) => {
standByInteractions += lastInteraction[interaction];
});
return standByInteractions;
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @index('./*service.ts', f => `export * from '${f.path}'`)
export * from "./getEcheanceInfos.service";
export * from "./countStanbyInteractions";
export * from "./getUrlUsagerProfil.service";
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ describe("formatInternationalPhoneNumber", () => {
// 06 98 XX XX XX - mobiles fictifs
{
input: { numero: "0698001122", countryCode: "FR" },
expected: "+33 6 98 00 11 22",
expected: "06 98 00 11 22",
},
{
input: { numero: "0698999999", countryCode: "FR" },
expected: "+33 6 98 99 99 99",
expected: "06 98 99 99 99",
},
// 01 99 XX XX XX - fixes fictifs
{
input: { numero: "0199001122", countryCode: "FR" },
expected: "+33 1 99 00 11 22",
expected: "01 99 00 11 22",
},
{
input: { numero: "0199999999", countryCode: "FR" },
expected: "+33 1 99 99 99 99",
expected: "01 99 99 99 99",
},
])(
"devrait formater correctement le numéro fictif $input.numero",
Expand Down
Loading

0 comments on commit 05ad965

Please sign in to comment.