Skip to content
Merged
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
@@ -1,4 +1,5 @@
import {
Box,
Button,
FormControlLabel,
Grid,
Expand Down Expand Up @@ -338,6 +339,47 @@ export default function AddUserForm({
});
};

const LiveRegion = ({ fieldName, message }: { fieldName: string; message?: string }) => {
const [delayedMessage, setDelayedMessage] = useState<string>('');

useEffect(() => {
if (!message || message === requiredError) {
setDelayedMessage('');
return;
}

const timer = setTimeout(() => {
setDelayedMessage(message);
}, 1000);

return () => clearTimeout(timer);
}, [message]);

if (!delayedMessage) {
return null;
}

return (
<Box
id={`${fieldName}-live-region`}
role="alert"
style={{
border: 0,
clip: 'rect(0 0 0 0)',
height: '1px',
margin: '-1px',
overflow: 'hidden',
padding: 0,
position: 'absolute',
whiteSpace: 'nowrap',
width: '1px',
}}
>
{delayedMessage}
</Box>
);
};

const baseTextFieldProps = (
field: keyof PartyUserOnCreation,
label: string,
Expand Down Expand Up @@ -386,6 +428,7 @@ export default function AddUserForm({
validTaxcode={validTaxcode}
isMobile={isMobile}
t={t}
LiveRegion={LiveRegion}
/>
)}

Expand Down Expand Up @@ -446,13 +489,13 @@ export default function AddUserForm({
/>
}
aria-label={t(titleKey)}
/*
onClick={async () => {
// TODO set isAddINBulkEAFlow only for role admin not operator
setIsAddInBulkEAFlow(value);
await formik.setFieldValue('toAddOnAggregates', value, true);
}}
*/
/*
onClick={async () => {
// TODO set isAddINBulkEAFlow only for role admin not operator
setIsAddInBulkEAFlow(value);
await formik.setFieldValue('toAddOnAggregates', value, true);
}}
*/
/>
))}
</RadioGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Grid } from '@mui/material';
import { Box, Grid } from '@mui/material';
import { theme } from '@pagopa/mui-italia';
import { TitleBox } from '@pagopa/selfcare-common-frontend/lib';
import { FormikProps } from 'formik';
Expand All @@ -16,6 +16,7 @@ type UserDataSectionProps = {
validTaxcode: string | undefined;
isMobile: boolean;
t: (key: string) => string;
LiveRegion?: React.FC<{ fieldName: string; message?: string }>;
};

export const UserDataSection = ({
Expand All @@ -24,6 +25,7 @@ export const UserDataSection = ({
validTaxcode,
isMobile,
t,
LiveRegion,
}: UserDataSectionProps) => (
<Grid container direction="column" sx={commonStyles}>
<Grid item xs={12}>
Expand All @@ -41,6 +43,7 @@ export const UserDataSection = ({
size="small"
{...baseTextFieldProps('taxCode', t('userEdit.addForm.fiscalCode.label'), '', 'uppercase')}
/>
{LiveRegion && <LiveRegion fieldName="taxCode" message={formik.errors.taxCode} />}
</Grid>
<Grid
item
Expand All @@ -55,18 +58,24 @@ export const UserDataSection = ({
},
}}
>
<CustomTextField
size="small"
style={{ width: isMobile ? '100%' : '49%' }}
{...baseTextFieldProps('name', t('userEdit.addForm.name.label'), '')}
disabled={formik.values.certifiedName || !validTaxcode}
/>
<CustomTextField
size="small"
style={{ width: isMobile ? '100%' : '49%', marginTop: isMobile ? '24px' : 0 }}
{...baseTextFieldProps('surname', t('userEdit.addForm.surname.label'), '')}
disabled={formik.values.certifiedSurname || !validTaxcode}
/>
<Box sx={{ width: isMobile ? '100%' : '49%', position: 'relative' }}>
<CustomTextField
size="small"
style={{ width: '100%' }}
{...baseTextFieldProps('name', t('userEdit.addForm.name.label'), '')}
disabled={formik.values.certifiedName || !validTaxcode}
/>
{LiveRegion && <LiveRegion fieldName="name" message={formik.errors.name} />}
</Box>
<Box sx={{ width: isMobile ? '100%' : '49%', marginTop: isMobile ? '24px' : 0, position: 'relative' }}>
<CustomTextField
size="small"
style={{ width: '100%' }}
{...baseTextFieldProps('surname', t('userEdit.addForm.surname.label'), '')}
disabled={formik.values.certifiedSurname || !validTaxcode}
/>
{LiveRegion && <LiveRegion fieldName="surname" message={formik.errors.surname} />}
</Box>
</Grid>
<Grid item xs={12} mb={3} sx={{ height: '75px' }}>
<CustomTextField
Expand All @@ -79,6 +88,7 @@ export const UserDataSection = ({
)}
disabled={!validTaxcode}
/>
{LiveRegion && <LiveRegion fieldName="email" message={formik.errors.email} />}
</Grid>
<Grid item xs={12} mb={3} sx={{ height: '75px' }}>
<CustomTextField
Expand All @@ -91,6 +101,7 @@ export const UserDataSection = ({
)}
disabled={!validTaxcode}
/>
{LiveRegion && <LiveRegion fieldName="confirmEmail" message={formik.errors.confirmEmail} />}
</Grid>
</Grid>
);
Loading