Skip to content

Commit

Permalink
fix(portail): add localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Dec 3, 2023
1 parent c34a1ed commit 33d9c4d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fileignoreconfig:
- filename: packages/portail-usagers/src/app/modules/general/components/_static/cgu/cgu.component.html
checksum: 584da8c9b8ebc95d1d996d0201e0e57cf31e05c6704104e7adacba67a7eb4dd7
- filename: packages/portail-usagers/src/app/modules/usager-auth/services/usager-auth.service.ts
checksum: d55d8d80cec2984b300d93cedc411653bb3c49d172cfb2c66e347ad49c715634
checksum: 628884c40a4907e9161c55bbd77110f15fad0504c7060a7be6be6612fe44daec
- filename: packages/portail-usagers/src/app/modules/usager-auth/usager-accept-cgu/usager-accept-cgu.component.ts
checksum: 189eb0e583dc89e07c097b61b59e3ee952d84b098dd0fd75bc7cd4bc71ab3fa5
- filename: yarn.lock
Expand Down
18 changes: 9 additions & 9 deletions packages/portail-usagers/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { NavigationEnd, Router } from "@angular/router";
import { filter } from "rxjs";
import { LIENS_PARTENAIRES } from "./modules/general/components/_static/plan-site/LIENS_PARTENAIRES.const";
import { PortailUsagerProfile } from "@domifa/common";
import { globalConstants } from "./shared";
import { MatomoTracker } from "ngx-matomo-client";

@Component({
Expand Down Expand Up @@ -38,26 +37,27 @@ export class AppComponent implements OnInit {
public matomoInfo: boolean;

public initMatomo(): void {
const matomo = globalConstants.getItem("matomo");
const matomo = localStorage.getItem("matomo");
const matomoOptedIn = localStorage.getItem("matomo-opted-in");
let disableMatomo = false;
this.matomoInfo = matomo === "done";

if (globalConstants.getItem("matomo-opted-in") === null) {
globalConstants.setItem("matomo-opted-in", JSON.stringify(true));
if (matomoOptedIn === null) {
localStorage.setItem("matomo-opted-in", JSON.stringify(true));
} else {
disableMatomo = JSON.parse(matomoOptedIn) === true;
}

const disableMatomo =
JSON.parse(globalConstants.getItem("matomo-opted-in")) === true;

if (!disableMatomo) {
this.matomo.optUserOut();
} else {
globalConstants.setItem("matomo-opted-in", JSON.stringify(true));
localStorage.setItem("matomo-opted-in", JSON.stringify(true));
}
}

public closeMatomo(): void {
this.matomoInfo = true;
globalConstants.setItem("matomo", "done");
localStorage.setItem("matomo", "done");
}

public ngOnInit(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component } from "@angular/core";
import { Title } from "@angular/platform-browser";
import { MatomoTracker } from "ngx-matomo-client";
import { globalConstants } from "../../../../../shared";

@Component({
selector: "app-politique",
Expand All @@ -21,9 +20,9 @@ export class PolitiqueComponent {
handleChange(optOut: any) {
if (optOut) {
this.tracker.optUserOut();
globalConstants.setItem("matomo-opted-in", false);
localStorage.setItem("matomo-opted-in", JSON.stringify(false));
} else {
globalConstants.setItem("matomo-opted-in", true);
localStorage.setItem("matomo-opted-in", JSON.stringify(true));
this.tracker.forgetUserOptOut();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BehaviorSubject, catchError, map, Observable, of } from "rxjs";
import { environment } from "../../../../environments/environment";
import { PortailUsagerAuthLoginForm } from "../../../../_common";
import { configureScope } from "@sentry/angular";
import { globalConstants } from "../../../shared";

import {
PortailUsagerProfile,
PortailUsagerAuthApiResponse,
Expand Down Expand Up @@ -66,7 +66,7 @@ export class UsagerAuthService {

public logout(): void {
this.currentUsagerSubject.next(null);
globalConstants.clearStorage();
localStorage.clearStorage();

configureScope((scope) => {
scope.setTag("profil-usager", "none");
Expand All @@ -92,13 +92,13 @@ export class UsagerAuthService {
}

public getToken(): string | null {
return globalConstants.getItem(TOKEN_KEY);
return localStorage.getItem(TOKEN_KEY);
}

public saveToken(apiAuthResponse: PortailUsagerAuthApiResponse): void {
// Enregistrement du token
globalConstants.removeItem(TOKEN_KEY);
globalConstants.setItem(TOKEN_KEY, apiAuthResponse.token);
localStorage.removeItem(TOKEN_KEY);
localStorage.setItem(TOKEN_KEY, JSON.stringify(apiAuthResponse.token));

// Build usager
this.saveAuthUsager(apiAuthResponse.profile);
Expand All @@ -112,8 +112,8 @@ export class UsagerAuthService {

public saveAuthUsager(authUsagerProfile: PortailUsagerProfile): void {
// Enregistrement de l'utilisateur
globalConstants.removeItem(USER_KEY);
globalConstants.setItem(USER_KEY, JSON.stringify(authUsagerProfile));
localStorage.removeItem(USER_KEY);
localStorage.setItem(USER_KEY, JSON.stringify(authUsagerProfile));

// Sentry
configureScope((scope) => {
Expand Down
60 changes: 0 additions & 60 deletions packages/portail-usagers/src/app/shared/global-constants.class.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/portail-usagers/src/app/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
//@index('./*', f => `export * from '${f.path}'`)
export * from "./global-constants.class";
export * from "./MATOMO_INJECTORS.const";

0 comments on commit 33d9c4d

Please sign in to comment.