Skip to content

Commit

Permalink
Fix purpose actions (#1030)
Browse files Browse the repository at this point in the history
* fix purpose actions

* fix backToDelegationsList navigation
  • Loading branch information
alten-dturus authored and ruggerocastagnola committed Dec 13, 2024
1 parent 9ea7b4c commit 35bdd40
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useGetAgreementsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useGetDelegationUserRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
11 changes: 9 additions & 2 deletions src/hooks/useGetProviderPurposesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -27,7 +33,8 @@ function useGetProviderPurposesActions(purpose?: Purpose) {
!purpose ||
purpose?.currentVersion?.state === 'ARCHIVED' ||
!isAdmin ||
!!purpose.rejectedVersion
!!purpose.rejectedVersion ||
isDelegator
) {
return { actions }
}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/DelegationDetailsPage/DelegationDetails.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -25,14 +27,17 @@ export const DelegationDetailsPage: React.FC = () => {

const { actions } = useGetDelegationActions(delegation)

const backToDelegationListTabKey =
delegation?.delegator.id === jwt?.organizationId ? 'delegationsGranted' : 'delegationsReceived'

return (
<PageContainer
title={t('title')}
isLoading={isLoading}
backToAction={{
label: t('backToDelegationList'),
to: 'DELEGATIONS',
urlParams: { tab: 'delegationsReceived' },
urlParams: { tab: backToDelegationListTabKey },
}}
topSideActions={actions}
>
Expand Down

0 comments on commit 35bdd40

Please sign in to comment.