Skip to content

Commit

Permalink
fix(U255): fix visualizzazione componenti sede 20241220
Browse files Browse the repository at this point in the history
  • Loading branch information
federico-tocci-dxc authored and sgravinadxc committed Jan 23, 2025
1 parent e5aa289 commit caf3b6c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 37 deletions.
59 changes: 34 additions & 25 deletions fe-piattaforma/src/components/DetailLayout/detailLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ const DetailLayout: React.FC<DetailLayoutI> = ({
const navigate = useNavigate();
const device = useAppSelector(selectDevice);
const dispatch = useDispatch();
const { hasUserPermission } = useGuard();
const canModify = hasUserPermission(['upd.sede.gest.prgt','upd.sede.partner']);
const { hasUserPermissionAny } = useGuard();
const canModify = hasUserPermissionAny(['upd.sede.gest.prgt','upd.sede.partner']);
const pagination = useAppSelector(selectEntityPagination);

const handleOnChangePage = (
Expand All @@ -102,17 +102,24 @@ const DetailLayout: React.FC<DetailLayoutI> = ({
const [currentItems, setCurrentItems] = useState<ItemListElemI[]>([]);

useEffect(() => {
const start = (pagination.pageNumber - 1) * pagination.pageSize;
const end = pagination.pageNumber * pagination.pageSize;
setCurrentItems([]);
setTimeout(() => {
setCurrentItems(itemsList?.items.slice(start, end) || []);
}, 0);
}, [pagination.pageNumber, pagination.pageSize, itemsList]);
if (currentTab === 'sedi' && itemsList?.items) {
const start = (pagination.pageNumber - 1) * pagination.pageSize;
const end = pagination.pageNumber * pagination.pageSize;

setCurrentItems([]);
setTimeout(() => {
setCurrentItems(itemsList.items.slice(start, end) || []);
}, 0);
}
}, [currentTab, pagination.pageNumber, pagination.pageSize, itemsList]);

useEffect(() => {
dispatch(setEntityPagination({ pageNumber: 1, pageSize: 4 }));
}, []);
if (currentTab === 'sedi') {
dispatch(setEntityPagination({ pageNumber: 1, pageSize: 4 }));
}else{
setCurrentItems([]);
}
}, [currentTab]);

return (
<>
Expand Down Expand Up @@ -284,20 +291,22 @@ const DetailLayout: React.FC<DetailLayoutI> = ({
{currentTab === 'enti-partner' &&
showItemsList &&
itemsList?.items?.length
? itemsList.items.map((item) => {
return (
<CardStatusActionPartnerAuthority
title={item.nome}
status={item.stato}
key={item.id}
id={item.id}
fullInfo={item.fullInfo}
onActionClick={item.actions}
/>
);
})
? itemsList.items
.filter(item => !item.enteDiRiferimento)
.map((item) => {
return (
<CardStatusActionPartnerAuthority
title={item.nome}
status={item.stato}
key={item.id}
id={item.id}
fullInfo={item.fullInfo}
onActionClick={item.actions}
/>
);
})
: null}
{currentTab === 'sedi' && showItemsList && itemsList?.items?.length
{currentTab === 'sedi' && showItemsList && currentItems?.length
? currentItems
.map((item) => {
return (
Expand All @@ -314,7 +323,7 @@ const DetailLayout: React.FC<DetailLayoutI> = ({
);
})
: null}
{pagination?.totalPages && (
{pagination?.totalPages && currentTab === 'sedi' &&(
<div className='pb-5'>
<Paginator
activePage={pagination.pageNumber}
Expand Down
10 changes: 9 additions & 1 deletion fe-piattaforma/src/hooks/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ const useGuard = () => {
[user, isLogged, permissions]
);

return { hasUserPermission };
const hasUserPermissionAny = useMemo(
() => (requiredPermissions: RolePermissionI[]) => {
if (!isLogged || !user) return false;
return requiredPermissions.some((p) => p === 'visible' || permissions.includes(p));
},
[user, isLogged, permissions]
);

return { hasUserPermission, hasUserPermissionAny };
};

export default useGuard;
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const HeadquartersDetails = () => {
const navigate = useNavigate();
const dispatch = useDispatch();
const device = useAppSelector(selectDevice);
const { hasUserPermission } = useGuard();
const { hasUserPermission, hasUserPermissionAny } = useGuard();
const {
headquarterId,
projectId,
Expand Down Expand Up @@ -299,7 +299,7 @@ const HeadquartersDetails = () => {
break;
}
} else {
buttons = hasUserPermission(['upd.sede.gest.prgt','upd.sede.partner'])
buttons = hasUserPermissionAny(['upd.sede.gest.prgt','upd.sede.partner'])
? [
{
size: 'xs',
Expand Down Expand Up @@ -367,9 +367,9 @@ const HeadquartersDetails = () => {
const getAccordionCTA = (title?: string) => {
switch (title) {
case 'Facilitatori':
return authorityType &&
return (authorityType || identeDiRiferimento) &&
(((authorityType === formTypes.ENTE_GESTORE_PROGRAMMA ||
authorityType === formTypes.ENTE_GESTORE_PROGETTO) &&
authorityType === formTypes.ENTE_GESTORE_PROGETTO || identeDiRiferimento) &&
hasUserPermission(['add.fac'])) ||
(authorityType === formTypes.ENTI_PARTNER &&
hasUserPermission(['add.fac.partner']))) &&
Expand Down Expand Up @@ -431,7 +431,7 @@ const HeadquartersDetails = () => {
(programPolicy !== 'SCD' ? item.title : 'Volontari') || ''
}
totElem={item.items.length}
cta={authorityId ? getAccordionCTA(item.title).cta : null}
cta={authorityId || identeDiRiferimento ? getAccordionCTA(item.title).cta : null}
onClickCta={getAccordionCTA(item.title)?.ctaAction}
lastBottom={index === itemAccordionList.length - 1}
detailAccordion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const ProjectsDetails = () => {
const projectDetails = project.dettagliInfoProgetto;
const programDetails = project.dettagliInfoProgramma;
const managingAuthorityID = project.idEnteGestoreProgetto;
const partnerAuthoritiesList = project.entiPartner;
const [partnerAuthoritiesList, setPartnerAuthoritiesList] = useState(project?.entiPartner);
const headquarterList = project?.sedi;
const authorityInfo = useAppSelector(selectAuthorities).detail;
const [activeTab, setActiveTab] = useState<string>(tabs.INFO);
Expand Down Expand Up @@ -209,6 +209,13 @@ const ProjectsDetails = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [projectId, projectDetails, activeTab]);

useEffect(() => {
setPartnerAuthoritiesList(project.entiPartner?.filter(
(entePartner: { associatoAUtente: boolean }) =>
entePartner.associatoAUtente === true
));
},[project.entiPartner])

useEffect(() => {
/* scrollTo(0, 0); */
centerActiveItem();
Expand Down Expand Up @@ -581,10 +588,7 @@ const ProjectsDetails = () => {
const PartnerAuthoritySection = () => {
setCorrectModal(<ManagePartnerAuthority creation />);
if (
partnerAuthoritiesList?.filter(
(entePartner: { associatoAUtente: boolean }) =>
entePartner.associatoAUtente
)?.length
partnerAuthoritiesList?.length
) {
setButtonsPosition('BOTTOM');
setCurrentForm(undefined);
Expand Down Expand Up @@ -790,7 +794,7 @@ const ProjectsDetails = () => {
active={activeTab === tabs.ENTI_PARTNER}
role='menuitem'
>
<span> Enti partner ({project?.entiPartner?.length || '-'}) </span>
<span> Enti partner ({partnerAuthoritiesList?.length || '-'}) </span>
</NavLink>
</li>
<li ref={sediRef} role='none'>
Expand Down
1 change: 1 addition & 0 deletions fe-piattaforma/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export interface ItemListElemI {
};
default?: boolean;
codiceFiscale?: string;
enteDiRiferimento?: string;
}

export interface ItemsListI {
Expand Down

0 comments on commit caf3b6c

Please sign in to comment.