Skip to content

Commit

Permalink
Hide edit button when the eservice is by delegation and the user is d…
Browse files Browse the repository at this point in the history
…elegator (#1024)
  • Loading branch information
alten-dturus authored Dec 9, 2024
1 parent c6c627c commit 7ca5879
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@ import { useTranslation } from 'react-i18next'
import EditIcon from '@mui/icons-material/Edit'
import type { AttributeKey } from '@/types/attribute.types'
import { ProviderEServiceUpdateDescriptorAttributesDrawer } from './ProviderEServiceUpdateDescriptorAttributesDrawer'
import { AuthHooks } from '@/api/auth'
import { useGetDelegationUserRole } from '@/hooks/useGetDelegationUserRole'

export const ProviderEServiceDescriptorAttributes: React.FC = () => {
const { t } = useTranslation('eservice', { keyPrefix: 'read.sections.attributes' })
const { t: tCommon } = useTranslation('common')
const { jwt } = AuthHooks.useJwt()

const { eserviceId, descriptorId } = useParams<'PROVIDE_ESERVICE_MANAGE'>()
const { data: descriptorAttributes } = useSuspenseQuery({
...EServiceQueries.getDescriptorProvider(eserviceId, descriptorId),
select: (d) => d.attributes,
})

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

const [editAttributeDrawerState, setEditAttributeDrawerState] = useState<{
kind: AttributeKey
isOpen: boolean
}>({ isOpen: false, kind: 'certified' })

const getAttributeSectionActions = (kind: AttributeKey): Array<ActionItemButton> | undefined => {
if (descriptorAttributes[kind].length === 0) return
if (descriptorAttributes[kind].length === 0 || isDelegator) return

return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@ import { EServiceVersionSelectorDrawer } from '@/components/shared/EServiceVersi
import EditIcon from '@mui/icons-material/Edit'
import { ProviderEServiceUpdateDescriptionDrawer } from './ProviderEServiceUpdateDescriptionDrawer'
import { useSuspenseQuery } from '@tanstack/react-query'
import { useGetDelegationUserRole } from '@/hooks/useGetDelegationUserRole'
import { AuthHooks } from '@/api/auth'

export const ProviderEServiceGeneralInfoSection: React.FC = () => {
const { t } = useTranslation('eservice', {
keyPrefix: 'read.sections.generalInformations',
})
const { t: tCommon } = useTranslation('common')
const { jwt } = AuthHooks.useJwt()

const { eserviceId, descriptorId } = useParams<'PROVIDE_ESERVICE_MANAGE'>()
const { data: descriptor } = useSuspenseQuery(
EServiceQueries.getDescriptorProvider(eserviceId, descriptorId)
)

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

const downloadConsumerList = EServiceDownloads.useDownloadConsumerList()
const exportVersion = EServiceDownloads.useExportVersion()

Expand Down Expand Up @@ -94,13 +102,17 @@ export const ProviderEServiceGeneralInfoSection: React.FC = () => {
innerSection
title={t('eserviceDescription.label')}
titleTypographyProps={{ variant: 'body1', fontWeight: 600 }}
topSideActions={[
{
action: openEServiceUpdateDescriptionDrawer,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]}
topSideActions={
isDelegator
? []
: [
{
action: openEServiceUpdateDescriptionDrawer,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]
}
>
<Typography variant="body2">{descriptor.eservice.description}</Typography>
</SectionContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import AttachFileIcon from '@mui/icons-material/AttachFile'
import { EServiceDownloads } from '@/api/eservice'
import { getDownloadDocumentName } from '@/utils/eservice.utils'
import { ProviderEServiceUpdateDocumentationDrawer } from './ProviderEServiceUpdateDocumentationDrawer'
import { AuthHooks } from '@/api/auth'
import { useGetDelegationUserRole } from '@/hooks/useGetDelegationUserRole'

type ProviderEServiceDocumentationSectionProps = {
descriptor: ProducerEServiceDescriptor
Expand All @@ -24,6 +26,13 @@ export const ProviderEServiceDocumentationSection: React.FC<
})
const { t: tCommon } = useTranslation('common')

const { jwt } = AuthHooks.useJwt()

const { isDelegator } = useGetDelegationUserRole({
eserviceId: descriptor.eservice.id,
organizationId: jwt?.organizationId,
})

const docs = [descriptor.interface, ...descriptor.docs]

const { isOpen, openDrawer, closeDrawer } = useDrawerState()
Expand All @@ -50,13 +59,17 @@ export const ProviderEServiceDocumentationSection: React.FC<
<SectionContainer
innerSection
title={t('documentation.title')}
topSideActions={[
{
action: onEdit,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]}
topSideActions={
isDelegator
? []
: [
{
action: onEdit,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]
}
>
<InformationContainer
label={t('documentation.label')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ProviderEServiceUsefulLinksSection } from './ProviderEServiceUsefulLink
import { ProviderEServiceDocumentationSection } from './ProviderEServiceDocumentationSection'
import { useSuspenseQuery } from '@tanstack/react-query'
import { STAGE } from '@/config/env'
import { PagoPAEnvVars } from '@/types/common.types'
import type { PagoPAEnvVars } from '@/types/common.types'

export const ProviderEServiceTechnicalInfoSection: React.FC = () => {
const signalHubFlagDisabledStage: PagoPAEnvVars['STAGE'][] = ['PROD', 'UAT']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { InformationContainer } from '@pagopa/interop-fe-commons'
import { formatThousands, secondsToMinutes } from '@/utils/format.utils'
import { useDrawerState } from '@/hooks/useDrawerState'
import { ProviderEServiceUpdateThresholdsDrawer } from './ProviderEServiceUpdateThresholdsDrawer'
import { AuthHooks } from '@/api/auth'
import { useGetDelegationUserRole } from '@/hooks/useGetDelegationUserRole'

type ProviderEServiceThresholdsSectionProps = {
descriptor: ProducerEServiceDescriptor
Expand All @@ -21,6 +23,13 @@ export const ProviderEServiceThresholdsSection: React.FC<
})
const { t: tCommon } = useTranslation('common')

const { jwt } = AuthHooks.useJwt()

const { isDelegator } = useGetDelegationUserRole({
eserviceId: descriptor.eservice.id,
organizationId: jwt?.organizationId,
})

const voucherLifespan = secondsToMinutes(descriptor.voucherLifespan)

const { isOpen, openDrawer, closeDrawer } = useDrawerState()
Expand All @@ -34,13 +43,17 @@ export const ProviderEServiceThresholdsSection: React.FC<
<SectionContainer
innerSection
title={t('thresholds.title')}
topSideActions={[
{
action: onEdit,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]}
topSideActions={
isDelegator
? []
: [
{
action: onEdit,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]
}
>
<Stack spacing={2}>
<InformationContainer
Expand Down

0 comments on commit 7ca5879

Please sign in to comment.