1 | import { useState } from 'react';
|
---|
2 | import { useHistory } from 'react-router-dom';
|
---|
3 | import useForm from '../../../hooks/useForm';
|
---|
4 |
|
---|
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,
|
---|
22 | } from './styles';
|
---|
23 |
|
---|
24 | import IconButton from '@mui/material/IconButton';
|
---|
25 |
|
---|
26 | import { employeeStatus } from '../../../config/enums';
|
---|
27 |
|
---|
28 | import { defaultUser } from '../../../config/defaultUser';
|
---|
29 |
|
---|
30 | 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,
|
---|
69 | };
|
---|
70 | });
|
---|
71 |
|
---|
72 | const onCreateEmployee = () => {
|
---|
73 | const changedEmployee = {
|
---|
74 | ...employeeEditableData,
|
---|
75 | accountActive: accStatus,
|
---|
76 | };
|
---|
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 | );
|
---|
199 | };
|
---|
200 |
|
---|
201 | export default EmployeeCreate;
|
---|