diff --git a/trash/assets/react.svg b/trash/assets/react.svg deleted file mode 100644 index 6c87de9..0000000 --- a/trash/assets/react.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/trash/core/api/fetcher.js b/trash/core/api/fetcher.js deleted file mode 100644 index 37a3e41..0000000 --- a/trash/core/api/fetcher.js +++ /dev/null @@ -1,37 +0,0 @@ -// manage empty response during PUT or POST request -const readJsonResponse = async response => { - try { - return await response.json(); - } catch (e) { - return {}; - } -}; - -export const fetcher = async (url, token, method, params, body) => { - const headers = { - Accept: "application/json", - "Content-Type": "application/json", - }; - - try { - const response = await fetch(params ? `${url}?${new URLSearchParams(params)}` : url, { - headers: token ? { ...headers, Authorization: `Bearer ${token}` } : headers, - method, - body: body ? JSON.stringify(body) : null, - }); - const { ok, status, statusText } = response; - if (ok) { - try { - const data = await readJsonResponse(response); - return { data, status, statusText }; - } catch (error) { - return { error: true, status, statusText: error.message }; - } - } else { - return { error: true, status, statusText }; - } - } catch (error) { - // network error - return { error: true, statusText: error.message }; - } -}; diff --git a/trash/core/api/index.js b/trash/core/api/index.js deleted file mode 100644 index a7dedb5..0000000 --- a/trash/core/api/index.js +++ /dev/null @@ -1,59 +0,0 @@ -import { fetcher } from "./fetcher"; - -const putRequest = url => body => token => fetcher(url, token, "PUT", null, body); -/* - const postRequest = (url) => (token) => (body) => - fetcher(url, token, "POST", body); -const deleteRequest = (url) => (token) => (body) => - fetcher(url, token, "DELETE", body); -*/ -const getRequest = url => params => token => fetcher(url, token, "GET", params, null); -const getAllContacts = apiUrl => token => getRequest(`${apiUrl}/api/contacts`)(null)(token); -const getAllCampaigns = apiUrl => token => getRequest(`${apiUrl}/api/campaigns`)(null)(token); -const getAllSurveyUnits = apiUrl => token => getRequest(`${apiUrl}/api/survey-units`)(null)(token); - -const getContacts = apiUrl => searchParams => token => - getRequest(`${apiUrl}/api/contacts/search`)(searchParams)(token); -const getContactById = apiUrl => id => token => getRequest(`${apiUrl}/api/contacts/${id}`)(null)(token); -const getContactAccreditations = apiUrl => id => token => - getRequest(`${apiUrl}/api/contacts/${id}/accreditations`)(null)(token); -const updateContact = apiUrl => (id, contactInfos) => token => - putRequest(`${apiUrl}/api/contacts/${id}`)(contactInfos)(token); -const getSources = apiUrl => token => getRequest(`${apiUrl}/api/sources`)(null)(token); - -// eslint-disable-next-line no-unused-vars -const getUsers = apiUrl => token => ({ - data: { - content: [ - { identifier: "1234", role: "admin" }, - { identifier: "5678", role: "gestionnaire" }, - ], - }, - //getRequest(`${apiUrl}/api/users`)(null)(token) -}); - -// eslint-disable-next-line no-unused-vars -const getSourceAccreditations = apiUrl => token => ({ - data: { content: [{ source: "Survey A" }, { source: "Survey B" }] }, - //getRequest(`${apiUrl}/api/user/source-accreditations`)(null)(token); -}); - -// eslint-disable-next-line no-unused-vars -const getUserRole = apiUrl => token => ({ - data: { role: "admin" }, - //getRequest(`${apiUrl}/api/user/role`)(null)(token); -}); - -export const API = { - getContactById, - getContactAccreditations, - getAllContacts, - getAllCampaigns, - getAllSurveyUnits, - getContacts, - updateContact, - getSourceAccreditations, - getUsers, - getUserRole, - getSources, -}; diff --git a/trash/core/configuration/env.js b/trash/core/configuration/env.js deleted file mode 100644 index f5a1025..0000000 --- a/trash/core/configuration/env.js +++ /dev/null @@ -1 +0,0 @@ -export const getEnvVar = key => window?._env_?.[key] || process.env[`REACT_APP_${key}`]; diff --git a/trash/core/configuration/get-configuration.js b/trash/core/configuration/get-configuration.js deleted file mode 100644 index 0310e30..0000000 --- a/trash/core/configuration/get-configuration.js +++ /dev/null @@ -1,13 +0,0 @@ -import { getEnvVar } from "./env"; - -const basePath = `${window.location.origin}`; - -const nameConfigFile = getEnvVar("NAME_CONFIG_FILE") ?? "configuration.json"; - -const nameOidcFile = getEnvVar("NAME_OIDC_FILE") ?? "keycloak.json"; - -const getFile = url => fetch(url).then(r => r.json()); - -export const getConfiguration = () => getFile(`${basePath}/${nameConfigFile}`); - -export const getOidc = () => getFile(`${basePath}/${nameOidcFile}`); diff --git a/trash/core/configuration/index.js b/trash/core/configuration/index.js deleted file mode 100644 index 09983a6..0000000 --- a/trash/core/configuration/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { getOidc, getConfiguration } from "./get-configuration"; -export { getEnvVar } from "./env"; diff --git a/trash/core/constants.js b/trash/core/constants.js deleted file mode 100644 index 280b73b..0000000 --- a/trash/core/constants.js +++ /dev/null @@ -1,41 +0,0 @@ -export const OIDC = "OIDC"; -export const NONE = "NONE"; - -export const SUCCESS_SEVERITY = "success"; -export const INFO_SEVERITY = "info"; -export const ERROR_SEVERITY = "error"; - -export const FAKE_USERS_LIST = [ - "Alain Térieur", - "Alain Verse", - "Barack Afritt", - "Brice Glace", - "Céline Évitable", - "Eric Hochet", - "Eva Porée", - "Guy Yiotine", - "Harry Cover", - "Jacques Ouzi", - "Jean Titouplin", - "Jean Registre", - "Justin Calva", - "Kelly Diote", - "Laurent Gina", - "Marie Rouana", - "Médhi Khaman", - "Nicolas Nihorangina", - "Paul Hémique", - "Prosper Hytté", - "Pierre Kiroul", - "Ray Ponse", - "Rob Otique", - "Sarah Pelle", - "Sandra Nicouverture", - "Tarek Tifié", - "Vishnou Lapaix", - "Yvon Tremblay", -].map(funnyName => ({ - given_name: funnyName.split(" ")[0], - family_name: funnyName.split(" ")[1], - preferred_username: funnyName, -})); diff --git a/trash/core/env.js b/trash/core/env.js deleted file mode 100644 index f5a1025..0000000 --- a/trash/core/env.js +++ /dev/null @@ -1 +0,0 @@ -export const getEnvVar = key => window?._env_?.[key] || process.env[`REACT_APP_${key}`]; diff --git a/trash/core/events/index.js b/trash/core/events/index.js deleted file mode 100644 index f541985..0000000 --- a/trash/core/events/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from "./listenActivity"; diff --git a/trash/core/events/listenActivity.js b/trash/core/events/listenActivity.js deleted file mode 100644 index e91eb60..0000000 --- a/trash/core/events/listenActivity.js +++ /dev/null @@ -1,11 +0,0 @@ -export const listenActivity = () => { - const activityEvents = ["mousedown", "mousemove", "keydown", "scroll", "touchstart"]; - return new Promise(resolve => { - const listener = () => { - resolve(); - }; - activityEvents.forEach(function (eventName) { - window.addEventListener(eventName, listener, { once: true }); - }); - }); -}; diff --git a/trash/core/fetch/fetcher.js b/trash/core/fetch/fetcher.js deleted file mode 100644 index e11fb26..0000000 --- a/trash/core/fetch/fetcher.js +++ /dev/null @@ -1,20 +0,0 @@ -export const fetcher = (url, method, body, params) => { - const headers = { - Accept: "application/json, text/plain, */*", - "Content-Type": "application/json", - }; - return fetch(params ? `${url}?${new URLSearchParams(params)}` : url, { - headers: headers, - method, - body: body ? JSON.stringify(body) : null, - }) - .then(r => { - console.log(r); - if (r.ok) return r.json(); - throw new Error("API failed"); - }) - .catch(e => { - console.log(e); - throw new Error(`Fetch error for ${url}`); - }); -}; diff --git a/trash/core/hooks/api.js b/trash/core/hooks/api.js deleted file mode 100644 index 38e5c4b..0000000 --- a/trash/core/hooks/api.js +++ /dev/null @@ -1,53 +0,0 @@ -import { useContext } from "react"; -import { AppContext } from "App"; -import { AuthContext } from "ui/context/auth/provider"; -import { API } from "core/api"; -import { useConstCallback } from "./useConstCallback"; - -export const useAPI = () => { - const oidcClient = useContext(AuthContext); - const { apiUrl } = useContext(AppContext); - - const getContactById = useConstCallback(id => API.getContactById(apiUrl)(id)(oidcClient.accessToken)); - - const getAllContacts = useConstCallback(() => API.getAllContacts(apiUrl)(oidcClient.accessToken)); - - const getAllCampaigns = useConstCallback(() => API.getAllCampaigns(apiUrl)(oidcClient.accessToken)); - - const getAllSurveyUnits = useConstCallback(() => - API.getAllSurveyUnits(apiUrl)(oidcClient.accessToken), - ); - - const getContactAccreditations = useConstCallback(id => - API.getContactAccreditations(apiUrl)(id)(oidcClient.accessToken), - ); - - const getContacts = useConstCallback(searchParams => - API.getContacts(apiUrl)(searchParams)(oidcClient.accessToken), - ); - - const getSources = useConstCallback(() => API.getSources(apiUrl)(oidcClient.accessToken)); - - const updateContact = useConstCallback((id, contactInfos) => - API.updateContact(apiUrl)(id, contactInfos)(oidcClient.accessToken), - ); - - const getSourceAccreditations = useConstCallback(() => - API.getSourceAccreditations(apiUrl)(oidcClient.accessToken), - ); - - const getUserRole = useConstCallback(() => API.getUserRole(apiUrl)(oidcClient.accessToken)); - - return { - getContactById, - getAllContacts, - getAllCampaigns, - getAllSurveyUnits, - getContacts, - updateContact, - getSourceAccreditations, - getUserRole, - getSources, - getContactAccreditations, - }; -}; diff --git a/trash/core/hooks/index.js b/trash/core/hooks/index.js deleted file mode 100644 index e888e64..0000000 --- a/trash/core/hooks/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./api"; -export * from "./useConstCallback"; diff --git a/trash/core/hooks/useConstCallback.js b/trash/core/hooks/useConstCallback.js deleted file mode 100644 index e4c3fad..0000000 --- a/trash/core/hooks/useConstCallback.js +++ /dev/null @@ -1,13 +0,0 @@ -import { useState, useRef } from "react"; -/** - * See https://github.com/garronej/powerhooks#useconstcallback for details - */ -export function useConstCallback(callback) { - const callbackRef = useRef(); - callbackRef.current = callback; - return useState( - () => - (...args) => - callbackRef.current(...args), - )[0]; -} diff --git a/trash/core/keycloak/index.js b/trash/core/keycloak/index.js deleted file mode 100644 index 8714cd9..0000000 --- a/trash/core/keycloak/index.js +++ /dev/null @@ -1 +0,0 @@ -export { createKeycloakOidcClient } from "./keycloakOidcClient"; diff --git a/trash/core/keycloak/keycloakOidcClient.js b/trash/core/keycloak/keycloakOidcClient.js deleted file mode 100644 index f60aeb6..0000000 --- a/trash/core/keycloak/keycloakOidcClient.js +++ /dev/null @@ -1,85 +0,0 @@ -import Keycloak from "keycloak-js"; - -export const createKeycloakOidcClient = async ({ - url, - realm, - clientId, - evtUserActivity, - identityProvider, -}) => { - const keycloakInstance = new Keycloak({ url, realm, clientId }); - - const isAuthenticated = await keycloakInstance - .init({ - onLoad: "check-sso", - silentCheckSsoRedirectUri: `${window.location.origin}/silent-sso.html`, - checkLoginIframe: false, - }) - .catch(error => error); - - const login = async () => { - await keycloakInstance.login({ idpHint: identityProvider, redirectUri: window.location.href }); - return new Promise(() => {}); - }; - - const loadUserInfo = async () => { - const userInfo = await keycloakInstance.loadUserInfo(); - return { ...userInfo, id: userInfo?.preferred_username }; - }; - - if (!isAuthenticated) { - return { - isUserLoggedIn: false, - login, - }; - } - - const oidcClient = { - isUserLoggedIn: true, - accessToken: keycloakInstance.token, - oidcUser: await loadUserInfo(), - logout: async ({ redirectTo }) => { - await keycloakInstance.logout({ - redirectUri: redirectTo || window.location.origin, - }); - - return new Promise(() => {}); - }, - }; - - (function callee() { - const msBeforeExpiration = keycloakInstance.tokenParsed.exp * 1000 - Date.now(); - - setTimeout( - async () => { - console.log( - `OIDC access token will expire in ${minValiditySecond} seconds, waiting for user activity before renewing`, - ); - - await evtUserActivity(); - - console.log("User activity detected. Refreshing access token now"); - - const error = await keycloakInstance.updateToken(-1).then( - () => undefined, - error => error, - ); - - if (error) { - console.log("Can't refresh OIDC access token, getting a new one"); - //NOTE: Never resolves - await login(); - } - - oidcClient.accessToken = keycloakInstance.token; - - callee(); - }, - msBeforeExpiration - minValiditySecond * 1000, - ); - })(); - - return oidcClient; -}; - -const minValiditySecond = 25; diff --git a/trash/core/mock/contacts.js b/trash/core/mock/contacts.js deleted file mode 100644 index d0e20a7..0000000 --- a/trash/core/mock/contacts.js +++ /dev/null @@ -1,281 +0,0 @@ -export const sleep = ms => { - return new Promise(resolve => setTimeout(resolve, ms)); -}; - -export const rows = [ - { - id: 1, - surveyUnitId: "999999033", - surveyName: " Activité et conditions d'emploi de la main-d'œuvre 4e trimestre 2021", - reporting: "Réponse attendue pour le 18 janvier 2022", - access: - "https://stromae-v2.dev.insee.io/visualize?questionnaire=https%3A%2F%2Fpogues-back-office.dev.insee.io%2Fapi%2Fpersistence%2Fquestionnaire%2Fjson-lunatic%2Fkzqsw3qa-q-0-1647855585412", - }, - { - id: 2, - surveyUnitId: "999999033", - surveyName: - "Technologies de l'information et de la communication et commerce électronique (TIC) 2022", - reporting: "Réponse attendue pour le 18 janvier 2022", - access: - "https://stromae-v2.dev.insee.io/visualize?questionnaire=https%3A%2F%2Fpogues-back-office.dev.insee.io%2Fapi%2Fpersistence%2Fquestionnaire%2Fjson-lunatic%2Fkzqsw3qa-q-0-1647855585412", - }, - { - id: 3, - surveyUnitId: "999999033", - surveyName: "Consommation d'énergie dans l'industrie (EACEI) 2021", - reporting: "Réponse attendue pour le 18 janvier 2022", - access: - "https://stromae-v2.dev.insee.io/visualize?questionnaire=https%3A%2F%2Fpogues-back-office.dev.insee.io%2Fapi%2Fpersistence%2Fquestionnaire%2Fjson-lunatic%2Fkzqsw3qa-q-0-1647855585412", - }, - { - id: 4, - surveyUnitId: "999999033", - surveyName: "Mensuelle de branche janvier 2022", - reporting: "Réponse attendue pour le 18 janvier 2022", - access: - "https://stromae-v2.dev.insee.io/visualize?questionnaire=https%3A%2F%2Fpogues-back-office.dev.insee.io%2Fapi%2Fpersistence%2Fquestionnaire%2Fjson-lunatic%2Fkzqsw3qa-q-0-1647855585412", - }, - { - id: 5, - surveyUnitId: "999999033", - surveyName: "Annuelle de Production (EAP) 2021", - reporting: "Réponse attendue pour le 18 janvier 2022", - access: - "https://stromae-v2.dev.insee.io/visualize?questionnaire=https%3A%2F%2Fpogues-back-office.dev.insee.io%2Fapi%2Fpersistence%2Fquestionnaire%2Fjson-lunatic%2Fkzqsw3qa-q-0-1647855585412", - }, -]; - -export const filteredRows = [ - { - id: "GHPGZ0Q", - lastName: "Bernhard", - firstName: "Nana", - email: "Nana.Bernhard@cocorico.fr", - function: "Banking Director", - phone: "(481) 247-6789", - comment: "Ruination IPA", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/N2BJO2L", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/N2BJO2L", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/N2BJO2L/address", - }, - }, - }, - { - id: "NBSRXR1", - lastName: "Morar", - firstName: "Odell", - email: "Morar.Odell@cocorico.fr", - function: "Direct Technology Orchestrator", - phone: "1-542-829-9548 x6486", - comment: "Hop Rod Rye", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/NBSRXR1", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/NBSRXR1", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/NBSRXR1/address", - }, - }, - }, - { - id: "SHHPNKB", - lastName: "West", - firstName: "Vanita", - email: "West.Vanita@cocorico.fr", - function: "Global Community-Services Manager", - phone: "1-141-531-5817 x4731", - comment: "Samuel Smith’s Oatmeal Stout", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/SHHPNKB", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/SHHPNKB", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/SHHPNKB/address", - }, - }, - }, - { - id: "D5K4LQX", - lastName: "Koch", - firstName: "Octavio", - email: "Koch.Octavio@cocorico.fr", - function: "Forward Construction Coordinator", - phone: "1-537-723-4566", - comment: "Double Bastard Ale", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/D5K4LQX", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/D5K4LQX", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/D5K4LQX/address", - }, - }, - }, - { - id: "CZT97QN", - lastName: "Kautzer", - firstName: "Gene", - email: "Kautzer.Gene@cocorico.fr", - function: "Investor Technology Producer", - phone: "474-120-5762 x300", - comment: "Arrogant Bastard Ale", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/CZT97QN", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/CZT97QN", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/CZT97QN/address", - }, - }, - }, - { - id: "FPIFYDB", - lastName: "Bergnaum", - firstName: "Paulene", - email: "Bergnaum.Paulene@cocorico.fr", - function: "Sales Liaison", - phone: "341.512.0859 x501", - comment: "Kirin Inchiban", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/FPIFYDB", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/FPIFYDB", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/FPIFYDB/address", - }, - }, - }, - { - id: "LKB64AY", - lastName: "Doyle", - firstName: "Mi", - email: "Doyle.Mi@cocorico.fr", - function: "Global IT Agent", - phone: "1-983-856-4028 x190", - comment: "Bell’s Expedition", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/LKB64AY", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/LKB64AY", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/LKB64AY/address", - }, - }, - }, - { - id: "8RLFR9I", - lastName: "Murphy", - firstName: "Damon", - email: "Murphy.Damon@cocorico.fr", - function: "Sales Coordinator", - phone: "724-804-3743 x745", - comment: "Storm King Stout", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/8RLFR9I", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/8RLFR9I", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/8RLFR9I/address", - }, - }, - }, - { - id: "VOAZXKD", - lastName: "Stracke", - firstName: "Ward", - email: "Stracke.Ward@cocorico.fr", - function: "Corporate Government Supervisor", - phone: "612-798-6367 x575", - comment: "Westmalle Trappist Tripel", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/VOAZXKD", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/VOAZXKD", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/VOAZXKD/address", - }, - }, - }, - { - id: "ZUP1TKM", - lastName: "Gibson", - firstName: "Zada", - email: "Gibson.Zada@cocorico.fr", - function: "Healthcare Manager", - phone: "196-146-6713 x53076", - comment: "Bell’s Expedition", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/ZUP1TKM", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/ZUP1TKM", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/ZUP1TKM/address", - }, - }, - }, - { - id: "YCBPOQ4", - lastName: "Konopelski", - firstName: "Donovan", - email: "Konopelski.Donovan@cocorico.fr", - function: "Central Community-Services Architect", - phone: "009.047.1155", - comment: "Delirium Tremens", - gender: "male", - _links: { - self: { - href: "https://datacollection-management-api.dev.insee.io/contacts/YCBPOQ4", - }, - contact: { - href: "https://datacollection-management-api.dev.insee.io/contacts/YCBPOQ4", - }, - address: { - href: "https://datacollection-management-api.dev.insee.io/contacts/YCBPOQ4/address", - }, - }, - }, -]; diff --git a/trash/core/mock/select-items.js b/trash/core/mock/select-items.js deleted file mode 100644 index 1c08ced..0000000 --- a/trash/core/mock/select-items.js +++ /dev/null @@ -1,79 +0,0 @@ -export const sourceItems = [ - { - key: 1, - value: "ARMADILLO", - label: "Technologie de l'information et de la communication", - }, - { key: 2, value: "CAMPING", label: "Fréquentation hôtelière de pleine air" }, - { - key: 3, - value: "ABATTAGEQUALITEVOLAILLES", - label: "Abattage et qualité volailles", - }, -]; - -export const yearItems = [ - { - key: 1, - value: "2019", - label: "2019", - }, - { - key: 2, - value: "2020", - label: "2020", - }, - { - key: 3, - value: "2021", - label: "2021", - }, - { - key: 4, - value: "2022", - label: "2022", - }, -]; - -export const periodItems = [ - { - key: 1, - value: "M1", - label: "M1 - Janvier", - }, - { - key: 2, - value: "M2", - label: "M2 - Février", - }, - { - key: 3, - value: "M3", - label: "M3 - Mars", - }, - { - key: 4, - value: "M4", - label: "M4 - Avril", - }, - { - key: 5, - value: "M5", - label: "M5 - Mai", - }, - { - key: 6, - value: "M6", - label: "M6 - Juin", - }, - { - key: 7, - value: "M7", - label: "M7 - Juillet", - }, - { - key: 8, - value: "M8", - label: "M8 - Aout", - }, -]; diff --git a/trash/core/properties.js b/trash/core/properties.js deleted file mode 100644 index fe68336..0000000 --- a/trash/core/properties.js +++ /dev/null @@ -1,29 +0,0 @@ -import { menuDictionary } from "i18n"; - -export const routes = moogUrl => [ - { - id: "surveys", - fullPath: "/pilotage/enquetes", - path: "enquetes", - label: menuDictionary.surveys, - }, - { - id: "users", - fullPath: "/pilotage/utilisateurs", - path: "utilisateurs", - label: menuDictionary.users, - }, - { - id: "contacts", - fullPath: "/pilotage/contacts", - path: "contacts", - label: menuDictionary.contacts, - }, - { - id: "suivi", - fullPath: moogUrl, - path: "suivi", - label: menuDictionary.follow, - external: true, - }, -]; diff --git a/trash/core/role/index.js b/trash/core/role/index.js deleted file mode 100644 index 64d7bb7..0000000 --- a/trash/core/role/index.js +++ /dev/null @@ -1,30 +0,0 @@ -import { routes } from "core/properties"; - -// Role in oidcUser i.e role in LDAP ! -// ToDo : verify reel value -export const ACCESS_APP_ROLE_ADMIN = "Utilisateurs_Coltrane-Pilotage"; -export const ACCESS_APP_ROLES = [ACCESS_APP_ROLE_ADMIN]; - -// Role retrieved in getRole method : role in api database -// ToDo refactor -export const ADMIN_ROLE = "admin"; -export const RESPONSABLE_ROLE = "responsable"; -export const GESTIONNAIRE_ROLE = "gestionnaire"; -export const ASSISTANCE_ROLE = "assistance"; - -export const canAccessToApp = (roles = []) => - ACCESS_APP_ROLES.reduce((canAccess, appRole) => { - return canAccess || roles.includes(appRole); - }, false); - -export const canManageUser = (roles = []) => roles.includes(ADMIN_ROLE); - -export const getRoutesForUser = (roles, moogUrl) => - routes(moogUrl).filter(({ id }) => { - switch (id) { - case "users": - return canManageUser(roles); - default: - return true; - } - }); diff --git a/trash/core/utils/numberUtils.js b/trash/core/utils/numberUtils.js deleted file mode 100644 index e7167ad..0000000 --- a/trash/core/utils/numberUtils.js +++ /dev/null @@ -1 +0,0 @@ -export const formatNumber = nb => new Intl.NumberFormat().format(nb); diff --git a/trash/core/utils/utils.js b/trash/core/utils/utils.js deleted file mode 100644 index 9597434..0000000 --- a/trash/core/utils/utils.js +++ /dev/null @@ -1,3 +0,0 @@ -import { routes } from "core/properties"; - -export const getRouteLabel = route => routes.filter(r => r.id === route.pathname.split("/")[2])[0].label; diff --git a/trash/demo/.eslintrc.cjs b/trash/demo/.eslintrc.cjs deleted file mode 100644 index d6c9537..0000000 --- a/trash/demo/.eslintrc.cjs +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - root: true, - env: { browser: true, es2020: true }, - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:react-hooks/recommended', - ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parser: '@typescript-eslint/parser', - plugins: ['react-refresh'], - rules: { - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], - }, -} diff --git a/trash/demo/.gitignore b/trash/demo/.gitignore deleted file mode 100644 index a547bf3..0000000 --- a/trash/demo/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules -dist -dist-ssr -*.local - -# Editor directories and files -.vscode/* -!.vscode/extensions.json -.idea -.DS_Store -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/trash/demo/README.md b/trash/demo/README.md deleted file mode 100644 index 1ebe379..0000000 --- a/trash/demo/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# React + TypeScript + Vite - -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. - -Currently, two official plugins are available: - -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh - -## Expanding the ESLint configuration - -If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: - -- Configure the top-level `parserOptions` property like this: - -```js - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - project: ['./tsconfig.json', './tsconfig.node.json'], - tsconfigRootDir: __dirname, - }, -``` - -- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` -- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` -- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list diff --git a/trash/demo/index.html b/trash/demo/index.html deleted file mode 100644 index e4b78ea..0000000 --- a/trash/demo/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - Vite + React + TS - - -
- - - diff --git a/trash/demo/package.json b/trash/demo/package.json deleted file mode 100644 index 1c23e69..0000000 --- a/trash/demo/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "demo", - "private": true, - "version": "0.0.0", - "type": "module", - "scripts": { - "dev": "vite", - "build": "tsc && vite build", - "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", - "preview": "vite preview" - }, - "dependencies": { - "react": "^18.2.0", - "react-dom": "^18.2.0" - }, - "devDependencies": { - "@types/react": "^18.2.15", - "@types/react-dom": "^18.2.7", - "@typescript-eslint/eslint-plugin": "^6.0.0", - "@typescript-eslint/parser": "^6.0.0", - "@vitejs/plugin-react": "^4.0.3", - "eslint": "^8.45.0", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-react-refresh": "^0.4.3", - "typescript": "^5.0.2", - "vite": "^4.4.5" - } -} diff --git a/trash/demo/public/vite.svg b/trash/demo/public/vite.svg deleted file mode 100644 index e7b8dfb..0000000 --- a/trash/demo/public/vite.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/trash/demo/src/App.css b/trash/demo/src/App.css deleted file mode 100644 index b9d355d..0000000 --- a/trash/demo/src/App.css +++ /dev/null @@ -1,42 +0,0 @@ -#root { - max-width: 1280px; - margin: 0 auto; - padding: 2rem; - text-align: center; -} - -.logo { - height: 6em; - padding: 1.5em; - will-change: filter; - transition: filter 300ms; -} -.logo:hover { - filter: drop-shadow(0 0 2em #646cffaa); -} -.logo.react:hover { - filter: drop-shadow(0 0 2em #61dafbaa); -} - -@keyframes logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} - -@media (prefers-reduced-motion: no-preference) { - a:nth-of-type(2) .logo { - animation: logo-spin infinite 20s linear; - } -} - -.card { - padding: 2em; -} - -.read-the-docs { - color: #888; -} diff --git a/trash/demo/src/App.tsx b/trash/demo/src/App.tsx deleted file mode 100644 index afe48ac..0000000 --- a/trash/demo/src/App.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { useState } from 'react' -import reactLogo from './assets/react.svg' -import viteLogo from '/vite.svg' -import './App.css' - -function App() { - const [count, setCount] = useState(0) - - return ( - <> -
- - Vite logo - - - React logo - -
-

Vite + React

-
- -

- Edit src/App.tsx and save to test HMR -

-
-

- Click on the Vite and React logos to learn more -

- - ) -} - -export default App diff --git a/trash/demo/src/assets/react.svg b/trash/demo/src/assets/react.svg deleted file mode 100644 index 6c87de9..0000000 --- a/trash/demo/src/assets/react.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/trash/demo/src/index.css b/trash/demo/src/index.css deleted file mode 100644 index 2c3fac6..0000000 --- a/trash/demo/src/index.css +++ /dev/null @@ -1,69 +0,0 @@ -:root { - font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; - line-height: 1.5; - font-weight: 400; - - color-scheme: light dark; - color: rgba(255, 255, 255, 0.87); - background-color: #242424; - - font-synthesis: none; - text-rendering: optimizeLegibility; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - -webkit-text-size-adjust: 100%; -} - -a { - font-weight: 500; - color: #646cff; - text-decoration: inherit; -} -a:hover { - color: #535bf2; -} - -body { - margin: 0; - display: flex; - place-items: center; - min-width: 320px; - min-height: 100vh; -} - -h1 { - font-size: 3.2em; - line-height: 1.1; -} - -button { - border-radius: 8px; - border: 1px solid transparent; - padding: 0.6em 1.2em; - font-size: 1em; - font-weight: 500; - font-family: inherit; - background-color: #1a1a1a; - cursor: pointer; - transition: border-color 0.25s; -} -button:hover { - border-color: #646cff; -} -button:focus, -button:focus-visible { - outline: 4px auto -webkit-focus-ring-color; -} - -@media (prefers-color-scheme: light) { - :root { - color: #213547; - background-color: #ffffff; - } - a:hover { - color: #747bff; - } - button { - background-color: #f9f9f9; - } -} diff --git a/trash/demo/src/main.tsx b/trash/demo/src/main.tsx deleted file mode 100644 index 3d7150d..0000000 --- a/trash/demo/src/main.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import React from 'react' -import ReactDOM from 'react-dom/client' -import App from './App.tsx' -import './index.css' - -ReactDOM.createRoot(document.getElementById('root')!).render( - - - , -) diff --git a/trash/demo/src/vite-env.d.ts b/trash/demo/src/vite-env.d.ts deleted file mode 100644 index 11f02fe..0000000 --- a/trash/demo/src/vite-env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// diff --git a/trash/demo/tsconfig.json b/trash/demo/tsconfig.json deleted file mode 100644 index a7fc6fb..0000000 --- a/trash/demo/tsconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2020", - "useDefineForClassFields": true, - "lib": ["ES2020", "DOM", "DOM.Iterable"], - "module": "ESNext", - "skipLibCheck": true, - - /* Bundler mode */ - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx", - - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true - }, - "include": ["src"], - "references": [{ "path": "./tsconfig.node.json" }] -} diff --git a/trash/demo/tsconfig.node.json b/trash/demo/tsconfig.node.json deleted file mode 100644 index 42872c5..0000000 --- a/trash/demo/tsconfig.node.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "composite": true, - "skipLibCheck": true, - "module": "ESNext", - "moduleResolution": "bundler", - "allowSyntheticDefaultImports": true - }, - "include": ["vite.config.ts"] -} diff --git a/trash/demo/vite.config.ts b/trash/demo/vite.config.ts deleted file mode 100644 index 5a33944..0000000 --- a/trash/demo/vite.config.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' - -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react()], -}) diff --git a/trash/ui/components/pages/contacts/accreditationsDetail/icons.js b/trash/ui/components/pages/contacts/accreditationsDetail/icons.js deleted file mode 100644 index 2b8102e..0000000 --- a/trash/ui/components/pages/contacts/accreditationsDetail/icons.js +++ /dev/null @@ -1,53 +0,0 @@ -import { useEffect, useState } from "react"; -import { useAPI } from "core/hooks"; -import { Chip, Divider, Typography } from "@mui/material"; - -export const AccreditationsIcons = ({ idec }) => { - const { getContactAccreditations } = useAPI(); - - const [pageState, setPageState] = useState({ - isLoading: false, - data: [], - }); - - useEffect(() => { - setPageState(old => ({ ...old, isLoading: true })); - (async () => { - const { data } = await getContactAccreditations(idec); - setPageState(old => ({ - ...old, - isLoading: false, - data: data, - })); - })(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [idec]); - - return ( - <> - {pageState.data.map(acc => ( - - - {acc.sourceId} {acc.year} {acc.period} - - - UE. {acc.identificationCode} {acc.identificationName} - - - } - /> - ))} - - ); -}; diff --git a/trash/ui/components/pages/contacts/accreditationsDetail/index.js b/trash/ui/components/pages/contacts/accreditationsDetail/index.js deleted file mode 100644 index ad816c3..0000000 --- a/trash/ui/components/pages/contacts/accreditationsDetail/index.js +++ /dev/null @@ -1,70 +0,0 @@ -import { useEffect, useState } from "react"; - -import { useAPI } from "core/hooks"; -import { DataGrid, frFR } from "@mui/x-data-grid"; -import { Box, Typography } from "@mui/material"; - -const columns = [ - { - field: "sourceId", - headerName: "Identifiant source", - width: "200", - }, - { - field: "sourceWording", - headerName: "Description Source", - width: "200", - }, - { field: "year", headerName: "Année", width: "200" }, - { field: "period", headerName: "Période", width: "200" }, - { field: "partition", headerName: "Partition", width: "200" }, - { field: "identificationCode", headerName: "Identifiant unité enquêtée", width: "200" }, - { field: "identificationName", headerName: "Nom unité enquêtée", width: "300" }, - { field: "main", headerName: "Est principal", width: "300" }, -]; - -export const AccreditationsDetail = ({ idec }) => { - const [accreditations, setAccreditations] = useState([]); - const { getContactAccreditations } = useAPI(); - - const [pageState, setPageState] = useState({ - isLoading: false, - data: [], - }); - - useEffect(() => { - setPageState(old => ({ ...old, isLoading: true })); - (async () => { - const { data } = await getContactAccreditations(idec); - setPageState(old => ({ - ...old, - isLoading: false, - data: data, - })); - - setAccreditations(data); - })(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [idec]); - - return ( - <> - Habilitations - - accreditations.indexOf(row)} - rows={pageState.data} - loading={pageState.isLoading} - pageSize={10} - rowsPerPageOptions={[10]} - disableSelectionOnClick - experimentalFeatures={{ newEditingApi: true }} - /> - - - ); -}; diff --git a/trash/ui/components/pages/contacts/detail/index.js b/trash/ui/components/pages/contacts/detail/index.js deleted file mode 100644 index 0c1588a..0000000 --- a/trash/ui/components/pages/contacts/detail/index.js +++ /dev/null @@ -1,71 +0,0 @@ -import { useState } from "react"; -import { useParams } from "react-router-dom"; -import Tabs from "@mui/material/Tabs"; -import Tab from "@mui/material/Tab"; -import Typography from "@mui/material/Typography"; -import Box from "@mui/material/Box"; -import { ContactsUpdateForm } from "ui/components/pages/contacts/updateForm"; -import { AccreditationsDetail } from "../accreditationsDetail"; -import { contactDictionary } from "i18n"; - -function TabPanel(props) { - const { children, value, index, ...other } = props; - - return ( - - ); -} -function a11yProps(index) { - return { - id: `simple-tab-${index}`, - "aria-controls": `simple-tabpanel-${index}`, - }; -} - -export const ContactsDetail = () => { - let { idec } = useParams(); - const [value, setValue] = useState(0); - - const handleChange = (event, newValue) => { - setValue(newValue); - }; - return ( - <> - - - - - - - - - - - - - - Renouveler le mot de passe de {idec} - - - Associer / dissocier des droits de {idec} - - - - Consulter une unité enquêtée - - - - ); -}; diff --git a/trash/ui/components/pages/contacts/search/index.js b/trash/ui/components/pages/contacts/search/index.js deleted file mode 100644 index 4da2fbd..0000000 --- a/trash/ui/components/pages/contacts/search/index.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useState } from "react"; -import { ContactsSearchForm } from "../searchForm"; -import { ContactsSearchResults } from "../searchResults"; - -export const ContactsSearch = () => { - const [formValues, setFormValues] = useState(null); - - const handleOnClickSearchButton = formValues => { - setFormValues(formValues); - }; - - const handleOnClickCancelButton = formValues => { - setFormValues(formValues); - }; - return ( - <> - - {formValues ? : null} - - ); -}; diff --git a/trash/ui/components/pages/contacts/searchForm/index.js b/trash/ui/components/pages/contacts/searchForm/index.js deleted file mode 100644 index 1076756..0000000 --- a/trash/ui/components/pages/contacts/searchForm/index.js +++ /dev/null @@ -1,184 +0,0 @@ -import { useEffect, useState } from "react"; -import Box from "@mui/material/Box"; -import FormControl from "@mui/material/FormControl"; -import Input from "@mui/material/Input"; -import InputLabel from "@mui/material/InputLabel"; -import MenuItem from "@mui/material/MenuItem"; -import Select from "@mui/material/Select"; -import { Button, Typography } from "@mui/material"; -import { yearItems, periodItems } from "core/mock/select-items"; -import { useAPI } from "core/hooks"; -import { buttonDictionary, contactDictionary } from "i18n"; - -const defaultValues = { - identifier: "", - lastName: "", - firstName: "", - email: "", - idSu: "", - identificationName: "", - identificationCode: "", - source: "", - year: "", - period: "", -}; - -export const ContactsSearchForm = ({ handleOnClickSearchButton, handleOnClickCancelButton }) => { - const [formValues, setFormValues] = useState(defaultValues); - const [sources, setSources] = useState([]); - const { getSources } = useAPI(); - - useEffect(() => { - (async () => { - const { data, error } = await getSources(); - if (!error && data) { - setSources(data.content); - } - })(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - - const handleChange = e => { - const { name, value } = e.target; - setFormValues({ - ...formValues, - [name]: value, - }); - }; - const resetForm = () => { - setFormValues(defaultValues); - }; - return ( - <> - :not(style)": { m: 1 }, - }} - noValidate - autoComplete="off" - > - - Idec - - - - {contactDictionary.personalDataLastname} - - - - {contactDictionary.personalDataFirstname} - - - - {contactDictionary.email} - - - - - {contactDictionary.surveyUnitIdentifier} - - - - - {contactDictionary.surveyUnitIdentificationCode} - - - - - - {contactDictionary.surveyUnitIdentificationName} - - - - - - - {contactDictionary.source} - - - - - - {contactDictionary.period} - - - - - - {contactDictionary.year} - - - - - - - - - ); -}; diff --git a/trash/ui/components/pages/contacts/searchResults/index.js b/trash/ui/components/pages/contacts/searchResults/index.js deleted file mode 100644 index 64fdbbd..0000000 --- a/trash/ui/components/pages/contacts/searchResults/index.js +++ /dev/null @@ -1,112 +0,0 @@ -import { useContext, useEffect, useState } from "react"; -import { useAPI } from "core/hooks"; -import { - Accordion, - AccordionDetails, - AccordionSummary, - Divider, - IconButton, - Pagination, - Stack, - Typography, -} from "@mui/material"; -import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; -import { AccreditationsIcons } from "../accreditationsDetail/icons"; -import { ContentPasteGo } from "@mui/icons-material"; -import { Link } from "react-router-dom"; -import { AppContext } from "App"; -import PermIdentityIcon from "@mui/icons-material/PermIdentity"; - -export const ContactsSearchResults = ({ formValues }) => { - const { getContacts } = useAPI(); - let [page, setPage] = useState(1); - - const { setLoading } = useContext(AppContext); - - const [pageState, setPageState] = useState({ - data: [], - total: 0, - page: 1, - pageSize: 5, - }); - - const nbPages = Math.ceil(pageState.total / pageState.pageSize); - - const handleChange = (e, p) => { - setPage(p); - setPageState(old => ({ - ...old, - page: p, - })); - }; - - useEffect(() => { - setLoading(true); - setPageState(old => ({ ...old, isLoading: true })); - (async () => { - const { data, error } = await getContacts({ - ...formValues, - pageNo: pageState.page - 1, - pageSize: pageState.pageSize, - }); - setLoading(false); - if (!error && data) { - setPageState(old => ({ - ...old, - isLoading: false, - data: data.content, - total: data.totalElements, - })); - } - })(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [pageState.page, pageState.pageSize]); - - return ( - <> - (Nombre de résultats: {pageState.total} - {pageState.data.map(c => ( - - } - aria-controls="panel1a-content" - id="panel1a-header" - > - - - {c.identifier} - - {c.lastName} {c.firstName} - - - {" "} - {c.email} - - - - - - - - - - - - - - ))} - - - - ; - - ); -}; diff --git a/trash/ui/components/pages/contacts/updateForm/index.js b/trash/ui/components/pages/contacts/updateForm/index.js deleted file mode 100644 index 29ce45a..0000000 --- a/trash/ui/components/pages/contacts/updateForm/index.js +++ /dev/null @@ -1,171 +0,0 @@ -import { useState, useEffect } from "react"; -import Box from "@mui/material/Box"; -import { Button, Grid, Typography } from "@mui/material"; -import { useAPI } from "core/hooks"; -import { FormInput } from "ui/shared/form/formInput"; - -const defaultValues = { - lastName: "", - firstName: "", - civility: "", - email: "", - phone: "", - comment: "", - function: "", - address: { - streetNumber: "", - streetName: "", - city: "", - zipCode: "", - countryName: "", - }, -}; - -export const ContactsUpdateForm = ({ idec }) => { - const [formValues, setFormValues] = useState(defaultValues); - const [contactHasBeenUpdated, setcontactHasBeenUpdated] = useState(false); - const { getContactById, updateContact } = useAPI(); - - useEffect(() => { - (async () => { - const { data } = await getContactById(idec); - setFormValues(data); - })(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [idec]); - - const handleChange = e => { - const { name, value } = e.target; - setFormValues({ - ...formValues, - [name]: value, - }); - }; - - const handleChangeAddress = e => { - const { name, value } = e.target; - const { address } = formValues; - setFormValues({ - ...formValues, - address: { ...address, [name]: value }, - }); - }; - - const handleUpdateContact = async () => { - const { ...contactInfos } = formValues; - - const { error } = await updateContact(idec, contactInfos); - if (!error) { - setcontactHasBeenUpdated(true); - } - }; - - const resetForm = () => { - setFormValues(defaultValues); - }; - - return ( - <> - {contactHasBeenUpdated &&
Contact mis à jour
} - :not(style)": { m: 1 }, - }} - noValidate - autoComplete="off" - > - Coordonnées - - - - - - - - - - - - - - - - - - - - - - - ); -}; diff --git a/trash/ui/components/pages/home/index.jsx b/trash/ui/components/pages/home/index.jsx deleted file mode 100644 index ac25ea0..0000000 --- a/trash/ui/components/pages/home/index.jsx +++ /dev/null @@ -1,41 +0,0 @@ -import { Box, Typography } from "@mui/material"; -import { useAPI } from "core/hooks"; -import { useEffect, useState } from "react"; -import { HomeChip } from "ui/shared/chip"; - -export const Home = () => { - const [nbContacts, setNbContacts] = useState(0); - const [nbCampaigns, setNbCampaigns] = useState(0); - const [nbSu, setNbSu] = useState(0); - - const { getAllContacts, getAllCampaigns, getAllSurveyUnits } = useAPI(); - - useEffect(() => { - (async () => { - const { data: contacts, error: errorContacts } = await getAllContacts(); - if (!errorContacts) { - setNbContacts(contacts?.totalElements); - } - const { data: campaigns, error: errorCampaigns } = await getAllCampaigns(); - if (!errorCampaigns) { - setNbCampaigns(campaigns?.totalElements); - } - const { data: sus, error: errorSus } = await getAllSurveyUnits(); - if (!errorSus) { - setNbSu(sus?.totalElements); - } - })(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - - return ( - <> - Welcome Home ! - - - - - - - ); -}; diff --git a/trash/ui/components/pages/surveys/index.jsx b/trash/ui/components/pages/surveys/index.jsx deleted file mode 100644 index 91cbbf5..0000000 --- a/trash/ui/components/pages/surveys/index.jsx +++ /dev/null @@ -1,3 +0,0 @@ -export const Surveys = () => { - return

Gérer des enquêtes

; -}; diff --git a/trash/ui/components/pages/users/index.js b/trash/ui/components/pages/users/index.js deleted file mode 100644 index 1a9e475..0000000 --- a/trash/ui/components/pages/users/index.js +++ /dev/null @@ -1,7 +0,0 @@ -export const Users = () => { - return ( - <> -

Gérer les utilisateurs

- - ); -}; diff --git a/trash/ui/context/UserAccount/index.jsx b/trash/ui/context/UserAccount/index.jsx deleted file mode 100644 index 7b4d4af..0000000 --- a/trash/ui/context/UserAccount/index.jsx +++ /dev/null @@ -1,73 +0,0 @@ -import { createContext, useContext, useEffect, useState } from "react"; -import { useAPI, useConstCallback } from "core/hooks"; -import { AppContext } from "App"; -import { AuthContext } from "../auth/provider"; -import { ERROR_SEVERITY, INFO_SEVERITY } from "core/constants"; -import { notifDictionary } from "i18n"; -import { canAccessToApp } from "core/role"; -import { Box, Typography } from "@mui/material"; -import { errorDictionary } from "i18n"; - -export const UserAccountContext = createContext(); - -export const UserAccountProvider = ({ children }) => { - const { setLoading, openNotif } = useContext(AppContext); - const { oidcUser } = useContext(AuthContext); - const [user, setUser] = useState(null); - const { getSourceAccreditations, getUserRole } = useAPI(); - - const loadUserData = useConstCallback(async id => { - setLoading(true); - const { data: dataSourceAcc, error: errorSourceAcc } = await getSourceAccreditations(); - const { data: dataRole, error: errorRole } = await getUserRole(); - if (errorSourceAcc || errorRole) { - openNotif({ - severity: ERROR_SEVERITY, - message: notifDictionary.userLoadingError, - }); - } else { - const userLoaded = { - id: id, - name: `${oidcUser?.preferred_username}`, - sourceAccreditations: dataSourceAcc?.content, - roles: [...(oidcUser["inseegroupedefaut"] || []), dataRole?.role], - canAccess: canAccessToApp(oidcUser["inseegroupedefaut"] || []), - }; - setUser(userLoaded); - if (userLoaded.canAccess) - openNotif({ - severity: INFO_SEVERITY, - message: `${notifDictionary.helloUser} ${userLoaded.name}`, - }); - } - - setLoading(false); - }); - - useEffect(() => { - // For Keyloack : check if the id is "id" or something like : "preferred_username" - if (oidcUser?.id) loadUserData(oidcUser?.id); - }, [oidcUser?.id, loadUserData]); - - return ( - <> - {user && user.canAccess && ( - {children} - )} - {user && !user.canAccess && ( - - {`${notifDictionary.helloUser} ${user.name}`} -
- - {errorDictionary.noAccessToApp} - -
- {errorDictionary.contactAdmin} -
- )} - - ); -}; diff --git a/trash/ui/context/auth/index.js b/trash/ui/context/auth/index.js deleted file mode 100644 index 6354d54..0000000 --- a/trash/ui/context/auth/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { default as AuthProvider } from "./provider"; -export { default as secure } from "./hoc"; diff --git a/trash/ui/context/auth/provider/component.jsx b/trash/ui/context/auth/provider/component.jsx deleted file mode 100644 index dc9c425..0000000 --- a/trash/ui/context/auth/provider/component.jsx +++ /dev/null @@ -1,55 +0,0 @@ -import { getOidc } from "core/configuration"; -import { NONE, OIDC } from "core/constants"; -import { listenActivity } from "core/events"; -import { createKeycloakOidcClient } from "core/keycloak"; -import React, { useEffect, useMemo, useState } from "react"; -import { LoaderSimple } from "ui/shared/loader"; -import { NoAuthLogin } from "./noAuth"; - -export const AuthContext = React.createContext(); - -const dummyOidcClient = { - isUserLoggedIn: false, -}; - -const AuthProvider = ({ authType, identityProvider, children }) => { - const [oidcClient, setOidcClient] = useState(null); - - useEffect(() => { - const loadOidcConf = async () => { - const oidcConf = await getOidc(); - const oidcClientKC = await createKeycloakOidcClient({ - url: oidcConf["auth-server-url"], - realm: oidcConf["realm"], - clientId: oidcConf["resource"], - evtUserActivity: listenActivity, - identityProvider, - }); - return oidcClientKC; - }; - - const loadConf = async () => { - if (authType === OIDC) { - const conf = await loadOidcConf(); - setOidcClient(conf); - } else setOidcClient(dummyOidcClient); - }; - - if (authType && oidcClient === null) loadConf(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [authType]); - - const contextOidc = useMemo(() => oidcClient, [oidcClient]); - - if (oidcClient === null) return ; - if (!oidcClient?.isUserLoggedIn) { - if (authType === NONE) return ; - else { - oidcClient.login(); - return ; - } - } - return {children}; -}; - -export default AuthProvider; diff --git a/trash/ui/context/auth/provider/index.js b/trash/ui/context/auth/provider/index.js deleted file mode 100644 index 2c4c0ca..0000000 --- a/trash/ui/context/auth/provider/index.js +++ /dev/null @@ -1 +0,0 @@ -export { AuthContext, default } from "./component"; diff --git a/trash/ui/context/auth/provider/noAuth.css b/trash/ui/context/auth/provider/noAuth.css deleted file mode 100644 index b5578b6..0000000 --- a/trash/ui/context/auth/provider/noAuth.css +++ /dev/null @@ -1,166 +0,0 @@ -body { - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - font-size: 14px; - line-height: 1.42857143; - color: #333; - /*background-color: #fff;*/ -} - -* { - box-sizing: border-box; -} -ul { - padding: 0; - margin-top: 10px; - margin-bottom: 10px; -} - -.img-right a { - text-decoration: none; -} -#bandeauSuperieur { - text-align: center; - height: 12em; -} - -#contenu { - margin: auto; - max-width: 600px; -} - -.group-heading { - padding: 10px 15px; - border: 1px solid #e7e7e7; - border-top-left-radius: 3px; - border-top-right-radius: 3px; - background-color: #dbdbdb; - background-image: linear-gradient(180deg, #ffffffd7 0, #dbdbdb); -} -.group-body { - padding: 10px 15px; - border: 1px solid #e7e7e7; - border-top: none; - border-bottom-left-radius: 3px; - border-bottom-right-radius: 3px; - margin-bottom: 2em; -} - -.form-group { - margin-bottom: 15px; -} -.text-right { - text-align: right; -} - -.button-insee { - border: 2px transparent; - cursor: pointer; - border-radius: 4px; - padding: 4px 12px; - background-color: #ffc400; - font-size: medium; - font-weight: bolder; - color: #0f417a; -} -.button-insee:hover { - background-color: #0f417a; - color: #ffc400; -} - -#bandeauSuperieur h1 { - text-align: center; - margin-top: 0.5em; - display: inline-block; - font-size: 2.5em; -} -/*** Bandeau superieur ***/ - -hr { - margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee; -} -/*** Titre ***/ - -#titrePortail { - margin: 0px 0px 0px 0px; -} - -#nomappli { - font-size: 75%; -} - -#urlappli { - font-size: 60%; -} - -/*Alert en rouge*/ -.alert { - margin-top: 1em; - margin-bottom: 0.5em; -} - -div.form-group-login { - margin-bottom: 1em; -} -div.form-group-login label { - margin-top: 0.5em; -} - -/*** Pied de page ***/ -#piedPage { - color: #404040; - background-color: #f8f8f8; - background-image: linear-gradient(180deg, #fff 0, #f8f8f8); - border: 1px solid; - border-color: #e7e7e7; - padding-top: 5px; - padding-bottom: 5px; - text-align: center; - height: 4em; - position: fixed; - bottom: 0; - right: 0; - left: 0; - z-index: 1030; -} - -#piedPage li { - margin-left: 2em; - margin-right: 2em; - display: inline; - list-style: none; -} - -#piedPage a { - color: #777; - text-decoration: none; -} -#piedPage a:hover, -#piedPage a:focus { - color: black; - text-decoration: none; -} - -@media (max-width: 1060px) { - #bandeauSuperieur { - height: auto; - } - #bandeauSuperieur h1 { - font-size: 2em; - width: auto; - } -} - -@media (max-width: 750px) { - #piedPage { - display: none; - } -} - -@media (max-width: 460px) { - #bandeauSuperieur h1 { - font-size: 1.2em; - } -} diff --git a/trash/ui/context/auth/provider/noAuth.jsx b/trash/ui/context/auth/provider/noAuth.jsx deleted file mode 100644 index 08aeeec..0000000 --- a/trash/ui/context/auth/provider/noAuth.jsx +++ /dev/null @@ -1,185 +0,0 @@ -import { - FormControl, - InputLabel, - MenuItem, - Select, - Stack, - Switch, - TextField, - Typography, -} from "@mui/material"; -import { useContext, useEffect, useState } from "react"; -import { AppContext } from "../../../../App"; -import { API } from "core/api"; -import { notifDictionary } from "i18n"; -import { ERROR_SEVERITY, FAKE_USERS_LIST } from "core/constants"; -import { buttonDictionary } from "i18n"; -import "./noAuth.css"; -import { ACCESS_APP_ROLE_ADMIN } from "core/role"; - -export const NoAuthLogin = ({ setOidcClient }) => { - const { apiUrl, portailUrl, setLoading, openNotif } = useContext(AppContext); - const [users, setUsers] = useState([]); - const [selected, setSelected] = useState(""); - const [idSelected, setIdSelected] = useState(""); - const [chooseType, setChooseType] = useState(false); - - const login = id => { - const fakeUserName = FAKE_USERS_LIST[Math.floor(Math.random() * FAKE_USERS_LIST.length)]; - const oidcClient = { - isUserLoggedIn: true, - accessToken: null, - oidcUser: { - id: id, - given_name: fakeUserName.given_name, - family_name: fakeUserName.family_name, - preferred_username: fakeUserName.preferred_username, - "inseegroupedefaut": [ACCESS_APP_ROLE_ADMIN], // Admin role for noAuth - }, - logout: () => (window.location.href = "/"), - }; - setOidcClient(oidcClient); - }; - - useEffect(() => { - const loadContact = async () => { - setLoading(true); - const { data, error } = await API.getUsers(apiUrl)(null); - if (data) { - const { content: usersFetched } = data; - setUsers(usersFetched); - } - if (error) { - openNotif({ - severity: ERROR_SEVERITY, - message: notifDictionary.contactLoadingError, - }); - } - - setLoading(false); - }; - if (users.length === 0 && chooseType) loadContact(); - - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [users, chooseType]); - - const handleChangeChooseType = event => { - setSelected(""); - setIdSelected(""); - setChooseType(event.target.checked); - }; - const handleChangeSelect = event => { - setSelected(event.target.value); - }; - - const handleChangeInput = event => { - setIdSelected(event.target.value); - }; - - const chooseUser = type => { - if (type) { - const { identifier } = users[selected]; - login(identifier); - } else if (!type) login(idSelected); - }; - - return ( -
-
-

- {"Portail d'authentification"} -
- {"Pilotage de la collecte et des contacts"} -

-
-
-
-
-
-
Authentification
-
- - - {`Choix de l'utilisateur`} - - - Avec un identifiant - - Parmi une liste - - -
- {!chooseType && ( - - - - )} - {chooseType && users.length > 0 && ( - - Utilisateurs - - {Number.isInteger(selected) && ( - <> -
- {`Le choix d'utilisateur n'a pas d'influence sur le rôle réel.`} - - )} -
- )} - - {(Number.isInteger(selected) || idSelected) && ( -
- -
- )} -
-
-
- -
-
- ); -}; diff --git a/trash/ui/router/index.jsx b/trash/ui/router/index.jsx deleted file mode 100644 index d33ffdb..0000000 --- a/trash/ui/router/index.jsx +++ /dev/null @@ -1,41 +0,0 @@ -import { BrowserRouter, Routes, Route, Outlet, Navigate } from "react-router-dom"; -import { Footer } from "ui/shared/footer"; -import { Users } from "ui/components/pages/users"; -import { ContactsSearch } from "ui/components/pages/contacts/search"; -import { ContactsDetail } from "ui/components/pages/contacts/detail"; -import { Surveys } from "ui/components/pages/surveys"; -import { Home } from "ui/components/pages/home"; -import ResponsiveAppBar from "ui/shared/appBar"; -import { useContext, useMemo } from "react"; -import { UserAccountContext } from "ui/context/UserAccount"; -import { canManageUser } from "core/role"; - -export const Router = () => { - const { user } = useContext(UserAccountContext); - const canMangeUserInApp = useMemo(() => canManageUser(user.roles), [user]); - - return ( - - - } /> - - - -