diff --git a/src/components/Consents/Consents.tsx b/src/components/Consents/Consents.tsx index 8b7a74491e18b96d95c977d075fdb9b9f067cd7c..3ee1795cd2e64bf942fb02059a99936283619954 100644 --- a/src/components/Consents/Consents.tsx +++ b/src/components/Consents/Consents.tsx @@ -14,8 +14,8 @@ import { DateTime } from 'luxon' import React, { useCallback, useEffect, useMemo, useState } from 'react' import { useWhoAmI } from '../../API' import { getAxiosXSRFHeader } from '../../axios.config' -import { IConsent } from '../../models/consent.model' -import { ConsentService } from '../../services/consent.service' +import { ISgeConsent } from '../../models/sgeConsent.model' +import { SgeConsentService } from '../../services/sgeConsent.service' import DownloadModal from './DownloadModal' import './agGridOverrides.scss' import styles from './consents.module.scss' @@ -27,13 +27,13 @@ const Consents: React.FC = () => { const [selectedNodes, setSelectedNodes] = useState<IRowNode[]>([]) const [isShowingSelection, setIsShowingSelection] = useState<boolean>(false) const [openDownloadModal, setOpenDownloadModal] = useState<boolean>(false) - const [consents, setConsents] = useState<IConsent[]>([]) + const [consents, setConsents] = useState<ISgeConsent[]>([]) const [page, setPage] = useState<number>(0) const [rowsPerPage, setRowsPerPage] = useState<number>(50) const [totalRows, setTotalRows] = useState<number>(50) const { data: user } = useWhoAmI() const consentService = useMemo(() => { - return new ConsentService() + return new SgeConsentService() }, []) const toggleOpenModal = useCallback(() => { diff --git a/src/components/Routes/Router.tsx b/src/components/Routes/Router.tsx index 64c8f6cbfaea33ba15f2932a25f06e4ace6bd55f..386cf72d8c9b990353d12ce696c3a5877b6c4bdd 100644 --- a/src/components/Routes/Router.tsx +++ b/src/components/Routes/Router.tsx @@ -24,9 +24,14 @@ export const links: Record< label: 'Prix', path: '/prices', }, - consents: { - label: 'Consentements', - path: '/consents', + sgeConsents: { + label: 'Consentements SGE', + path: '/consents/sge', + adminOnly: true, + }, + grdfConsents: { + label: 'Consentements GRDF', + path: '/consents/grdf', adminOnly: true, }, } @@ -52,7 +57,7 @@ const Router = () => { <Route path={links.prices.path} element={<Prices />} /> <Route path="/popups" element={<Popups />} /> {user.isAdmin && ( - <Route path={links.consents.path} element={<Consents />} /> + <Route path={links.sgeConsents.path} element={<Consents />} /> )} <Route path="/login" element={<Login />} /> <Route diff --git a/src/models/grdfConsent.ts b/src/models/grdfConsent.ts index f0d381e5f3ef575116f41168a6060d4f42564767..20490a5944af648682f40adf45779b75544956b4 100644 --- a/src/models/grdfConsent.ts +++ b/src/models/grdfConsent.ts @@ -1,4 +1,5 @@ import { DateTime } from 'luxon' + export interface IGrdfConsent extends Omit<GrdfConsentEntity, 'CreatedAt' | 'endDate' | 'inseeCode'> { startDate: DateTime diff --git a/src/models/consent.model.ts b/src/models/sgeConsent.model.ts similarity index 50% rename from src/models/consent.model.ts rename to src/models/sgeConsent.model.ts index 8c1714ae30c3b6af5970699bd0c9665758d6a9ba..fe09f1300080502b82424dd703dfef5283534ef0 100644 --- a/src/models/consent.model.ts +++ b/src/models/sgeConsent.model.ts @@ -1,11 +1,11 @@ import { DateTime } from 'luxon' -export interface IConsent - extends Omit<ConsentEntity, 'CreatedAt' | 'endDate' | 'inseeCode'> { +export interface ISgeConsent + extends Omit<SgeConsentEntity, 'CreatedAt' | 'endDate' | 'inseeCode'> { startDate: DateTime endDate: DateTime } -export interface ConsentEntity { +export interface SgeConsentEntity { ID: number CreatedAt: string endDate: string @@ -19,13 +19,13 @@ export interface ConsentEntity { safetyOnBoarding: boolean } -export interface IConsentPagination - extends Omit<ConsentPaginationEntity, 'rows'> { - rows: IConsent[] +export interface ISgeConsentPagination + extends Omit<SgeConsentPaginationEntity, 'rows'> { + rows: ISgeConsent[] } -export interface ConsentPaginationEntity { +export interface SgeConsentPaginationEntity { totalRows: number totalPages: number - rows: ConsentEntity[] + rows: SgeConsentEntity[] } diff --git a/src/services/consent.service.ts b/src/services/sgeConsent.service.ts similarity index 71% rename from src/services/consent.service.ts rename to src/services/sgeConsent.service.ts index 185b123064e38d2ce903f0fc177a80a9bd5cad1b..986e0fab8fad60acaa8bb7b872e1eb5cf3bac996 100644 --- a/src/services/consent.service.ts +++ b/src/services/sgeConsent.service.ts @@ -2,13 +2,13 @@ import axios, { AxiosRequestConfig } from 'axios' import { DateTime } from 'luxon' import { toast } from 'react-toastify' import { - ConsentEntity, - ConsentPaginationEntity, - IConsent, - IConsentPagination, -} from '../models/consent.model' + ISgeConsent, + ISgeConsentPagination, + SgeConsentEntity, + SgeConsentPaginationEntity, +} from '../models/sgeConsent.model' -export class ConsentService { +export class SgeConsentService { /** * Search for consents * @param search @@ -21,13 +21,13 @@ export class ConsentService { limit: number, page: number, axiosHeaders: AxiosRequestConfig - ): Promise<IConsentPagination | null> => { + ): Promise<ISgeConsentPagination | null> => { try { const { data } = await axios.get( - `/api/admin/consent?search=${search}&limit=${limit}&page=${page}`, + `/api/admin/sge/consent?search=${search}&limit=${limit}&page=${page}`, axiosHeaders ) - const consentPagination = data as ConsentPaginationEntity + const consentPagination = data as SgeConsentPaginationEntity return this.parseConsentPagination(consentPagination) } catch (e) { if (e.response.status === 403) { @@ -44,11 +44,11 @@ export class ConsentService { * Converts consent entity into consent * @param consentEntity */ - public parseConsent = (consentEntity: ConsentEntity): IConsent => { - const startDate: DateTime = DateTime.fromISO(consentEntity.CreatedAt, { + public parseConsent = (consentEntity: SgeConsentEntity): ISgeConsent => { + const startDate = DateTime.fromISO(consentEntity.CreatedAt, { zone: 'utc', }).setLocale('fr-FR') - const endDate: DateTime = DateTime.fromISO(consentEntity.endDate, { + const endDate = DateTime.fromISO(consentEntity.endDate, { zone: 'utc', }).setLocale('fr-FR') @@ -71,13 +71,13 @@ export class ConsentService { * @param consentPaginationEntity */ public parseConsentPagination = ( - consentPaginationEntity: ConsentPaginationEntity - ): IConsentPagination => { + consentPaginationEntity: SgeConsentPaginationEntity + ): ISgeConsentPagination => { const rows = consentPaginationEntity.rows.map(consent => this.parseConsent(consent) ) - const consentPagination: IConsentPagination = { + const consentPagination: ISgeConsentPagination = { rows: rows, totalRows: consentPaginationEntity.totalRows, totalPages: consentPaginationEntity.totalPages,