Changeset bc20307 for sources/client/src/components/admin/EmployeeCreate
- Timestamp:
- 02/14/22 01:41:41 (2 years ago)
- Branches:
- master
- Children:
- 747e0ab
- Parents:
- e8b1076
- Location:
- sources/client/src/components/admin/EmployeeCreate
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/client/src/components/admin/EmployeeCreate/index.js
re8b1076 rbc20307 4 4 5 5 import { 6 EmployeeEditWrapper,7 Title,8 RowWrapper,9 LabelAndInputWrapper,10 Label,11 StandardInputField,12 Dropdown,13 DropdownOption,14 SwitchRowWrapper,15 SwitchTitle,16 SwitchLabelAndInputWrapper,17 AccountSwitch,18 BackButton,19 SaveChangesButton,20 VisibilityIcon,21 VisibilityOffIcon,6 EmployeeEditWrapper, 7 Title, 8 RowWrapper, 9 LabelAndInputWrapper, 10 Label, 11 StandardInputField, 12 Dropdown, 13 DropdownOption, 14 SwitchRowWrapper, 15 SwitchTitle, 16 SwitchLabelAndInputWrapper, 17 AccountSwitch, 18 BackButton, 19 SaveChangesButton, 20 VisibilityIcon, 21 VisibilityOffIcon, 22 22 } from './styles'; 23 23 24 24 import IconButton from '@mui/material/IconButton'; 25 import Checkbox from '@mui/material/Checkbox'; 26 import ListItemText from '@mui/material/ListItemText'; 27 import AbsoluteLoader from '../../Loaders/AbsoluteLoader'; 25 28 26 29 import { employeeStatus } from '../../../config/enums'; 30 import useGetData from '../../../hooks/useGetData'; 31 import useCreateEmployee from '../../../hooks/useCreateEmployee'; 27 32 28 33 import { defaultUser } from '../../../config/defaultUser'; 29 34 35 const MenuProps = { 36 PaperProps: { 37 style: { 38 maxHeight: 220, 39 }, 40 }, 41 }; 42 30 43 const EmployeeCreate = () => { 31 const [isPasswordVisible, setIsPasswordVisible] = useState(false);32 let history = useHistory();33 34 const { data: employeeEditableData, onFormChange: setEmployeeEditableData } =35 useForm({ ...defaultUser, confirmPassword: defaultUser.password});36 const [accStatus, setAccStatus] = useState(defaultUser.accountActive);37 38 const zoneOptions = [39 {40 text: 'Nitu edna zona',41 value: 'none',42 },43 {44 text: 'Zona 1',45 value: 'zone1',46 },47 {48 text: 'Zona 2',49 value: 'zone2',50 },51 {52 text: 'Zona 3',53 value: 'zone3',54 },55 {56 text: 'Zona 4', 57 value: 'zone4',58 },59 {60 text: 'Zona 5',61 value: 'zone5',62 },63 ];64 65 const statusOptions = Object.keys(employeeStatus).map((key) => {66 return {67 text: employeeStatus[key],68 value: key,44 const [isPasswordVisible, setIsPasswordVisible] = useState(false); 45 let history = useHistory(); 46 const { data: zoneOptions, isLoading: isLoadingZonesData } = useGetData({ 47 url: `/parkingZone/parkingZoneNames`, 48 }); 49 const { createEmployee } = useCreateEmployee(); 50 const { 51 data: employeeEditableData, 52 onFormChange: setEmployeeEditableData, 53 } = useForm({ ...defaultUser }); 54 const [accStatus, setAccStatus] = useState(defaultUser.locked); 55 const { 56 data: { confirmPassword }, 57 onFormChange: setConfirmPassword, 58 } = useForm({ 59 confirmPassword: defaultUser.password, 60 }); 61 const [zones, setZones] = useState(defaultUser.parkingZones); // TODO RENAME ZONE TO ZONES 62 console.log(zones); 63 const statusOptions = Object.keys(employeeStatus).map((key) => { 64 return { 65 text: employeeStatus[key], 66 value: key, 67 }; 68 }); 69 70 const onCreateEmployee = () => { 71 if (zones.length === 1 && zones[0] === 'NONE') { 72 zones.shift(); 73 } 74 console.log(`Confirm password: ${confirmPassword}`); 75 const changedEmployee = { 76 ...employeeEditableData, 77 locked: accStatus, 78 parkingZones: zones, 79 confirmPass: confirmPassword, 80 }; 81 createEmployee({ employee: changedEmployee }); 69 82 }; 70 }); 71 72 const onCreateEmployee = () => { 73 const changedEmployee = { 74 ...employeeEditableData, 75 accountActive: accStatus, 83 const handleZonesChange = (event) => { 84 const { 85 target: { value }, 86 } = event; 87 if (value.length > 1 && value[0] === 'NONE') { 88 value.shift(); 89 } 90 setZones( 91 typeof value === 'string' 92 ? value.split(', ') 93 : value.length === 0 94 ? ['NONE'] 95 : value 96 ); 76 97 }; 77 console.log('Created employee: ', changedEmployee); 78 }; 79 80 return ( 81 <EmployeeEditWrapper> 82 <Title variant='h5'>Создади вработен</Title> 83 <RowWrapper> 84 <LabelAndInputWrapper> 85 <Label>Име</Label> 86 <StandardInputField 87 value={employeeEditableData.firstName} 88 name='firstName' 89 onChange={setEmployeeEditableData} 90 /> 91 </LabelAndInputWrapper> 92 <LabelAndInputWrapper> 93 <Label>Презиме</Label> 94 <StandardInputField 95 value={employeeEditableData.lastName} 96 name='lastName' 97 onChange={setEmployeeEditableData} 98 /> 99 </LabelAndInputWrapper> 100 </RowWrapper> 101 <RowWrapper> 102 <LabelAndInputWrapper> 103 <Label>Емаил</Label> 104 <StandardInputField 105 value={employeeEditableData.email} 106 name='email' 107 type='email' 108 onChange={setEmployeeEditableData} 109 /> 110 </LabelAndInputWrapper> 111 <LabelAndInputWrapper> 112 <Label>Телефон</Label> 113 <StandardInputField 114 value={employeeEditableData.phoneNumber} 115 name='phoneNumber' 116 onChange={setEmployeeEditableData} 117 /> 118 </LabelAndInputWrapper> 119 </RowWrapper> 120 <RowWrapper> 121 <LabelAndInputWrapper> 122 <Label>Лозинка</Label> 123 <StandardInputField 124 value={employeeEditableData.password} 125 name='password' 126 type={isPasswordVisible ? 'text' : 'password'} 127 $autoComplete={true} 128 onChange={setEmployeeEditableData} 129 /> 130 </LabelAndInputWrapper> 131 <IconButton 132 sx={{ marginTop: '23px' }} 133 onClick={() => setIsPasswordVisible(!isPasswordVisible)} 134 > 135 {isPasswordVisible ? <VisibilityIcon /> : <VisibilityOffIcon />} 136 </IconButton> 137 <LabelAndInputWrapper> 138 <Label>Потврди лозинка</Label> 139 <StandardInputField 140 value={employeeEditableData.confirmPassword} 141 name='confirmPassword' 142 type={isPasswordVisible ? 'text' : 'password'} 143 onChange={setEmployeeEditableData} 144 /> 145 </LabelAndInputWrapper> 146 </RowWrapper> 147 <RowWrapper> 148 <LabelAndInputWrapper> 149 <Label>Одговорен за</Label> 150 <Dropdown 151 value={employeeEditableData.zone} 152 name='zone' 153 onChange={setEmployeeEditableData} 154 > 155 {zoneOptions.map((option) => ( 156 <DropdownOption value={option.value} key={option.value}> 157 {option.text} 158 </DropdownOption> 159 ))} 160 </Dropdown> 161 </LabelAndInputWrapper> 162 <LabelAndInputWrapper> 163 <Label>Статус</Label> 164 <Dropdown 165 value={employeeEditableData.status} 166 name='status' 167 onChange={setEmployeeEditableData} 168 > 169 {statusOptions.map((option) => ( 170 <DropdownOption value={option.value} key={option.value}> 171 {option.text} 172 </DropdownOption> 173 ))} 174 </Dropdown> 175 </LabelAndInputWrapper> 176 </RowWrapper> 177 <SwitchRowWrapper> 178 <SwitchTitle>Акаунт</SwitchTitle> 179 <SwitchLabelAndInputWrapper> 180 <Label>Активен:</Label> 181 <AccountSwitch 182 checked={accStatus} 183 value={accStatus} 184 name='accountActive' 185 onClick={() => setAccStatus(!accStatus)} 186 /> 187 </SwitchLabelAndInputWrapper> 188 </SwitchRowWrapper> 189 <RowWrapper> 190 <BackButton onClick={() => history.push('/employees')}> 191 Врати се назад 192 </BackButton> 193 <SaveChangesButton onClick={onCreateEmployee}> 194 Создади вработен 195 </SaveChangesButton> 196 </RowWrapper> 197 </EmployeeEditWrapper> 198 ); 98 return ( 99 <EmployeeEditWrapper> 100 <Title variant='h5'>Создади вработен</Title> 101 <RowWrapper> 102 <LabelAndInputWrapper> 103 <Label>Име</Label> 104 <StandardInputField 105 value={employeeEditableData.firstName} 106 name='firstName' 107 onChange={setEmployeeEditableData} 108 /> 109 </LabelAndInputWrapper> 110 <LabelAndInputWrapper> 111 <Label>Презиме</Label> 112 <StandardInputField 113 value={employeeEditableData.lastName} 114 name='lastName' 115 onChange={setEmployeeEditableData} 116 /> 117 </LabelAndInputWrapper> 118 </RowWrapper> 119 <RowWrapper> 120 <LabelAndInputWrapper> 121 <Label>Емаил</Label> 122 <StandardInputField 123 value={employeeEditableData.email} 124 name='email' 125 type='email' 126 onChange={setEmployeeEditableData} 127 /> 128 </LabelAndInputWrapper> 129 <LabelAndInputWrapper> 130 <Label>Телефон</Label> 131 <StandardInputField 132 value={employeeEditableData.mobile} 133 name='mobile' 134 onChange={setEmployeeEditableData} 135 /> 136 </LabelAndInputWrapper> 137 </RowWrapper> 138 <RowWrapper> 139 <LabelAndInputWrapper> 140 <Label>Лозинка</Label> 141 <StandardInputField 142 value={employeeEditableData.password} 143 name='password' 144 type={isPasswordVisible ? 'text' : 'password'} 145 $autoComplete={true} 146 onChange={setEmployeeEditableData} 147 /> 148 </LabelAndInputWrapper> 149 <IconButton 150 sx={{ marginTop: '23px' }} 151 onClick={() => setIsPasswordVisible(!isPasswordVisible)} 152 > 153 {isPasswordVisible ? ( 154 <VisibilityIcon /> 155 ) : ( 156 <VisibilityOffIcon /> 157 )} 158 </IconButton> 159 <LabelAndInputWrapper> 160 <Label>Потврди лозинка</Label> 161 <StandardInputField 162 value={confirmPassword} 163 name='confirmPassword' 164 type={isPasswordVisible ? 'text' : 'password'} 165 onChange={setConfirmPassword} 166 /> 167 </LabelAndInputWrapper> 168 </RowWrapper> 169 <RowWrapper> 170 {isLoadingZonesData ? ( 171 <AbsoluteLoader 172 containerStyle={{ 173 position: 'absolute', 174 left: '310px', 175 bottom: '5px', 176 width: '40px', 177 height: '40px', 178 }} 179 /> 180 ) : null} 181 <LabelAndInputWrapper> 182 <Label>Одговорен за</Label> 183 <Dropdown 184 multiple 185 value={zones} 186 onChange={handleZonesChange} 187 renderValue={(selected) => { 188 return selected.join(', '); 189 }} 190 MenuProps={MenuProps} 191 > 192 {!isLoadingZonesData && 193 zoneOptions.map((zone) => ( 194 <DropdownOption value={zone} key={zone}> 195 <Checkbox 196 checked={zones.indexOf(zone) > -1} 197 /> 198 <ListItemText primary={zone} /> 199 </DropdownOption> 200 ))} 201 </Dropdown> 202 </LabelAndInputWrapper> 203 <LabelAndInputWrapper> 204 <Label>Статус</Label> 205 <Dropdown 206 value={employeeEditableData.status} 207 name='status' 208 onChange={setEmployeeEditableData} 209 MenuProps={MenuProps} 210 > 211 {statusOptions.map((option) => ( 212 <DropdownOption 213 value={option.value} 214 key={option.value} 215 > 216 {option.text} 217 </DropdownOption> 218 ))} 219 </Dropdown> 220 </LabelAndInputWrapper> 221 </RowWrapper> 222 <SwitchRowWrapper> 223 <SwitchTitle>Акаунт</SwitchTitle> 224 <SwitchLabelAndInputWrapper> 225 <Label>Активен:</Label> 226 <AccountSwitch 227 checked={!accStatus} 228 value={accStatus} 229 name='locked' 230 onClick={() => setAccStatus(!accStatus)} 231 /> 232 </SwitchLabelAndInputWrapper> 233 </SwitchRowWrapper> 234 <RowWrapper> 235 <BackButton onClick={() => history.push('/employees')}> 236 Врати се назад 237 </BackButton> 238 <SaveChangesButton onClick={onCreateEmployee}> 239 Создади вработен 240 </SaveChangesButton> 241 </RowWrapper> 242 </EmployeeEditWrapper> 243 ); 199 244 }; 200 245 -
sources/client/src/components/admin/EmployeeCreate/styles.js
re8b1076 rbc20307 1 import styled from "styled-components"; 2 import { Button, InputLabel, MenuItem, Select, Switch, TextField, Typography } from "@mui/material"; 1 import styled from 'styled-components'; 2 import { 3 Button, 4 InputLabel, 5 MenuItem, 6 Select, 7 Switch, 8 TextField, 9 Typography, 10 } from '@mui/material'; 3 11 import VIcon from '@mui/icons-material/Visibility'; 4 12 import VOffIcon from '@mui/icons-material/VisibilityOff'; 5 13 6 14 export const EmployeeEditWrapper = styled.div` 7 8 9 10 11 12 13 14 15 16 box-shadow: 15px 15px 10px ${props=> props.theme.palette.background.shadow};15 display: flex; 16 flex-direction: column; 17 max-width: 800px; 18 border: 1px solid whiteSmoke; 19 border-radius: 10px; 20 padding: 10px 20px; 21 margin-top: 20px; 22 margin-left: 30px; 23 background-color: white; 24 box-shadow: 15px 15px 10px ${(props) => props.theme.palette.background.shadow}; 17 25 `; 18 26 19 export const Title = styled(Typography).attrs({ 20 21 })` 22 border-bottom: 2px solid rgba(0, 0, 0, 0.12); 23 padding-bottom: 10px; 24 margin-bottom: 15px; 27 export const Title = styled(Typography).attrs({})` 28 border-bottom: 2px solid rgba(0, 0, 0, 0.12); 29 padding-bottom: 10px; 30 margin-bottom: 15px; 25 31 `; 26 32 27 33 export const RowWrapper = styled.div` 28 display: flex; 29 flex-direction: row; 30 justify-content: space-between; 31 margin-bottom: 25px; 34 display: flex; 35 flex-direction: row; 36 justify-content: space-between; 37 margin-bottom: 25px; 38 position: relative; 32 39 `; 33 40 34 export const LabelAndInputWrapper = styled.div` 41 export const LabelAndInputWrapper = styled.div``; 35 42 36 `;43 export const Label = styled(InputLabel).attrs({})``; 37 44 38 export const Label = styled(InputLabel).attrs({ 39 40 })``; 41 42 export const StandardInputField = styled(TextField).attrs({ 43 44 })` 45 width: 300px; 45 export const StandardInputField = styled(TextField).attrs({})` 46 width: 300px; 46 47 `; 47 48 48 49 export const VisibilityIcon = styled(VIcon).attrs({ 49 50 fontSize: '2rem'51 }50 sx: { 51 fontSize: '2rem', 52 }, 52 53 })``; 53 54 54 55 export const VisibilityOffIcon = styled(VOffIcon).attrs({ 55 56 fontSize: '2rem'57 }56 sx: { 57 fontSize: '2rem', 58 }, 58 59 })``; 59 60 60 export const Dropdown = styled(Select).attrs({ 61 62 })` 63 width: 300px; 61 export const Dropdown = styled(Select).attrs({})` 62 width: 300px; 64 63 `; 65 64 66 export const DropdownOption = styled(MenuItem).attrs({ 67 68 })``; 65 export const DropdownOption = styled(MenuItem).attrs({})` 66 > span { 67 color: ${(props) => props.theme.palette.primary.main}; 68 svg { 69 color: ${(props) => props.theme.palette.primary.main}; 70 } 71 } 72 > div > span { 73 font-size: 1.3rem; 74 } 75 `; 69 76 70 77 export const SwitchRowWrapper = styled.div` 71 72 73 78 text-align: center; 79 margin-top: 10px; 80 margin-bottom: 50px; 74 81 `; 75 82 76 83 export const SwitchTitle = styled.p` 77 78 79 80 84 font-size: 18px; 85 font-weight: 600; 86 margin: 0; 87 margin-bottom: 5px; 81 88 `; 82 89 83 90 export const SwitchLabelAndInputWrapper = styled.div` 84 display: flex; 85 flex-direction: row; 86 align-items: center; 87 justify-content: center; 88 91 display: flex; 92 flex-direction: row; 93 align-items: center; 94 justify-content: center; 89 95 `; 90 96 91 export const AccountSwitch = styled(Switch).attrs(props => ({ 92 }))` 93 .MuiSwitch-switchBase { 94 color: red; 95 } 96 .MuiSwitch-track { 97 background-color: red; 98 } 99 .MuiSwitch-switchBase.Mui-checked { 100 color: ${props => props.theme.palette.primary.main}; 101 } 102 .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track { 103 background-color: ${props => props.theme.palette.primary.main}; 104 } 97 export const AccountSwitch = styled(Switch).attrs((props) => ({}))` 98 .MuiSwitch-switchBase { 99 color: red; 100 } 101 .MuiSwitch-track { 102 background-color: red; 103 } 104 .MuiSwitch-switchBase.Mui-checked { 105 color: ${(props) => props.theme.palette.primary.main}; 106 } 107 .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track { 108 background-color: ${(props) => props.theme.palette.primary.main}; 109 } 105 110 `; 106 111 107 112 export const BackButton = styled(Button).attrs({ 108 variant: 'outlined'113 variant: 'outlined', 109 114 })` 110 111 112 113 114 115 margin-right: 15px; 116 :hover { 117 border: 2px solid; 118 font-weight: 600; 119 } 115 120 `; 116 121 117 export const SaveChangesButton = styled(Button).attrs( props=> ({118 119 120 backgroundColor: `${props.theme.palette.primary.main}`121 }122 export const SaveChangesButton = styled(Button).attrs((props) => ({ 123 variant: 'contained', 124 sx: { 125 backgroundColor: `${props.theme.palette.primary.main}`, 126 }, 122 127 }))` 123 124 125 background-color: ${props => props.theme.palette.primary.dark}126 128 padding: 10px 16px; 129 :hover { 130 background-color: ${(props) => props.theme.palette.primary.dark}; 131 } 127 132 `;
Note:
See TracChangeset
for help on using the changeset viewer.