/* eslint-disable import/prefer-default-export */ import React from 'react'; import { replace } from './helpers'; const impersonationLabels: Record> = { IMPERSONATION_SELECT_OPTION_CPR: { da: 'CPR-nr.', en: 'CPR no.' }, IMPERSONATION_SELECT_OPTION_EMAIL: { da: 'E-mail', en: 'Email' }, IMPERSONATION_SELECT_OPTION_AUID: { da: 'AU-id', en: 'AU ID' }, IMPERSONATION_SELECT_OPTION_STUDENTNUMBER: { da: 'Studienummer', en: 'Student Number' }, }; declare global { interface Window { IMPERSONATE_AUID: string; IMPERSONATE_VALUE: string; IMPERSONATE_TYPE: string; PHASE: number; REAL_PHASE: number; authenticated: boolean; userContext: AU.IUserContext; impersonateError: boolean; } } const portals: (lang: string) => AU.IPortalContext[] = (lang: string) => [ { name: 'mitstudie', impersonationSetup: { auid: window.IMPERSONATE_AUID, value: window.IMPERSONATE_VALUE, type: window.IMPERSONATE_TYPE, }, impersonationOptions: [ { value: 'auid', label: impersonationLabels.IMPERSONATION_SELECT_OPTION_AUID[lang], }, { value: 'studentnumber', label: impersonationLabels.IMPERSONATION_SELECT_OPTION_STUDENTNUMBER[lang], }, ], deactivateFormContent: ( activatedText: string, replaceText: string[], replaceWith: string[], portal: AU.IPortalContext, ) => ( <>
), }, { name: 'minansoegning', impersonationSetup: { auid: window.IMPERSONATE_AUID, value: window.IMPERSONATE_VALUE, type: window.IMPERSONATE_TYPE, phase: window.PHASE, realPhase: window.REAL_PHASE, }, impersonationOptions: [ { value: 'auid', label: impersonationLabels.IMPERSONATION_SELECT_OPTION_AUID[lang], }, { value: 'cpr', label: impersonationLabels.IMPERSONATION_SELECT_OPTION_CPR[lang], }, { value: 'email', label: impersonationLabels.IMPERSONATION_SELECT_OPTION_EMAIL[lang], }, ], deactivateFormContent: ( activatedText: string, replaceText: string[], replaceWith: string[], portal: AU.IPortalContext, ) => ( <>
), }, { name: 'mitmedarbejdere', impersonationSetup: { auid: '', value: '', type: '', }, impersonationOptions: [], deactivateFormContent: ( activatedText: string, replaceText: string[], replaceWith: string[], portal: AU.IPortalContext, ) => ( <>
), }, ]; export const getPortalByName = ( lang: string, name: string, ): AU.IPortalContext | null => portals(lang).find((portal) => portal.name === name) ?? null; export const impersonationPortalElement = document.querySelector('.page__pre-header'); export const isImpersonating = (): boolean => { if (window.userContext == null) { return false; } if (window.userContext.impersonatedUser == null) { return false; } return true; }; export const impersonationHasErrored = (): boolean => window.impersonateError;