diff --git a/src/components/ChangePassword.tsx b/src/components/ChangePassword.tsx index 07ee96e..89dae19 100644 --- a/src/components/ChangePassword.tsx +++ b/src/components/ChangePassword.tsx @@ -2,23 +2,25 @@ import { memo, useState } from 'react' import { useForm } from 'antd/lib/form/Form' import { Form, Input, Modal, FormProps } from 'antd' -import { AuthService } from '../services/api' -import { passwordRules } from '../utils/validationRules' +import { AuthService, UserDto } from '../services/api' +import { passwordRules, createPasswordRules } from '../utils/validationRules' import LoaderPortal from './LoaderPortal' import { invokeWebApiWrapperAsync } from './factory' +import { UserView } from './Views' const formLayout: FormProps = { labelCol: { span: 11 }, wrapperCol: { span: 16 } } export type ChangePasswordProps = { - userId?: number + user?: UserDto visible?: boolean onCancel?: () => void onOk?: () => void } +const fieldRules = [...passwordRules, ...createPasswordRules] -export const ChangePassword = memo(({ userId, visible, onCancel, onOk }) => { +export const ChangePassword = memo(({ user, visible, onCancel, onOk }) => { const [showLoader, setShowLoader] = useState(false) const [password, setPassword] = useState('') @@ -31,7 +33,7 @@ export const ChangePassword = memo(({ userId, visible, onCa const onFormFinish = () => invokeWebApiWrapperAsync( async() => { - await AuthService.changePassword(userId ?? localStorage['userId'], `"${password}"`) + await AuthService.changePassword(user?.id ?? localStorage['userId'], `"${password}"`) onOk?.() }, setShowLoader, @@ -41,7 +43,12 @@ export const ChangePassword = memo(({ userId, visible, onCa return ( + Сменить пароль + {user && <> ()} + + )} visible={visible} onCancel={onModalCancel} onOk={() => form.submit()} @@ -53,9 +60,26 @@ export const ChangePassword = memo(({ userId, visible, onCa name={'change-password'} onFinish={onFormFinish} > - + setPassword(e.target.value)} value={password} /> + ({ validator(_, value: string) { + if (value !== password) + return Promise.reject('Пароли не совпадают!') + return Promise.resolve() + }})]} + > + + diff --git a/src/components/Views/TelemetryView.tsx b/src/components/Views/TelemetryView.tsx index e76a2fc..a353cb5 100644 --- a/src/components/Views/TelemetryView.tsx +++ b/src/components/Views/TelemetryView.tsx @@ -41,5 +41,5 @@ export const TelemetryView = memo(({ telemetry }) => telemet {getTelemetryLabel(telemetry)} ) : ( - {getTelemetryLabel()} + - )) diff --git a/src/pages/AdminPanel/UserController.jsx b/src/pages/AdminPanel/UserController.jsx index 095f724..b84ba44 100644 --- a/src/pages/AdminPanel/UserController.jsx +++ b/src/pages/AdminPanel/UserController.jsx @@ -47,12 +47,12 @@ export default function UserController() { const [users, setUsers] = useState([]) const [showLoader, setShowLoader] = useState(false) const [columns, setColumns] = useState([]) - const [selectedId, setSelectedId] = useState(null) + const [selectedUser, setSelectedUser] = useState(null) const additionalButtons = (record, editingKey) => (