diff --git a/src/hooks/useGetAgreementsActions.ts b/src/hooks/useGetAgreementsActions.ts index d4f6d104a..0e6ce0d05 100644 --- a/src/hooks/useGetAgreementsActions.ts +++ b/src/hooks/useGetAgreementsActions.ts @@ -30,7 +30,7 @@ function useGetAgreementsActions(agreement?: Agreement | AgreementListEntry): { const { mutate: cloneAgreement } = AgreementMutations.useClone() const { mutate: archiveAgreement } = AgreementMutations.useArchive() const { isDelegator } = useGetDelegationUserRole({ - eserviceId: agreement?.eservice.id as string, + eserviceId: agreement?.eservice.id, organizationId: jwt?.organizationId, }) diff --git a/src/hooks/useGetDelegationUserRole.ts b/src/hooks/useGetDelegationUserRole.ts index a756f09b9..6c89b62f2 100644 --- a/src/hooks/useGetDelegationUserRole.ts +++ b/src/hooks/useGetDelegationUserRole.ts @@ -5,17 +5,18 @@ export function useGetDelegationUserRole({ eserviceId, organizationId, }: { - eserviceId: string + eserviceId: string | undefined organizationId: string | undefined }) { const { data: producerDelegations } = useQuery({ ...DelegationQueries.getProducerDelegationsList({ - eserviceIds: [eserviceId], + eserviceIds: [eserviceId as string], states: ['ACTIVE'], kind: 'DELEGATED_PRODUCER', offset: 0, limit: 50, }), + enabled: Boolean(eserviceId), select: (delegations) => delegations.results, }) diff --git a/src/hooks/useGetProviderPurposesActions.ts b/src/hooks/useGetProviderPurposesActions.ts index 727548ceb..d76a9d2cb 100644 --- a/src/hooks/useGetProviderPurposesActions.ts +++ b/src/hooks/useGetProviderPurposesActions.ts @@ -7,11 +7,17 @@ import PauseCircleOutlineIcon from '@mui/icons-material/PauseCircleOutline' import PlayCircleOutlineIcon from '@mui/icons-material/PlayCircleOutline' import CloseIcon from '@mui/icons-material/Close' import { useDialog } from '@/stores' +import { useGetDelegationUserRole } from './useGetDelegationUserRole' function useGetProviderPurposesActions(purpose?: Purpose) { const { t } = useTranslation('common', { keyPrefix: 'actions' }) - const { isAdmin } = AuthHooks.useJwt() + const { isAdmin, jwt } = AuthHooks.useJwt() + + const { isDelegator } = useGetDelegationUserRole({ + eserviceId: purpose?.eservice.id, + organizationId: jwt?.organizationId, + }) const { mutate: activateVersion } = PurposeMutations.useActivateVersion() const { mutate: suspendVersion } = PurposeMutations.useSuspendVersion() @@ -27,7 +33,8 @@ function useGetProviderPurposesActions(purpose?: Purpose) { !purpose || purpose?.currentVersion?.state === 'ARCHIVED' || !isAdmin || - !!purpose.rejectedVersion + !!purpose.rejectedVersion || + isDelegator ) { return { actions } } diff --git a/src/pages/DelegationDetailsPage/DelegationDetails.page.tsx b/src/pages/DelegationDetailsPage/DelegationDetails.page.tsx index cff340250..e02627f5d 100644 --- a/src/pages/DelegationDetailsPage/DelegationDetails.page.tsx +++ b/src/pages/DelegationDetailsPage/DelegationDetails.page.tsx @@ -12,10 +12,12 @@ import { Alert, Link } from '@mui/material' import { useDrawerState } from '@/hooks/useDrawerState' import { RejectReasonDrawer } from '@/components/shared/RejectReasonDrawer' import { useGetDelegationActions } from '@/hooks/useGetDelegationActions' +import { AuthHooks } from '@/api/auth' export const DelegationDetailsPage: React.FC = () => { const { delegationId } = useParams<'DELEGATION_DETAILS'>() const { t } = useTranslation('party', { keyPrefix: 'delegations.details' }) + const { jwt } = AuthHooks.useJwt() const { data: delegation, isLoading } = useQuery( DelegationQueries.getSingle({ delegationId: delegationId }) @@ -25,6 +27,9 @@ export const DelegationDetailsPage: React.FC = () => { const { actions } = useGetDelegationActions(delegation) + const backToDelegationListTabKey = + delegation?.delegator.id === jwt?.organizationId ? 'delegationsGranted' : 'delegationsReceived' + return ( { backToAction={{ label: t('backToDelegationList'), to: 'DELEGATIONS', - urlParams: { tab: 'delegationsReceived' }, + urlParams: { tab: backToDelegationListTabKey }, }} topSideActions={actions} >