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

Mpdx 8159 fix email addresses style updates #1069

Merged
merged 4 commits into from
Sep 16, 2024
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
111 changes: 85 additions & 26 deletions src/components/Tool/FixEmailAddresses/EmailValidationForm.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
import { Grid, IconButton, TextField } from '@mui/material';
import {
Box,
FormControl,
FormHelperText,
Grid,
IconButton,
TextField,
Theme,
Tooltip,
} from '@mui/material';
import { styled } from '@mui/material/styles';
import { Form, Formik } from 'formik';
import clsx from 'clsx';
import { Formik } from 'formik';
import { useSnackbar } from 'notistack';
import { useTranslation } from 'react-i18next';
import { makeStyles } from 'tss-react/mui';
import * as yup from 'yup';
import { AddIcon } from 'src/components/Contacts/ContactDetails/ContactDetailsTab/StyledComponents';
import i18n from 'src/lib/i18n';
import { useEmailAddressesMutation } from './AddEmailAddress.generated';
import { RowWrapper } from './FixEmailAddressPerson/FixEmailAddressPerson';
import {
GetInvalidEmailAddressesDocument,
GetInvalidEmailAddressesQuery,
} from './FixEmailAddresses.generated';

const useStyles = makeStyles()((theme: Theme) => ({
responsiveBorder: {
[theme.breakpoints.down('xs')]: {
paddingBottom: theme.spacing(2),
borderBottom: `1px solid ${theme.palette.cruGrayMedium.main}`,
},
},
paddingX: {
paddingLeft: theme.spacing(2),
paddingRight: theme.spacing(2),
},
paddingB2: {
paddingBottom: theme.spacing(1),
},
iconButton: {
display: 'flex',
alignItems: 'center',
paddingLeft: theme.spacing(2),
paddingRight: theme.spacing(2),
},
}));

const ContactInputField = styled(TextField, {
shouldForwardProp: (prop) => prop !== 'destroyed',
})(({ destroyed }: { destroyed: boolean }) => ({
Expand Down Expand Up @@ -52,6 +84,7 @@ const EmailValidationForm = ({
const { t } = useTranslation();
const [emailAddressesMutation] = useEmailAddressesMutation();
const { enqueueSnackbar } = useSnackbar();
const { classes } = useStyles();

const initialEmail = {
email: '',
Expand Down Expand Up @@ -134,34 +167,60 @@ const EmailValidationForm = ({
validationSchema={validationSchema}
onSubmit={onSubmit}
>
{({ values, handleChange, handleBlur, isValid, touched, errors }) => (
<Form>
<RowWrapper>
<Grid container>
<ContactInputField
destroyed={false}
label={t('New Email Address')}
type="email"
name="email"
value={values.email}
onChange={handleChange}
onBlur={handleBlur}
error={touched.email && Boolean(errors.email)}
helperText={
touched.email && Boolean(errors.email) ? errors.email : ''
}
/>
{({
values,
handleChange,
handleBlur,
touched,
errors,
handleSubmit,
isValid,
}) => (
<>
<Grid item xs={12} sm={6} className={classes.paddingB2}>
<Box
display="flex"
justifyContent="flex-start"
className={clsx(classes.responsiveBorder, classes.paddingX)}
>
<FormControl fullWidth>
<ContactInputField
destroyed={false}
label={t('New Email Address')}
type="email"
name="email"
value={values.email}
style={{ width: '100%' }}
size="small"
onChange={handleChange}
onBlur={handleBlur}
/>
</FormControl>

<IconButton
type="submit"
color="primary"
onClick={() => handleSubmit()}
className={classes.iconButton}
disabled={!isValid || values.email === ''}
data-testid={`addButton-${initialEmail.personId}`}
>
<AddIcon fontSize="large" />
<Tooltip title="Add Address">
<AddIcon fontSize="small" />
</Tooltip>
</IconButton>
</Grid>
</RowWrapper>
</Form>
</Box>
</Grid>

{touched.email && Boolean(errors.email) && (
<>
<Grid item xs={12} sm={6}></Grid>
<Grid item xs={12} sm={6}>
<FormHelperText error={true} className={classes.paddingX}>
{errors.email}
</FormHelperText>
</Grid>
</>
)}
</>
)}
</Formik>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const person: PersonInvalidEmailFragment = {
firstName: 'Test',
lastName: 'Contact',
contactId: 'contactTestId',
avatar: '',
emailAddresses: {
nodes: [
{
Expand Down
Loading
Loading