Skip to content

Commit

Permalink
update dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
alten-dturus committed Dec 20, 2024
1 parent 2ef8c1b commit e73d756
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/components/dialogs/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import type {
DialogRemoveUserFromKeychainProps,
DialogDeleteProducerKeychainKeyProps,
DialogDelegationsProps,
DialogAcceptProducerDelegationProps,
DialogRejectProducerDelegationProps,
DialogAcceptDelegationProps,
DialogRejectDelegationProps,
DialogRevokeProducerDelegationProps,
DialogRejectDelegatedVersionDraftProps,
} from '@/types/dialog.types'
Expand All @@ -37,8 +37,8 @@ import { DialogSetTenantMail } from './DialogSetTenantMail'
import { DialogRemoveUserFromKeychain } from './DialogRemoveUserFromKeychain'
import { DialogDeleteProducerKeychainKey } from './DialogDeleteProducerKeychainKey'
import { DialogDelegations } from './DialogDelegations'
import { DialogAcceptProducerDelegation } from './DialogAcceptProducerDelegation'
import { DialogRejectProducerDelegation } from './DialogRejectProducerDelegation'
import { DialogAcceptDelegation } from './DialogAcceptDelegation'
import { DialogRejectDelegation } from './DialogRejectDelegation'
import { DialogRevokeProducerDelegation } from './DialogRevokeProducerDelegation'
import { DialogRejectDelegatedVersionDraft } from './DialogRejectDelegatedVersionDraft'

Expand All @@ -57,8 +57,8 @@ function match<T>(
onRemoveUserFromKeychain: (props: DialogRemoveUserFromKeychainProps) => T,
onDeleteProducerKeychainKey: (props: DialogDeleteProducerKeychainKeyProps) => T,
onDelegations: (props: DialogDelegationsProps) => T,
onAcceptDelegation: (props: DialogAcceptProducerDelegationProps) => T,
onRejectDelegation: (props: DialogRejectProducerDelegationProps) => T,
onAcceptDelegation: (props: DialogAcceptDelegationProps) => T,
onRejectDelegation: (props: DialogRejectDelegationProps) => T,
onRevokeProducerDelegation: (props: DialogRevokeProducerDelegationProps) => T,
onRejectDelegatedVersionDraft: (props: DialogRejectDelegatedVersionDraftProps) => T
) {
Expand Down Expand Up @@ -119,8 +119,8 @@ const _Dialog = match(
(props) => <DialogRemoveUserFromKeychain {...props} />,
(props) => <DialogDeleteProducerKeychainKey {...props} />,
(props) => <DialogDelegations {...props} />,
(props) => <DialogAcceptProducerDelegation {...props} />,
(props) => <DialogRejectProducerDelegation {...props} />,
(props) => <DialogAcceptDelegation {...props} />,
(props) => <DialogRejectDelegation {...props} />,
(props) => <DialogRevokeProducerDelegation {...props} />,
(props) => <DialogRejectDelegatedVersionDraft {...props} />
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DelegationMutations } from '@/api/delegation'
import { useDialog } from '@/stores'
import type { DialogAcceptProducerDelegationProps } from '@/types/dialog.types'
import type { DialogAcceptDelegationProps } from '@/types/dialog.types'
import {
Button,
Checkbox,
Expand All @@ -14,19 +14,27 @@ import {
} from '@mui/material'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { match } from 'ts-pattern'

export const DialogAcceptProducerDelegation: React.FC<DialogAcceptProducerDelegationProps> = ({
export const DialogAcceptDelegation: React.FC<DialogAcceptDelegationProps> = ({
delegationId,
delegationKind,
}) => {
const ariaLabelId = React.useId()

const { t: tCommon } = useTranslation('common', { keyPrefix: 'actions' })
const { t } = useTranslation('shared-components', {
keyPrefix: 'dialogAcceptProducerDelegation',
keyPrefix: 'dialogAcceptDelegation',
})

const { closeDialog } = useDialog()
const { mutate: acceptDelegation } = DelegationMutations.useApproveProducerDelegation()
const { mutate: acceptProducerDelegation } = DelegationMutations.useApproveProducerDelegation()
const { mutate: acceptConsumerDelegation } = DelegationMutations.useApproveConsumerDelegation()

const acceptDelegation = match(delegationKind)
.with('DELEGATED_PRODUCER', () => acceptProducerDelegation)
.with('DELEGATED_CONSUMER', () => acceptConsumerDelegation)
.exhaustive()

const [isConfirmCheckboxChecked, setIsConfirmCheckboxChecked] = React.useState<boolean>(false)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import { DelegationMutations } from '@/api/delegation'
import { useDialog } from '@/stores'
import type { DialogRejectProducerDelegationProps } from '@/types/dialog.types'
import type { DialogRejectDelegationProps } from '@/types/dialog.types'
import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle } from '@mui/material'
import React from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { RHFTextField } from '../shared/react-hook-form-inputs'
import { useTranslation } from 'react-i18next'
import { match } from 'ts-pattern'

type RejectDelegationFormValues = {
reason: string
}

export const DialogRejectProducerDelegation: React.FC<DialogRejectProducerDelegationProps> = ({
export const DialogRejectDelegation: React.FC<DialogRejectDelegationProps> = ({
delegationId,
delegationKind,
}) => {
const ariaLabelId = React.useId()

const { t: tCommon } = useTranslation('common', { keyPrefix: 'actions' })
const { t } = useTranslation('shared-components', {
keyPrefix: 'dialogRejectProducerDelegation',
keyPrefix: 'dialogRejectDelegation',
})
const { closeDialog } = useDialog()

const { mutate: rejectDelegation } = DelegationMutations.useRejectProducerDelegation()
const { mutate: rejectProducerDelegation } = DelegationMutations.useRejectProducerDelegation()
const { mutate: rejectConsumerDelegation } = DelegationMutations.useRejectConsumerDelegation()

const rejectDelegation = match(delegationKind)
.with('DELEGATED_PRODUCER', () => rejectProducerDelegation)
.with('DELEGATED_CONSUMER', () => rejectConsumerDelegation)
.exhaustive()

const formMethods = useForm<RejectDelegationFormValues>({
defaultValues: { reason: '' },
Expand Down
4 changes: 2 additions & 2 deletions src/static/locales/en/shared-components.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"title": "Confirm public key deletion",
"description": "The key can no longer be used to sign responses to users of your e-services. To find out more, <1>read the guide</1>."
},
"dialogAcceptProducerDelegation": {
"dialogAcceptDelegation": {
"title": "Appointment of Data Controller",
"content": {
"description": "Please remember that it is necessary to have been appointed as Personal Data Controller, by signing the deed required by art. 28 of the GDPR, before starting any processing activity via the infrastructure on behalf of the Delegator, Data Controller.",
Expand All @@ -153,7 +153,7 @@
"accept": "Accept delegation"
}
},
"dialogRejectProducerDelegation": {
"dialogRejectDelegation": {
"title": "Reject delegation",
"content": {
"reason": {
Expand Down
4 changes: 2 additions & 2 deletions src/static/locales/it/shared-components.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"title": "Conferma eliminazione chiave pubblica",
"description": "La chiave non potrà più essere utilizzata per firmare risposte verso i fruitori dei tuoi e-service. Per saperne di più, <1>leggi la guida</1>."
},
"dialogAcceptProducerDelegation": {
"dialogAcceptDelegation": {
"title": "Nomina Responsabile del Trattamento",
"content": {
"description": "Si ricorda che è necessario essere stati nominati Responsabile del Trattamento ai dati personali, con sottoscrizione dell'atto previsto dall'art. 28 del GDPR, prima di avviare qualsiasi attività di trattamento tramite l'infrastruttura per conto del Delegante, Titolare del Trattamento.",
Expand All @@ -153,7 +153,7 @@
"accept": "Accetta delega"
}
},
"dialogRejectProducerDelegation": {
"dialogRejectDelegation": {
"title": "Rifiuta delega",
"content": {
"reason": {
Expand Down
11 changes: 7 additions & 4 deletions src/types/dialog.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
Agreement,
RequesterCertifiedAttribute,
CompactPurposeEService,
DelegationKind,
} from '@/api/api.generatedTypes'
import type { DialogProps as MUIDialogProps } from '@mui/material'

Expand Down Expand Up @@ -29,8 +30,8 @@ export type DialogProps =
| DialogRemoveUserFromKeychainProps
| DialogDeleteProducerKeychainKeyProps
| DialogDelegationsProps
| DialogAcceptProducerDelegationProps
| DialogRejectProducerDelegationProps
| DialogAcceptDelegationProps
| DialogRejectDelegationProps
| DialogRevokeProducerDelegationProps
| DialogRejectDelegatedVersionDraftProps

Expand Down Expand Up @@ -115,14 +116,16 @@ export type DialogDelegationsProps = {
onConfirm: () => void
}

export type DialogAcceptProducerDelegationProps = {
export type DialogAcceptDelegationProps = {
type: 'acceptDelegation'
delegationId: string
delegationKind: DelegationKind
}

export type DialogRejectProducerDelegationProps = {
export type DialogRejectDelegationProps = {
type: 'rejectDelegation'
delegationId: string
delegationKind: DelegationKind
}

export type DialogRevokeProducerDelegationProps = {
Expand Down

0 comments on commit e73d756

Please sign in to comment.