mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
Shaswat: Remove usage of useStyles from UserForm (#2619)
Changes for [issue](https://github.com/Unleash/unleash/issues/2606) Co-authored-by: Nuno Góis <github@nunogois.com>
This commit is contained in:
parent
1bd95d44e5
commit
59c043e1ab
@ -1,60 +0,0 @@
|
|||||||
import { makeStyles } from 'tss-react/mui';
|
|
||||||
|
|
||||||
export const useStyles = makeStyles()(theme => ({
|
|
||||||
container: {
|
|
||||||
maxWidth: '400px',
|
|
||||||
},
|
|
||||||
form: {
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
},
|
|
||||||
input: { width: '100%', marginBottom: '1rem' },
|
|
||||||
label: {
|
|
||||||
minWidth: '300px',
|
|
||||||
[theme.breakpoints.down(600)]: {
|
|
||||||
minWidth: 'auto',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
buttonContainer: {
|
|
||||||
marginTop: 'auto',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'flex-end',
|
|
||||||
},
|
|
||||||
cancelButton: {
|
|
||||||
marginLeft: '1.5rem',
|
|
||||||
},
|
|
||||||
inputDescription: {
|
|
||||||
marginBottom: '0.5rem',
|
|
||||||
},
|
|
||||||
permissionErrorContainer: {
|
|
||||||
position: 'relative',
|
|
||||||
},
|
|
||||||
errorMessage: {
|
|
||||||
fontSize: theme.fontSizes.smallBody,
|
|
||||||
color: theme.palette.error.main,
|
|
||||||
position: 'absolute',
|
|
||||||
top: '-8px',
|
|
||||||
},
|
|
||||||
roleBox: {
|
|
||||||
margin: '3px 0',
|
|
||||||
border: '1px solid #EFEFEF',
|
|
||||||
padding: '1rem',
|
|
||||||
},
|
|
||||||
userInfoContainer: {
|
|
||||||
margin: '-20px 0',
|
|
||||||
},
|
|
||||||
roleRadio: {
|
|
||||||
marginRight: '15px',
|
|
||||||
},
|
|
||||||
roleSubtitle: {
|
|
||||||
margin: '0.5rem 0',
|
|
||||||
},
|
|
||||||
errorAlert: {
|
|
||||||
marginBottom: '1rem',
|
|
||||||
},
|
|
||||||
flexRow: {
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
}));
|
|
@ -7,14 +7,62 @@ import {
|
|||||||
Typography,
|
Typography,
|
||||||
Radio,
|
Radio,
|
||||||
Switch,
|
Switch,
|
||||||
|
styled,
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { useStyles } from './UserForm.styles';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useUsers } from 'hooks/api/getters/useUsers/useUsers';
|
import { useUsers } from 'hooks/api/getters/useUsers/useUsers';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { EDIT } from 'constants/misc';
|
import { EDIT } from 'constants/misc';
|
||||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||||
|
|
||||||
|
const StyledForm = styled('form')(() => ({
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
height: '100%',
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledContainer = styled('div')(({ theme }) => ({
|
||||||
|
maxWidth: theme.spacing(50),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledInputDescription = styled('p')(({ theme }) => ({
|
||||||
|
marginBottom: theme.spacing(1),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledInput = styled(Input)(({ theme }) => ({
|
||||||
|
width: '100%',
|
||||||
|
marginBottom: theme.spacing(2),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledRoleSubtitle = styled(Typography)(({ theme }) => ({
|
||||||
|
margin: theme.spacing(1, 0),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledRoleBox = styled(FormControlLabel)(({ theme }) => ({
|
||||||
|
margin: theme.spacing(0.5, 0),
|
||||||
|
border: `1px solid ${theme.palette.divider}`,
|
||||||
|
padding: theme.spacing(2),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledRoleRadio = styled(Radio)(({ theme }) => ({
|
||||||
|
marginRight: theme.spacing(2),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledFlexRow = styled('div')(() => ({
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledButtonContainer = styled('div')(() => ({
|
||||||
|
marginTop: 'auto',
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledCancelButton = styled(Button)(({ theme }) => ({
|
||||||
|
marginLeft: theme.spacing(3),
|
||||||
|
}));
|
||||||
|
|
||||||
interface IUserForm {
|
interface IUserForm {
|
||||||
email: string;
|
email: string;
|
||||||
name: string;
|
name: string;
|
||||||
@ -47,7 +95,6 @@ const UserForm: React.FC<IUserForm> = ({
|
|||||||
clearErrors,
|
clearErrors,
|
||||||
mode,
|
mode,
|
||||||
}) => {
|
}) => {
|
||||||
const { classes: styles } = useStyles();
|
|
||||||
const { roles } = useUsers();
|
const { roles } = useUsers();
|
||||||
const { uiConfig } = useUiConfig();
|
const { uiConfig } = useUiConfig();
|
||||||
|
|
||||||
@ -62,13 +109,12 @@ const UserForm: React.FC<IUserForm> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit} className={styles.form}>
|
<StyledForm onSubmit={handleSubmit}>
|
||||||
<div className={styles.container}>
|
<StyledContainer>
|
||||||
<p className={styles.inputDescription}>
|
<StyledInputDescription>
|
||||||
Who is the new Unleash user?
|
Who is the new Unleash user?
|
||||||
</p>
|
</StyledInputDescription>
|
||||||
<Input
|
<StyledInput
|
||||||
className={styles.input}
|
|
||||||
label="Full name"
|
label="Full name"
|
||||||
value={name}
|
value={name}
|
||||||
onChange={e => setName(e.target.value)}
|
onChange={e => setName(e.target.value)}
|
||||||
@ -77,8 +123,7 @@ const UserForm: React.FC<IUserForm> = ({
|
|||||||
onFocus={() => clearErrors()}
|
onFocus={() => clearErrors()}
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
<Input
|
<StyledInput
|
||||||
className={styles.input}
|
|
||||||
label="Email"
|
label="Email"
|
||||||
type="email"
|
type="email"
|
||||||
value={email}
|
value={email}
|
||||||
@ -88,13 +133,9 @@ const UserForm: React.FC<IUserForm> = ({
|
|||||||
onFocus={() => clearErrors()}
|
onFocus={() => clearErrors()}
|
||||||
/>
|
/>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Typography
|
<StyledRoleSubtitle variant="subtitle1" data-loading>
|
||||||
variant="subtitle1"
|
|
||||||
className={styles.roleSubtitle}
|
|
||||||
data-loading
|
|
||||||
>
|
|
||||||
What is your team member allowed to do?
|
What is your team member allowed to do?
|
||||||
</Typography>
|
</StyledRoleSubtitle>
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
name="rootRole"
|
name="rootRole"
|
||||||
value={rootRole || ''}
|
value={rootRole || ''}
|
||||||
@ -103,10 +144,9 @@ const UserForm: React.FC<IUserForm> = ({
|
|||||||
>
|
>
|
||||||
{/* @ts-expect-error */}
|
{/* @ts-expect-error */}
|
||||||
{roles.sort(sortRoles).map(role => (
|
{roles.sort(sortRoles).map(role => (
|
||||||
<FormControlLabel
|
<StyledRoleBox
|
||||||
key={`role-${role.id}`}
|
key={`role-${role.id}`}
|
||||||
labelPlacement="end"
|
labelPlacement="end"
|
||||||
className={styles.roleBox}
|
|
||||||
label={
|
label={
|
||||||
<div>
|
<div>
|
||||||
<strong>{role.name}</strong>
|
<strong>{role.name}</strong>
|
||||||
@ -116,9 +156,8 @@ const UserForm: React.FC<IUserForm> = ({
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<StyledRoleRadio
|
||||||
checked={role.id === rootRole}
|
checked={role.id === rootRole}
|
||||||
className={styles.roleRadio}
|
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
value={role.id}
|
value={role.id}
|
||||||
@ -130,14 +169,13 @@ const UserForm: React.FC<IUserForm> = ({
|
|||||||
condition={mode !== EDIT && Boolean(uiConfig?.emailEnabled)}
|
condition={mode !== EDIT && Boolean(uiConfig?.emailEnabled)}
|
||||||
show={
|
show={
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Typography
|
<StyledRoleSubtitle
|
||||||
variant="subtitle1"
|
variant="subtitle1"
|
||||||
className={styles.roleSubtitle}
|
|
||||||
data-loading
|
data-loading
|
||||||
>
|
>
|
||||||
Should we send an email to your new team member
|
Should we send an email to your new team member
|
||||||
</Typography>
|
</StyledRoleSubtitle>
|
||||||
<div className={styles.flexRow}>
|
<StyledFlexRow>
|
||||||
<Switch
|
<Switch
|
||||||
name="sendEmail"
|
name="sendEmail"
|
||||||
onChange={() => setSendEmail(!sendEmail)}
|
onChange={() => setSendEmail(!sendEmail)}
|
||||||
@ -146,18 +184,18 @@ const UserForm: React.FC<IUserForm> = ({
|
|||||||
<Typography>
|
<Typography>
|
||||||
{sendEmail ? 'Yes' : 'No'}
|
{sendEmail ? 'Yes' : 'No'}
|
||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</StyledFlexRow>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</StyledContainer>
|
||||||
<div className={styles.buttonContainer}>
|
<StyledButtonContainer>
|
||||||
{children}
|
{children}
|
||||||
<Button onClick={handleCancel} className={styles.cancelButton}>
|
<StyledCancelButton onClick={handleCancel}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</StyledCancelButton>
|
||||||
</div>
|
</StyledButtonContainer>
|
||||||
</form>
|
</StyledForm>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user