-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/pin 7481 create purpose template step1 modal #1406
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
Merged
Alepazz
merged 17 commits into
feature/PIN-7480-purpose-template-list-page
from
feature/PIN-7481-create-purpose-template-step1-modal
Nov 3, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fb7a861
Added DialogTenantKindPurposeTemplate to create purpose template
martinaCampoli 6b37a7f
Added purpose tempalate dialog to dialog.types
martinaCampoli e879ad2
Removed console.log
martinaCampoli e6f54d9
Fixed routes + commented not available routes
martinaCampoli c77b6ab
Added useGetSidenavItems tests for new sections
martinaCampoli 90db15d
Added tests for purpose templates list page and for dialog + Fixed di…
martinaCampoli f10e408
Fixed types after rebase
martinaCampoli 6a68259
Added Radio button for personal data
martinaCampoli 5456aaf
Fixed tests replaced with rebase
martinaCampoli d3c7f58
Removed isConsumerDelegable from api call for eservice options
martinaCampoli ab89fa4
fix: Changed name to filename in generateApi props to specify generat…
Alepazz 6c1b8e0
feature: Added post create purpose template api call (PIN-7846)
Alepazz 2f0c17c
fix: Rollback generated file formatting and name property (PIN-7846)
Alepazz 284d18c
feature: Added personalData support on purposeTemplate creation (PIN-…
Alepazz 5de43e8
fix: Removed logs (PIN-7846)
Alepazz 70b3cc6
Updated types and commented out handlesPersonalData
martinaCampoli ce294f8
Updated types
martinaCampoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/components/dialogs/DialogTenantKindPurposeTemplate.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import React from 'react' | ||
| import { | ||
| Box, | ||
| Button, | ||
| Dialog, | ||
| DialogActions, | ||
| DialogContent, | ||
| DialogTitle, | ||
| Stack, | ||
| Typography, | ||
| } from '@mui/material' | ||
| import { useTranslation } from 'react-i18next' | ||
| import { useDialog } from '@/stores' | ||
| import type { DialogTenantKindPurposeTemplateProps } from '@/types/dialog.types' | ||
| import { RHFAutocompleteSingle, RHFRadioGroup } from '../shared/react-hook-form-inputs' | ||
| import { FormProvider, useForm } from 'react-hook-form' | ||
| import type { TenantKind } from '@/api/api.generatedTypes' | ||
|
|
||
| export const DialogTenantKindPurposeTemplate: React.FC<DialogTenantKindPurposeTemplateProps> = ({ | ||
| onConfirm, | ||
| }) => { | ||
| const ariaLabelId = React.useId() | ||
|
|
||
| const { closeDialog } = useDialog() | ||
| const { t } = useTranslation('shared-components', { | ||
| keyPrefix: 'dialogPurposeTemplatesTenantKind', | ||
| }) | ||
| const { t: tCommon } = useTranslation('common', { keyPrefix: 'actions' }) | ||
|
|
||
| const handleCancel = () => { | ||
| closeDialog() | ||
| } | ||
|
|
||
| const formMethods = useForm<{ tenantKind: TenantKind; personalData: string }>({ | ||
| defaultValues: { | ||
| tenantKind: 'PA', | ||
| personalData: 'true', | ||
| }, | ||
| }) | ||
|
|
||
| const onSubmit = formMethods.handleSubmit(({ tenantKind, personalData }) => { | ||
| const handlesPersonalData = personalData === 'true' | ||
| onConfirm(tenantKind, handlesPersonalData) | ||
| closeDialog() | ||
| }) | ||
|
|
||
| const options: Array<{ label: string; value: TenantKind }> = [ | ||
| { | ||
| label: t('content.options.labelPA'), | ||
| value: 'PA', | ||
| }, | ||
| { | ||
| label: t('content.options.labelNotPA'), | ||
| value: 'PRIVATE', | ||
| }, | ||
| ] | ||
|
|
||
| const optionsPersonalData: Array<{ label: string; value: string }> = [ | ||
| { | ||
| label: t('content.personalDataRadioBtn.options.true'), | ||
| value: 'true', | ||
| }, | ||
| { | ||
| label: t('content.personalDataRadioBtn.options.false'), | ||
| value: 'false', | ||
| }, | ||
| ] | ||
|
|
||
| return ( | ||
| <Dialog | ||
| open | ||
| onClose={handleCancel} | ||
| aria-labelledby={ariaLabelId} | ||
| maxWidth={'md'} | ||
| fullWidth | ||
| data-testid="create-purpose-modal" | ||
| > | ||
| <FormProvider {...formMethods}> | ||
| <Box component="form" noValidate onSubmit={onSubmit}> | ||
| <DialogTitle id={ariaLabelId}>{t('title')}</DialogTitle> | ||
| <DialogContent> | ||
| <Stack spacing={3}> | ||
| <Typography variant="body1">{t('content.description')}</Typography> | ||
| <RHFAutocompleteSingle | ||
| sx={{ my: 0 }} | ||
| name="tenantKind" | ||
| options={options} | ||
| label={t('content.label')} | ||
| rules={{ required: true }} | ||
| /> | ||
| <RHFRadioGroup | ||
| name="personalData" | ||
| options={optionsPersonalData} | ||
| label={t('content.personalDataRadioBtn.label')} | ||
| rules={{ required: true }} | ||
| row | ||
| /> | ||
| </Stack> | ||
| </DialogContent> | ||
| <DialogActions> | ||
| <Button type="button" variant="outlined" onClick={handleCancel}> | ||
| {tCommon('cancel')} | ||
| </Button> | ||
| <Button type="submit" variant="contained"> | ||
| {tCommon('confirm')} | ||
| </Button> | ||
| </DialogActions> | ||
| </Box> | ||
| </FormProvider> | ||
| </Dialog> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/components/dialogs/__tests__/DialogTenantKindPurposeTemplate.tsx.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import React from 'react' | ||
| import { fireEvent, render, screen, waitFor } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { vi } from 'vitest' | ||
| import { DialogTenantKindPurposeTemplate } from '../DialogTenantKindPurposeTemplate' | ||
|
|
||
| // Mock useDialog to avoid side effects | ||
| vi.mock('@/stores', () => ({ | ||
| useDialog: () => ({ closeDialog: vi.fn() }), | ||
| })) | ||
|
|
||
| describe('DialogTenantKindEserviceTemplate', () => { | ||
| it('renders dialog with autocomplete and handles selection and confirm', async () => { | ||
| const onConfirm = vi.fn() | ||
| render( | ||
| <DialogTenantKindPurposeTemplate type="tenantKindPurposeTemplate" onConfirm={onConfirm} /> | ||
| ) | ||
|
|
||
| // Check dialog title and description | ||
| expect(screen.getByText('title')).toBeInTheDocument() | ||
| expect(screen.getByText('content.description')).toBeInTheDocument() | ||
|
|
||
| const autocompleteInput = screen.getByLabelText('content.label') | ||
|
|
||
| // Focus / click into the autocomplete input | ||
| fireEvent.mouseDown(autocompleteInput) | ||
|
|
||
| // You can also simulate typing if needed | ||
| await userEvent.type(autocompleteInput, 'P') | ||
|
|
||
| // Wait for options to appear | ||
| await waitFor(() => { | ||
| expect(screen.getByText('content.options.labelPA')).toBeInTheDocument() | ||
|
|
||
| expect(screen.getByText('content.options.labelNotPA')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| // Select PRIVATE and confirm | ||
| const privateInput = screen.getByLabelText('content.options.labelNotPA') | ||
| await userEvent.click(privateInput) | ||
| await userEvent.click(screen.getByRole('button', { name: 'select' })) | ||
| expect(onConfirm).toHaveBeenCalledWith('PRIVATE') | ||
| }) | ||
|
|
||
| it('calls closeDialog on cancel', async () => { | ||
| const onConfirm = vi.fn() | ||
| render( | ||
| <DialogTenantKindPurposeTemplate type="tenantKindPurposeTemplate" onConfirm={onConfirm} /> | ||
| ) | ||
| const cancelButton = screen.getByRole('button', { name: 'cancel' }) | ||
| await userEvent.click(cancelButton) | ||
| expect(onConfirm).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.