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

Feature/fix delegations card #1028

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added ByDelegationChip in providerAgreementTableRow + Replaced delega…
…tor logic with hook useGetDelegationUserRole in useGetAgreementAction
martinaCampoli committed Dec 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 6ba582bfb93edc8fa75ff02bfea624f8b074e0ed
21 changes: 7 additions & 14 deletions src/hooks/useGetAgreementsActions.ts
Original file line number Diff line number Diff line change
@@ -11,8 +11,7 @@ import CloseIcon from '@mui/icons-material/Close'
import ContentCopyIcon from '@mui/icons-material/ContentCopy'
import ArchiveIcon from '@mui/icons-material/Archive'
import { AuthHooks } from '@/api/auth'
import { useQuery } from '@tanstack/react-query'
import { DelegationQueries } from '@/api/delegation'
import { useGetDelegationUserRole } from '@/hooks/useGetDelegationUserRole'

type AgreementActions = Record<AgreementState, Array<ActionItem>>

@@ -31,20 +30,14 @@ function useGetAgreementsActions(agreement?: Agreement | AgreementListEntry): {
const { mutate: cloneAgreement } = AgreementMutations.useClone()
const { mutate: archiveAgreement } = AgreementMutations.useArchive()

const { data: activeProducerDelegation } = useQuery({
...DelegationQueries.getProducerDelegationsList({
limit: 50,
offset: 0,
eserviceIds: [agreement?.eservice.id as string],
states: ['ACTIVE'],
}),
enabled: !!agreement,
select: (d) => d.results[0],
})

if (!agreement || mode === null || !isAdmin) return { actions: [] }

const isDelegator = activeProducerDelegation?.delegator.id === jwt?.organizationId
const eserviceId = agreement.eservice.id

const { isDelegator } = useGetDelegationUserRole({
eserviceId,
organizationId: jwt?.organizationId,
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooks cannot be called conditionally, so this hook call must be above line 33


if (isDelegator) return { actions: [] }

Original file line number Diff line number Diff line change
@@ -2,9 +2,11 @@ import { AgreementQueries } from '@/api/agreement'
import type { AgreementListEntry } from '@/api/api.generatedTypes'
import { AuthHooks } from '@/api/auth'
import { ActionMenu, ActionMenuSkeleton } from '@/components/shared/ActionMenu'
import { ByDelegationChip } from '@/components/shared/ByDelegationChip'
import { ButtonSkeleton } from '@/components/shared/MUI-skeletons'
import { StatusChip, StatusChipSkeleton } from '@/components/shared/StatusChip'
import useGetAgreementsActions from '@/hooks/useGetAgreementsActions'
import { useGetDelegationUserRole } from '@/hooks/useGetDelegationUserRole'
import { Link } from '@/router'
import { Box, Chip, Skeleton } from '@mui/material'
import { TableRow } from '@pagopa/interop-fe-commons'
@@ -27,7 +29,12 @@ export const ProviderAgreementsTableRow: React.FC<{ agreement: AgreementListEntr
const eservice = agreement.eservice
const descriptor = agreement.descriptor

const isDelegatedEservice = eservice.producer.id !== AuthHooks.useJwt().jwt?.organizationId
const { isDelegator, isDelegate } = useGetDelegationUserRole({
eserviceId: eservice.id,
organizationId: AuthHooks.useJwt().jwt?.organizationId,
})

const isDelegatedEservice = isDelegate || isDelegator

const handlePrefetch = () => {
queryClient.prefetchQuery(AgreementQueries.getSingle(agreement.id))
@@ -39,7 +46,7 @@ export const ProviderAgreementsTableRow: React.FC<{ agreement: AgreementListEntr
name: eservice.name,
version: descriptor.version,
})}{' '}
{isDelegatedEservice && <Chip label={t('eserviceChip')} />}
{isDelegatedEservice && <ByDelegationChip />}
</>
)