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: PIN-5827 - Delegated agreement producer management #1058

Open
wants to merge 4 commits into
base: feature/pin-5258-consumer-delegations
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const ProviderAgreementDetailsPageContent: React.FC = () => {
.with({ suspendedByPlatform: true }, () => 'byPlatform' as const)
.otherwise(() => undefined)

const isDelegated = Boolean('delegation' in agreement)

return (
<PageContainer
title={t('providerRead.title')}
Expand All @@ -48,6 +50,11 @@ const ProviderAgreementDetailsPageContent: React.FC = () => {
agreement,
}}
>
{agreement.state === 'PENDING' && isDelegated && (
<Alert sx={{ mb: 3 }} severity="info">
{t('providerRead.delegatedAlert')}
</Alert>
)}
{suspendedBy && (
<Alert sx={{ mb: 3 }} severity="error">
<Trans
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ type ProviderAgreementDetailsContactDrawerProps = {
isOpen: boolean
onClose: VoidFunction
contact: Mail
isDelegatedConsumer?: boolean
}

export const ProviderAgreementDetailsContactDrawer: React.FC<
ProviderAgreementDetailsContactDrawerProps
> = ({ isOpen, onClose, contact }) => {
> = ({ isOpen, onClose, contact, isDelegatedConsumer }) => {
const { t } = useTranslation('agreement', {
keyPrefix: 'providerRead.sections.generalInformations.contactDrawer',
})

return (
<Drawer isOpen={isOpen} onClose={onClose} title={t('title')}>
<Drawer
isOpen={isOpen}
onClose={onClose}
title={t(isDelegatedConsumer ? 'title.delegatedConsumer' : 'title.consumer')}
>
<Stack spacing={2}>
<InformationContainer
label={t('emailField.label')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ export const ProviderAgreementDetailsGeneralInfoSection: React.FC = () => {
const { agreement } = useProviderAgreementDetailsContext()
const downloadContract = AgreementDownloads.useDownloadContract()

const isDelegated = Boolean('delegation' in agreement)

const {
isOpen: isContactDrawerOpen,
openDrawer: openContactDrawer,
closeDrawer: closeContactDrawer,
} = useDrawerState()

const {
isOpen: isDelegatedContactDrawerOpen,
openDrawer: openDelegatedContactDrawer,
closeDrawer: closeDelegatedContactDrawer,
} = useDrawerState()

const [attributesDrawerData, setAttributesDrawerData] = React.useState<{
isOpen: boolean
attributeType: 'certified' | 'declared'
Expand All @@ -34,10 +42,6 @@ export const ProviderAgreementDetailsGeneralInfoSection: React.FC = () => {
attributeType: 'certified',
})

const handleOpenContactDrawer = () => {
openContactDrawer()
}

const handleOpenAttributesDrawer = (type: 'certified' | 'declared') => {
setAttributesDrawerData({
isOpen: true,
Expand Down Expand Up @@ -92,7 +96,17 @@ export const ProviderAgreementDetailsGeneralInfoSection: React.FC = () => {
label: t('consumerDetailsLink.label'),
component: 'button',
type: 'button',
onClick: handleOpenContactDrawer,
onClick: openContactDrawer,
})
}

if (isDelegated && agreement.delegation?.delegate.contactMail) {
actions.push({
startIcon: <ContactMailIcon fontSize="small" />,
label: t('delegatedConsumerDetailsLink.label'),
component: 'button',
type: 'button',
onClick: openDelegatedContactDrawer,
})
}

Expand Down Expand Up @@ -121,6 +135,12 @@ export const ProviderAgreementDetailsGeneralInfoSection: React.FC = () => {
label={t('consumerField.label')}
content={agreement.consumer.name}
/>
{isDelegated && (
<InformationContainer
label={t('delegatedConsumerField.label')}
content={agreement.delegation?.delegate.name ?? '-'}
/>
)}
{agreement.state === 'REJECTED' && agreement.rejectionReason && (
<InformationContainer
label={t('rejectionMessageField.label')}
Expand All @@ -137,6 +157,14 @@ export const ProviderAgreementDetailsGeneralInfoSection: React.FC = () => {
contact={agreement.consumer.contactMail}
/>
)}
{agreement.delegation?.delegate.contactMail && (
<ProviderAgreementDetailsContactDrawer
isOpen={isDelegatedContactDrawerOpen}
onClose={closeDelegatedContactDrawer}
contact={agreement.delegation?.delegate.contactMail}
isDelegatedConsumer={true}
/>
)}
<ProviderAgreementDetailsAttributesDrawer
isOpen={attributesDrawerData.isOpen}
onClose={closeAttributesDrawer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ 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 { Box, Skeleton } from '@mui/material'
import { TableRow } from '@pagopa/interop-fe-commons'
import { useQueryClient } from '@tanstack/react-query'
import React from 'react'
Expand All @@ -29,13 +28,6 @@ export const ProviderAgreementsTableRow: React.FC<{ agreement: AgreementListEntr
const eservice = agreement.eservice
const descriptor = agreement.descriptor

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

const isDelegatedEservice = isDelegate || isDelegator

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

Expand Down
12 changes: 11 additions & 1 deletion src/static/locales/en/agreement.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"backToRequestsBtn": "Go back to requests",
"providerRead": {
"title": "Manage agreement",
"delegatedAlert": "This agreement relates to a delegation.",
"suspendedAlert": {
"byProducer": "This agreement has been suspended by the PROVIDER. Until it is reactivated it will not be possible to access the data.",
"byConsumer": "This agreement has been suspended by the CONSUMER. Until it is reactivated it will not be possible to access the data.",
Expand All @@ -17,6 +18,9 @@
"consumerField": {
"label": "Consumer"
},
"delegatedConsumerField": {
"label": "Delegated Consumer"
},
"rejectionMessageField": {
"label": "Reason for rejection"
},
Expand All @@ -35,8 +39,14 @@
"consumerDetailsLink": {
"label": "View consumer details"
},
"delegatedConsumerDetailsLink": {
"label": "View delegated consumer details"
},
"contactDrawer": {
"title": "Consumer contacts",
"title": {
"delegatedConsumer": "Delegated consumer contacts",
"consumer": "Consumer contacts"
},
"emailField": {
"label": "Contact email"
},
Expand Down
12 changes: 11 additions & 1 deletion src/static/locales/it/agreement.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"backToRequestsBtn": "Torna alle richieste",
"providerRead": {
"title": "Gestisci richiesta di fruizione",
"delegatedAlert": "Questa richiesta di fruizione è relativa a una delega.",
"suspendedAlert": {
"byProducer": "Questa richiesta di fruizione è stata sospesa da <strong>erogatore</strong>. Fino alla sua riattivazione non sarà possibile accedere ai dati.",
"byConsumer": "Questa richiesta di fruizione è stata sospesa da <strong>fruitore</strong>. Fino alla sua riattivazione non sarà possibile accedere ai dati.",
Expand All @@ -17,6 +18,9 @@
"consumerField": {
"label": "Fruitore"
},
"delegatedConsumerField": {
"label": "Delegato alla fruizione"
},
"rejectionMessageField": {
"label": "Motivazione del rifiuto"
},
Expand All @@ -35,8 +39,14 @@
"consumerDetailsLink": {
"label": "Visualizza dettagli fruitore"
},
"delegatedConsumerDetailsLink": {
"label": "Visualizza dettagli del delegato alla fruizione"
},
"contactDrawer": {
"title": "Contatti del fruitore",
"title": {
"delegatedConsumer": "Contatti del delegato alla fruizione",
"consumer": "Contatti del fruitore"
},
"emailField": {
"label": "Email di contatto"
},
Expand Down
Loading