source: sources/client/src/components/admin/EmployeeEdit/index.js@ 3a58bd6

Last change on this file since 3a58bd6 was 3a58bd6, checked in by Viktor <39170279+Tasevski2@…>, 3 years ago

Added Frontend

  • Property mode set to 100644
File size: 6.9 KB
Line 
1import { useState } from 'react';
2import { useParams, useHistory } from 'react-router-dom';
3import useForm from '../../../hooks/useForm';
4
5import {
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 BackAndSaveChangesButtonsWrapper,
19 DeleteButton,
20 BackButton,
21 SaveChangesButton,
22 VisibilityIcon,
23 VisibilityOffIcon
24} from './styles';
25
26import IconButton from '@mui/material/IconButton';
27
28import {
29 employeeStatus
30} from '../../../config/enums';
31
32import {
33 employees
34} from '../EmployeesTable/mockData';
35
36const EmployeeEdit = () => {
37 const [isPasswordVisible, setIsPasswordVisible] = useState(false);
38 let history = useHistory();
39 let { employeeId } = useParams();
40 employeeId = parseInt(employeeId);
41
42 const employee = employees.find(e => e.id === employeeId);
43 const { data: employeeEditableData, onFormChange: setEmployeeEditableData } = useForm({ ...employee, confirmPassword: employee.password });
44 const [accStatus, setAccStatus] = useState(employee ? employee.accountActive : false);
45
46 const zoneOptions = [
47 {
48 text: 'Nitu edna zona',
49 value: 'none'
50 },
51 {
52 text: 'Zona 1',
53 value: 'zone1'
54 },
55 {
56 text: 'Zona 2',
57 value: 'zone2'
58 },
59 {
60 text: 'Zona 3',
61 value: 'zone3'
62 },
63 {
64 text: 'Zona 4',
65 value: 'zone4'
66 },
67 {
68 text: 'Zona 5',
69 value: 'zone5'
70 }
71 ];
72
73 const statusOptions = Object.keys(employeeStatus).map(key => {
74 return {
75 text: employeeStatus[key],
76 value: key
77 }
78 });
79
80 const onSaveChanges = () => {
81 const changedEmployee = {
82 ...employeeEditableData,
83 accountActive: accStatus
84 }
85 console.log('Changed employee: ', changedEmployee);
86 }
87
88 const onDeleteEmployee = () => {
89 console.log(`Empoyee with ${employee.id} is deleted`);
90 }
91
92 return <EmployeeEditWrapper>
93 <Title variant='h5'>Uredi vraboten</Title>
94 <RowWrapper>
95 <LabelAndInputWrapper>
96 <Label>Ime</Label>
97 <StandardInputField
98 value={employeeEditableData?.firstName ?? ''}
99 name='firstName'
100 onChange={setEmployeeEditableData}
101 />
102 </LabelAndInputWrapper>
103 <LabelAndInputWrapper>
104 <Label>Prezime</Label>
105 <StandardInputField
106 value={employeeEditableData?.lastName ?? ''}
107 name='lastName'
108 onChange={setEmployeeEditableData}
109 />
110 </LabelAndInputWrapper>
111 </RowWrapper>
112 <RowWrapper>
113 <LabelAndInputWrapper>
114 <Label>Email</Label>
115 <StandardInputField
116 value={employeeEditableData?.email ?? ''}
117 name='email'
118 type='email'
119 onChange={setEmployeeEditableData}
120 />
121 </LabelAndInputWrapper>
122 <LabelAndInputWrapper>
123 <Label>Telefon</Label>
124 <StandardInputField
125 value={employeeEditableData?.phoneNumber ?? ''}
126 name='phoneNumber'
127 onChange={setEmployeeEditableData}
128 />
129 </LabelAndInputWrapper>
130 </RowWrapper>
131 <RowWrapper>
132 <LabelAndInputWrapper>
133 <Label>Lozinka</Label>
134 <StandardInputField
135 value={employeeEditableData?.password ?? ''}
136 name='password'
137 type={isPasswordVisible ? 'text' : 'password'}
138 onChange={setEmployeeEditableData}
139 />
140 </LabelAndInputWrapper>
141 <IconButton sx={{ marginTop: '23px' }} onClick={() => setIsPasswordVisible(!isPasswordVisible)}>
142 {
143 isPasswordVisible ?
144 <VisibilityIcon />
145 :
146 <VisibilityOffIcon />
147 }
148 </IconButton>
149 <LabelAndInputWrapper>
150 <Label>Potvrdi lozinka</Label>
151 <StandardInputField
152 value={employeeEditableData?.confirmPassword ?? ''}
153 name='confirmPassword'
154 type={isPasswordVisible ? 'text' : 'password'}
155 onChange={setEmployeeEditableData}
156 />
157 </LabelAndInputWrapper>
158 </RowWrapper>
159 <RowWrapper>
160 <LabelAndInputWrapper>
161 <Label>Odgovoren za</Label>
162 <Dropdown
163 value={employeeEditableData?.zone !== '' ? employeeEditableData?.zone : zoneOptions[0].value}
164 name='zone'
165 onChange={setEmployeeEditableData}
166 >
167 {
168 zoneOptions.map(option => <DropdownOption value={option.value} key={option.value}>{option.text}</DropdownOption>)
169 }
170 </Dropdown>
171 </LabelAndInputWrapper>
172 <LabelAndInputWrapper>
173 <Label>Status</Label>
174 <Dropdown
175 value={employeeEditableData?.status !== '' ? employeeEditableData?.status : statusOptions[0].value}
176 name='status'
177 onChange={setEmployeeEditableData}
178 >
179 {
180 statusOptions.map(option => <DropdownOption value={option.value} key={option.value}>{option.text}</DropdownOption>)
181 }
182 </Dropdown>
183 </LabelAndInputWrapper>
184 </RowWrapper>
185 <SwitchRowWrapper>
186 <SwitchTitle>Akaunt</SwitchTitle>
187 <SwitchLabelAndInputWrapper>
188 <Label>Aktiven:</Label>
189 <AccountSwitch
190 checked={accStatus}
191 value={accStatus}
192 name='accountActive'
193 onClick={() => setAccStatus(!accStatus)}
194 />
195 </SwitchLabelAndInputWrapper>
196 </SwitchRowWrapper>
197 <RowWrapper>
198 <DeleteButton onClick={onDeleteEmployee}>
199 Izbrisi vraboten
200 </DeleteButton>
201 <BackAndSaveChangesButtonsWrapper>
202 <BackButton onClick={() => history.push('/employees')}>
203 Vrati se nazad
204 </BackButton>
205 <SaveChangesButton onClick={onSaveChanges}>
206 Zacuvaj gi promenti
207 </SaveChangesButton>
208 </BackAndSaveChangesButtonsWrapper>
209 </RowWrapper>
210 </EmployeeEditWrapper>
211};
212
213export default EmployeeEdit;
Note: See TracBrowser for help on using the repository browser.