Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sistemato menu a seconda del tipo di utente che si connette al portale #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 98 additions & 13 deletions components/layout/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import Nav from 'react-bootstrap/Nav';
import Navbar from 'react-bootstrap/Navbar';
import Head from 'next/head';
import { useEffect, useState } from "react";
import { signIn, signOut, useSession } from "next-auth/react"

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
Expand All @@ -21,7 +22,53 @@ interface HeaderProps {

const Header: React.FC<HeaderProps> = ({ title }) => {
const { data: session, status } = useSession()
const loading = status === "loading"

const [personInfo, setPersonInfo] = useState<any>(null);
const [roles, setRoles] = useState<string[]>([]);
const [rolesOffice, setRolesOffice] = useState<string[]>([]);
const loadingSession = status === "loading";

useEffect(() => {
const fetchUserType = async () => {
if (session) {
try {
const res = await fetch('/api/rest/v4?endpoint=userinfo',
{ method: 'GET' });

if (res.ok) {
const data = await res.json();
console.log("DATA USERINFO>>>> ", data);
setRolesOffice(data.rolesOffice);
setRoles(data.roles);
} else {
console.error("Errore nella chiamata API");
}
} catch (error) {
console.error("Errore di rete", error);
}
}
};
const fetchPersonInfo = async () => {
if (session) {
try {
const res = await fetch('/api/rest/v4?endpoint=personinfo%2Fextend',
{ method: 'GET' });

if (res.ok) {
const data = await res.json();
console.log("DATA PERSONINFO>>>> ", data);
setPersonInfo(data);
} else {
console.error("Errore nella chiamata API");
}
} catch (error) {
console.error("Errore di rete", error);
}
}
};
fetchUserType();
fetchPersonInfo();
}, [session]);

const handleSignOut = async () => {
await signOut({ callbackUrl: '/' });
Expand All @@ -31,21 +78,59 @@ const Header: React.FC<HeaderProps> = ({ title }) => {
const keycloakLogoutUrl = `${logoutUrl}?redirect_uri=${redirectUrl}`;
window.location.replace(keycloakLogoutUrl);
};
const isAdminOrDeveloper = ['ADMIN', 'DEVELOPER'].every(role => roles.includes(role));

const isAdminRolesOffice = ["Amministratore Personale Sola lettura",
"Amministratore Personale","Responsabile Sede","Gestore buoni pasto","Gestore anagrafica"].every(role => rolesOffice.includes(role));

const isEmployee = rolesOffice.includes('Dipendente');

const isGroupManager = ['Responsabile gruppo'].every(role => rolesOffice.includes(role));

const isSeatManager = ["Amministratore Personale","Amministratore Personale Sola lettura",
"Amministratore Tecnico","Responsabile Sede"].every(role => rolesOffice.includes(role));

const hasShiftOrReperibility = personInfo && (personInfo.shiftCategories.length > 0
|| personInfo.reperibilityTypes.length > 0
|| personInfo.categories.length > 0
||personInfo.reperibilities.length > 0);

let navbarElem;
if (loadingSession) {
navbarElem = <><div>Caricamento...</div></>;
} else if (session) {
navbarElem = <>
{isEmployee ? <PersonalDataMenu personInfo={personInfo}/> : ''}

{/* <PersonalWorkflowsMenu /> */}

{/*(isAdminOrDeveloper || isAdminRolesOffice) ? (
<AdminMenu />
)*/}

{isAdminOrDeveloper || isAdminRolesOffice || hasShiftOrReperibility ?
<CalendarsMenu/> : ''
}

{/*(isAdminOrDeveloper || isGroupManager) ? (
<GroupMenu />
)*/}

{/*(isAdminOrDeveloper || isSeatManager) ? (
<ConfigMenu />
)*/}

{/*(isAdminOrDeveloper ) ? (
<ToolsMenu />
)*/}

if(session) {
navbarElem = <>
<PersonalDataMenu />
{/*
<PersonalWorkflowsMenu />
*/}
<CalendarsMenu />
<SelectPeriod />
<Nav className="ms-auto text-white">
<Nav.Link className="text-white" onClick={handleSignOut}>Esci <FontAwesomeIcon icon={faRightFromBracket}/></Nav.Link>
</Nav>
</>
<SelectPeriod/>
<Nav className="ms-auto text-white">
<Nav.Link className="text-white" onClick={handleSignOut}>
Esci <FontAwesomeIcon icon={faRightFromBracket} />
</Nav.Link>
</Nav>
</>;
}

return (<div>
Expand Down
2 changes: 1 addition & 1 deletion components/layout/menu/calendarsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NavDropdown } from "react-bootstrap"
function CalendarsMenu() {
return (
<NavDropdown title="Calendari" id="calendars">
<NavDropdown.Item href="/stampings"><FontAwesomeIcon icon={faCalendarDays} /> Calendario turni</NavDropdown.Item>
<NavDropdown.Item href="/reperibility"><FontAwesomeIcon icon={faCalendarDays} /> Calendario turni</NavDropdown.Item>
<NavDropdown.Item href="/reperibility"><FontAwesomeIcon icon={faCalendarDays} /> Calendario reperibilit&agrave;</NavDropdown.Item>
</NavDropdown>
)
Expand Down
19 changes: 18 additions & 1 deletion components/layout/menu/personalDataMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import { faCalendarDays, faMoneyBill, faUserXmark, faPlane, faCalendar, faClock,
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { NavDropdown } from "react-bootstrap"
import { useSession} from "next-auth/react"
import { PersonShowExtended } from "../../../types/personShowExtended";

function PersonalDataMenu() {
interface PersonalDataMenuProps {
personInfo: PersonShowExtended;
}

const PersonalDataMenu: React.FC<PersonalDataMenuProps> = ({ personInfo }) => {

let userLogon;
const { data: session, status } = useSession()
Expand All @@ -18,6 +23,18 @@ function PersonalDataMenu() {
<NavDropdown.Item href="/absencesYearly"><FontAwesomeIcon icon={faCalendar} /> Assenze Annuali</NavDropdown.Item>
<NavDropdown.Item href="/vacations"><FontAwesomeIcon icon={faPlane} /> Ferie</NavDropdown.Item>
<NavDropdown.Item href="/competences"><FontAwesomeIcon icon={faMoneyBill} /> Competenze</NavDropdown.Item>
{ (personInfo?.personShifts ?? []).length>0 ?
<NavDropdown.Item href="/reperibility">
<FontAwesomeIcon icon={faCalendarDays} />&nbsp;
Calendario turni
</NavDropdown.Item> : ''
}
{ personInfo && personInfo.available ?
<NavDropdown.Item href="/reperibility">
<FontAwesomeIcon icon={faCalendarDays} />&nbsp;
Calendario reperibilit&agrave;
</NavDropdown.Item> : ''
}
<NavDropdown.Item href="/trainingRecap"><FontAwesomeIcon icon={faGraduationCap} /> Ore di formazione</NavDropdown.Item>
<NavDropdown.Item href="/personMonthsHoursRecap"><FontAwesomeIcon icon={faClock} /> Riepilogo orario</NavDropdown.Item>
{/*
Expand Down
27 changes: 27 additions & 0 deletions types/personReperibilityType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { MonthlyCompetenceType } from './monthlyCompetenceType';

/**
* Tipologia di reperibilità
* @export
* @interface PersonReperibilityType
*/
export type PersonReperibilityType = {
/**
* Id univoco
* @type {number}
* @memberof PersonReperibilityType
*/
id: number;
/**
*
* @type {string}
* @memberof PersonReperibilityType
*/
description?: string;
/**
*
* @type {MonthlyCompetenceType}
* @memberof PersonReperibilityType
*/
monthlyCompetenceType?: MonthlyCompetenceType;
}
14 changes: 14 additions & 0 deletions types/personShift.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type PersonShift = {
/**
* Id univoco
* @type {number}
* @memberof PersonShift
*/
id: number;
/**
*
* @type {string}
* @memberof PersonShift
*/
description?: string;
}
170 changes: 170 additions & 0 deletions types/personShowExtended.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import type { UserShowTerse } from './userShowTerse';
import type { PersonShift } from './personShift';
import type { ShiftCategory } from './shiftCategory';
import type { OfficeShowTerse } from './officeShowTerse';
import type { PersonReperibilityType } from './personReperibilityType';

export type PersonShowExtended = {
/**
* Nome
* @type {string}
* @memberof PersonShowExtended
*/
name: string;
/**
* Cognome
* @type {string}
* @memberof PersonShowExtended
*/
surname: string;
/**
* Codice fiscale
* @type {string}
* @memberof PersonShowExtended
*/
fiscalCode?: string;
/**
* Email
* @type {string}
* @memberof PersonShowExtended
*/
email: string;
/**
* Matricola
* @type {string}
* @memberof PersonShowExtended
*/
number?: string;
/**
* eppn - indicatore univoco all'interno dell'organizzazione
* @type {string}
* @memberof PersonShowExtended
*/
eppn?: string;
/**
* livello
* @type {number}
* @memberof PersonShowExtended
*/
qualification: number;
/**
* Id di collegamento con l'anagrafica CNR
* @type {number}
* @memberof PersonShowExtended
*/
perseoId?: number;
/**
* Data di nascita
* @type {Date}
* @memberof PersonShowExtended
*/
birthday?: Date;
/**
* Residenza
* @type {string}
* @memberof PersonShowExtended
*/
residence?: string;
/**
* Numero del telefono ufficio
* @type {string}
* @memberof PersonShowExtended
*/
telephone?: string;
/**
* Numero di fax
* @type {string}
* @memberof PersonShowExtended
*/
fax?: string;
/**
* Numero di cellulare
* @type {string}
* @memberof PersonShowExtended
*/
mobile?: string;
/**
* Abilitato invio delle email si/no
* @type {boolean}
* @memberof PersonShowExtended
*/
wantEmail?: boolean;
/**
* Id della persona
* @type {number}
* @memberof PersonShowExtended
*/
id?: number;
/**
* Data inizio validità
* @type {Date}
* @memberof PersonShowExtended
*/
beginDate?: Date;
/**
* Data fine validità
* @type {Date}
* @memberof PersonShowExtended
*/
endDate?: Date;
/**
*
* @type {UserShowTerse}
* @memberof PersonShowExtended
*/
user?: UserShowTerse;
/**
*
* @type {OfficeShowTerse}
* @memberof PersonShowExtended
*/
office?: OfficeShowTerse;
/**
* Data ultimo aggiornamento
* @type {Date}
* @memberof PersonShowExtended
*/
updatedAt?: Date;
/**
* Data di nascita
* @type {Date}
* @memberof PersonShowExtended
*/
birthDate?: Date;
/**
*
* @type {boolean}
* @memberof PersonShowExtended
*/
available?: boolean;
/**
*
* @type {Array<ShiftCategory>}
* @memberof PersonShowExtended
*/
shiftCategories?: Array<ShiftCategory>;
/**
*
* @type {Array<PersonReperibilityType>}
* @memberof PersonShowExtended
*/
reperibilityTypes?: Array<PersonReperibilityType>;
/**
*
* @type {Array<ShiftCategory>}
* @memberof PersonShowExtended
*/
categories?: Array<ShiftCategory>;
/**
*
* @type {Array<PersonReperibilityType>}
* @memberof PersonShowExtended
*/
reperibilities?: Array<PersonReperibilityType>;
/**
*
* @type {Array<PersonShift>}
* @memberof PersonShowExtended
*/
personShifts?: Array<PersonShift>;
}
Loading