import { MouseEventHandler, useState } from 'react' import { Link, useHistory } from 'react-router-dom' import { Button, Dropdown, Menu, Modal, Form, Input, FormProps } from 'antd' import { useForm } from 'antd/lib/form/Form' import { UserOutlined } from '@ant-design/icons' import { AuthService } from '../services/api' import { passwordRules } from '../utils/validationRules' import { invokeWebApiWrapperAsync } from './factory' import { PrivateMenuItem } from './Private' import LoaderPortal from './LoaderPortal' const handleLogout = () => { localStorage.removeItem('login') localStorage.removeItem('token') } const formLayout: FormProps = { labelCol: { span: 11 }, wrapperCol: { span: 16 } } type UserMenuProps = { isAdmin?: boolean } export const UserMenu: React.FC = ({ isAdmin }) => { const [form] = useForm() const [isModalVisible, setIsModalVisible] = useState(false) const [showLoader, setShowLoader] = useState(false) const [password, setPassword] = useState('') const history = useHistory() const changePassword = () => invokeWebApiWrapperAsync( async() => { await AuthService.changePassword(localStorage['userId'], `"${password}"`) history.push('/login') }, setShowLoader, `Не удалось сменить пароль пользователя ${localStorage['login']}` ) const onFormCancel = () => { form.resetFields() setIsModalVisible(false) } const onChangePasswordClick: MouseEventHandler = (e) => { setIsModalVisible(true) e.preventDefault() } return ( <> {isAdmin ? ( Вернуться на сайт ) : ( Панель администратора )} Сменить пароль Выход )} > form.submit()} >
setPassword(e.target.value)} value={password} />
) }