Skip to content

Commit cb87fe6

Browse files
committed
fix(frontend): search remote usagers after a reload
1 parent 1883ba4 commit cb87fe6

File tree

5 files changed

+70
-36
lines changed

5 files changed

+70
-36
lines changed

packages/frontend/src/app/interceptors/server-error.interceptor.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import { Injectable, Injector } from "@angular/core";
1111
import { Observable, throwError, timer } from "rxjs";
1212
import { catchError, retry } from "rxjs/operators";
1313
import { AuthService } from "../modules/shared/services/auth.service";
14-
import { captureException } from "@sentry/angular";
14+
import { captureException, getCurrentScope } from "@sentry/angular";
1515
import { CustomToastService } from "../modules/shared/services";
1616
import { Router } from "@angular/router";
1717

18-
const MAX_RETRIES = 1;
19-
const RETRY_DELAY = 800;
20-
const ERROR_STATUS_CODES_TO_RETRY = [0, 408, 500, 502, 503, 504];
18+
const MAX_RETRIES = 2;
19+
const RETRY_DELAY = 1000;
20+
const ERROR_STATUS_CODES_TO_RETRY = [0, 408, 409, 444, 502, 503, 504, 520];
2121

2222
@Injectable({
2323
providedIn: "root",
@@ -33,6 +33,16 @@ export class ServerErrorInterceptor implements HttpInterceptor {
3333
const toastr = this.injector.get(CustomToastService);
3434
const router = this.injector.get(Router);
3535

36+
if (authService?.currentUserValue) {
37+
const user = authService.currentUserValue;
38+
getCurrentScope().setTag("structure", user?.structureId?.toString());
39+
getCurrentScope().setUser({
40+
email: user.email,
41+
username:
42+
"STRUCTURE " + user?.structureId?.toString() + " : " + user?.prenom,
43+
});
44+
}
45+
3646
return next.handle(request).pipe(
3747
retry({
3848
count: MAX_RETRIES,
@@ -66,11 +76,10 @@ export class ServerErrorInterceptor implements HttpInterceptor {
6676
} else if (error.status === 404) {
6777
toastr.error("La page que vous recherchez n'existe pas");
6878
router.navigate(["404"]);
69-
} else if (error.status >= 500) {
79+
} else {
7080
toastr.error(
7181
"Une erreur serveur est survenue. Nos équipes ont été notifiées."
7282
);
73-
captureException(error);
7483
}
7584
}
7685
this.logError(request, error);
@@ -84,14 +93,14 @@ export class ServerErrorInterceptor implements HttpInterceptor {
8493
}
8594

8695
private logError(request: HttpRequest<any>, error: HttpErrorResponse): void {
87-
captureException(error, { data: request });
88-
console.error("HTTP Error", {
96+
console.error(error.message, {
8997
status: error.status,
9098
statusText: error.statusText,
9199
url: error.url,
92100
message: error.message,
93101
error: error.error,
94102
request,
95103
});
104+
captureException(error, { data: request });
96105
}
97106
}

packages/frontend/src/app/modules/manage-usagers/components/manage-usagers-page/manage-usagers-page.component.ts

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
152152
if (!searchPageLoadedUsagersData.dataLoaded) {
153153
this.loadDataFromAPI();
154154
} else {
155+
if (
156+
searchPageLoadedUsagersData.usagersRadiesFirsts.length >=
157+
searchPageLoadedUsagersData.usagersRadiesTotalCount
158+
) {
159+
this.chargerTousRadies$.next(true);
160+
}
155161
this.updateComponentState(searchPageLoadedUsagersData);
156162
}
157163
}
@@ -167,29 +173,9 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
167173
map((value: string) => value.trim()),
168174
filter((value: string) => value !== this.filters.searchString),
169175
withLatestFrom(this.chargerTousRadies$),
170-
switchMap(([searchString, chargerTousRadies]) => {
171-
if (
172-
!chargerTousRadies &&
173-
searchString.length >= 3 &&
174-
(this.filters.statut === "TOUS" || this.filters.statut === "RADIE")
175-
) {
176-
this.searching = true;
177-
return this.usagerService
178-
.getSearchPageRemoteSearchRadies({
179-
searchString,
180-
})
181-
.pipe(
182-
catchError(() => {
183-
this.searching = false;
184-
this.toastr.error(
185-
"La recherche n'a pas abouti, merci de réessayer dans quelques instants"
186-
);
187-
return searchString;
188-
})
189-
);
190-
}
191-
return of(searchString);
192-
}),
176+
switchMap(([searchString, chargerTousRadies]) =>
177+
this.findRemoteUsagers(chargerTousRadies, searchString)
178+
),
193179
tap((searchString: string) => {
194180
this.filters.searchString = searchString ?? null;
195181
this.filters.page = 0;
@@ -226,12 +212,50 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
226212
return this.usagerService.getSearchPageUsagerData({
227213
chargerTousRadies,
228214
});
215+
}),
216+
switchMap(() => this.chargerTousRadies$),
217+
switchMap((chargerTousRadies) => {
218+
// Call remote usagers to update list
219+
if (!chargerTousRadies) {
220+
return this.findRemoteUsagers(
221+
chargerTousRadies,
222+
this.filters.searchString
223+
);
224+
}
225+
return of(chargerTousRadies);
229226
})
230227
)
231228
.subscribe()
232229
);
233230
}
234231

232+
private findRemoteUsagers(
233+
chargerTousRadies: boolean,
234+
searchString: string
235+
): Observable<string> {
236+
if (
237+
!chargerTousRadies &&
238+
searchString.length >= 3 &&
239+
(this.filters.statut === "TOUS" || this.filters.statut === "RADIE")
240+
) {
241+
this.searching = true;
242+
return this.usagerService
243+
.getSearchPageRemoteSearchRadies({
244+
searchString,
245+
})
246+
.pipe(
247+
catchError(() => {
248+
this.searching = false;
249+
this.toastr.error(
250+
"La recherche n'a pas abouti, merci de réessayer dans quelques instants"
251+
);
252+
return searchString;
253+
})
254+
);
255+
}
256+
return of(searchString);
257+
}
258+
235259
private updateComponentState(
236260
searchPageLoadedUsagersData: SearchPageLoadedUsagersData
237261
) {

packages/frontend/src/app/modules/usager-dossier/components/decision-valide-form/decision-valide-form.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class DecisionValideFormComponent implements OnInit, OnDestroy {
109109

110110
this.subscription.add(
111111
this.valideForm.get("customRef")?.valueChanges.subscribe((value) => {
112-
if (value) {
112+
if (value?.trim()) {
113113
this.checkDuplicatesRef(value);
114114
} else {
115115
this.duplicates = [];

packages/frontend/src/app/modules/usager-dossier/components/step-etat-civil/step-etat-civil.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ export class StepEtatCivilComponent
9292
}
9393
public isDuplicateName(): void {
9494
if (
95-
this.usagerForm.controls.nom.value &&
96-
this.usagerForm.controls.prenom.value
95+
this.usagerForm.controls.nom?.value?.trim() &&
96+
this.usagerForm.controls.prenom?.value?.trim()
9797
) {
9898
const params: {
9999
nom: string;
@@ -102,7 +102,7 @@ export class StepEtatCivilComponent
102102
} = {
103103
nom: this.usagerForm.controls.nom.value,
104104
prenom: this.usagerForm.controls.prenom.value,
105-
usagerRef: this.usager.ref || null,
105+
usagerRef: this.usager.ref ?? null,
106106
};
107107

108108
this.subscription.add(

packages/frontend/src/app/modules/usager-notes/components/usager-notes-actions/usager-notes-actions.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export class UsagerNotesActionsComponent implements OnDestroy {
7373
})
7474
.subscribe({
7575
next: () => {
76-
this.toastService.success("Note supprimée avec succès");
7776
this.closeModal();
77+
this.toastService.success("Note supprimée avec succès");
7878
},
7979
error: () => {
8080
this.toastService.error("Impossible de supprimer la note");
@@ -90,6 +90,7 @@ export class UsagerNotesActionsComponent implements OnDestroy {
9090
const message = this.note.archived
9191
? "Note désarchivée avec succès"
9292
: "Note archivée avec succès";
93+
9394
this.subscription.add(
9495
this.usagerNotesService
9596
.archiveNote({

0 commit comments

Comments
 (0)