import { useState } from 'react'; import { useParams, useHistory } from 'react-router-dom'; import useForm from '../../../hooks/useForm'; import { EmployeeEditWrapper, Title, RowWrapper, LabelAndInputWrapper, Label, StandardInputField, Dropdown, DropdownOption, SwitchRowWrapper, SwitchTitle, SwitchLabelAndInputWrapper, AccountSwitch, BackAndSaveChangesButtonsWrapper, DeleteButton, BackButton, SaveChangesButton, VisibilityIcon, VisibilityOffIcon } from './styles'; import IconButton from '@mui/material/IconButton'; import { employeeStatus } from '../../../config/enums'; import { employees } from '../EmployeesTable/mockData'; const EmployeeEdit = () => { const [isPasswordVisible, setIsPasswordVisible] = useState(false); let history = useHistory(); let { employeeId } = useParams(); employeeId = parseInt(employeeId); const employee = employees.find(e => e.id === employeeId); const { data: employeeEditableData, onFormChange: setEmployeeEditableData } = useForm({ ...employee, confirmPassword: employee.password }); const [accStatus, setAccStatus] = useState(employee ? employee.accountActive : false); const zoneOptions = [ { text: 'Nitu edna zona', value: 'none' }, { text: 'Zona 1', value: 'zone1' }, { text: 'Zona 2', value: 'zone2' }, { text: 'Zona 3', value: 'zone3' }, { text: 'Zona 4', value: 'zone4' }, { text: 'Zona 5', value: 'zone5' } ]; const statusOptions = Object.keys(employeeStatus).map(key => { return { text: employeeStatus[key], value: key } }); const onSaveChanges = () => { const changedEmployee = { ...employeeEditableData, accountActive: accStatus } console.log('Changed employee: ', changedEmployee); } const onDeleteEmployee = () => { console.log(`Empoyee with ${employee.id} is deleted`); } return Uredi vraboten setIsPasswordVisible(!isPasswordVisible)}> { isPasswordVisible ? : } { zoneOptions.map(option => {option.text}) } { statusOptions.map(option => {option.text}) } Akaunt setAccStatus(!accStatus)} /> Izbrisi vraboten history.push('/employees')}> Vrati se nazad Zacuvaj gi promenti }; export default EmployeeEdit;