Compare commits

..
2 Commits
8 changed files with 145 additions and 51 deletions

No files matched your search

+4
View File
@@ -1,3 +1,7 @@
## 0.12.3
- Добавлена логика изменения пароля
## 0.12.2
- Добавлена возможность копирования конфига
## 0.12.1
- Исправлен шрифт в редакторах кода
- Исправлены перерисовки экрана "Модули"
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "isp-admin-ui",
"private": true,
"version": "0.12.1",
"version": "0.12.3",
"type": "module",
"scripts": {
"start": "vite",
+65 -15
View File
@@ -1,5 +1,5 @@
import { FormComponents } from 'isp-ui-kit'
import { FC } from 'react'
import { FC, useEffect, useState } from 'react'
import { useForm } from 'react-hook-form'
import Modal from '@widgets/Modal'
@@ -8,53 +8,102 @@ import {
ChangePasswordModalProps,
ChangePasswordModalType
} from '@components/ChangePasswordModal/change-password-modal.type.ts'
import { apiService } from '@services/apiService.ts'
import { ChangeProfilePassword } from '@pages/ProfilePage/profile-page.type.ts'
import { apiPaths } from '@constants/api/apiPaths.ts'
import { message } from 'antd'
import useLogout from '@hooks/useLogout.tsx'
const { FormInputPassword } = FormComponents
const ChangePasswordModal: FC<ChangePasswordModalProps> = ({
open,
onClose
}) => {
const { control, handleSubmit } = useForm<ChangePasswordModalType>({
open,
onClose
}) => {
const {
control,
handleSubmit,
setError,
clearErrors,
watch,
reset,
trigger
} = useForm<ChangePasswordModalType>({
mode: 'onChange'
})
const [loading, setLoading] = useState(false)
const { logoutUser } = useLogout()
const onSubmit = (formValue: ChangePasswordModalType) => {
//TODO добавить бэк, как появится
console.log(formValue)
const onSubmit = async (formValue: ChangePasswordModalType) => {
setLoading(true)
try {
await apiService.post<ChangeProfilePassword>(
apiPaths.changePassword,
{ oldPassword: formValue.oldPassword, newPassword: formValue.newPassword }
)
await logoutUser()
message.success('Пароль успешно изменен')
clearErrors('oldPassword')
} catch (error: any) {
if (error.response.data.errorCode === 1001) {
setError('oldPassword', {
message: 'Не верный текущий пароль'
})
}
} finally {
setLoading(false)
}
}
const handleCloseModal = () => {
onClose()
reset()
}
const confirmPassword = watch('confirmPassword')
const newPassword = watch('newPassword')
useEffect(() => {
trigger('newPassword')
trigger('confirmPassword')
}, [newPassword, confirmPassword])
return (
<Modal
title="Сменить пароль"
open={open}
onClose={onClose}
onClose={handleCloseModal}
onOk={handleSubmit(onSubmit)}
footer={{ onOkText: 'Изменить пароль', onCanselText: 'Отмена' }}
loading={loading}
>
<form key="change-pass-modal">
<FormInputPassword
rules={{
required: { value: true, message: 'Поле не может быть пустым' }
}}
label="Старый пароль"
label="Текущий пароль"
control={control}
name="oldPassword"
/>
<FormInputPassword
rules={{
required: { value: true, message: 'Поле не может быть пустым' }
required: { value: true, message: 'Поле не может быть пустым' },
validate: (value) => {
return value === confirmPassword || 'Пароли не совпадают'
}
}}
label="Новый пароль"
control={control}
name="newPassword"
/>
<FormInputPassword
rules={{
required: { value: true, message: 'Поле не может быть пустым' },
validate: (value, formValues) => {
const { newPassword } = formValues
return value !== newPassword ? 'Пароли не совпадают' : true
validate: (value) => {
if (value !== newPassword) return 'Пароли не совпадают'
if (!value) return 'Поле не может быть пустым'
return true
}
}}
label="Подтвердите пароль"
@@ -66,3 +115,4 @@ const ChangePasswordModal: FC<ChangePasswordModalProps> = ({
)
}
export default ChangePasswordModal
+2
View File
@@ -53,6 +53,7 @@ type PathKeys =
| 'markConfigAsActive'
| 'getUI'
| 'getByModuleId'
| 'changePassword'
export const apiPaths: Record<PathKeys, string> = {
baseUrl: '/api/kkd-configuration-service',
@@ -71,6 +72,7 @@ export const apiPaths: Record<PathKeys, string> = {
// ======= PROFILE ======
getProfile: '/api/admin/user/get_profile',
getUI: '/api/admin/user/get_design',
changePassword: '/api/admin/user/change_password',
// ======= USERS ======
getUsers: '/get_users',
createUser: '/create_user',
@@ -16,6 +16,11 @@ export type ProfileType = {
error: string
}
export type ChangeProfilePassword = {
oldPassword: string
newPassword: string
}
export type UIDataType = {
name: string
primaryColor: string
+63 -32
View File
@@ -5,9 +5,10 @@ import {
EyeOutlined,
HistoryOutlined,
SwapOutlined,
EllipsisOutlined
EllipsisOutlined,
CopyOutlined
} from '@ant-design/icons'
import { Button, Dropdown, Popconfirm, Tooltip } from 'antd'
import { Button, Dropdown, message, Popconfirm, Tooltip } from 'antd'
import { FC } from 'react'
import { useNavigate } from 'react-router-dom'
@@ -16,6 +17,8 @@ import { ActiveTableActionButtonsPropsType } from './active-table-action-buttons
import './active-table-action-buttons.scss'
import CanEdit from '@components/CanEdit'
import { routePaths } from '@routes/routePaths.ts'
import configServiceApi from '@services/configService.ts'
import { ConfigType } from '@pages/ModulesPage/module.type.ts'
const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
({
@@ -27,10 +30,25 @@ const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
handleMarkConfigActive
}) => {
const navigate = useNavigate()
const [createUpdateConfig] = configServiceApi.useCreateUpdateConfigMutation()
const navigateToAllVersion = () => navigate(`${record.id}/all_versions`)
const renderDropDown = (record: any) => {
const copyConfig = () => {
const newConfig = {
name: `${record.name} (copy)`,
moduleId: record.moduleId,
id: '',
version: 0,
data: record.data
} as ConfigType
createUpdateConfig(newConfig)
.unwrap()
.then(() => message.success('Конфиг успешно скопирован'))
.catch(() => message.error('Не удалось скопировать конфиг'))
}
const renderDropDownNoActive = (record: any) => {
return (
<div className="dropdown">
<Tooltip key="1" title="Сравнение версий">
@@ -43,6 +61,9 @@ const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
<Button onClick={navigateToAllVersion} icon={<HistoryOutlined />} />
</Tooltip>
<CanEdit>
<Tooltip key="4" title="Копировать конфиг">
<Button icon={<CopyOutlined />} onClick={copyConfig} />
</Tooltip>
<Popconfirm
title="Вы действительно хотите удалить выбранный конфиг?"
onConfirm={() => handleDeleteConfig(record)}
@@ -56,23 +77,33 @@ const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
)
}
const renderDropDownActive = (record: any) => {
return (
<div className="dropdown">
<Tooltip key="1" title="Сравнение версий">
<Button
onClick={() => handleShowCompareModal(record)}
icon={<SwapOutlined />}
/>
</Tooltip>
<Tooltip key="2" title="Просмотр истории">
<Button onClick={navigateToAllVersion} icon={<HistoryOutlined />} />
</Tooltip>
<CanEdit>
<Tooltip key="4" title="Копировать конфиг">
<Button icon={<CopyOutlined />} onClick={copyConfig} />
</Tooltip>
</CanEdit>
</div>
)
}
const renderAdditionalButtons = () => {
if (isActive) {
return (
<>
<Tooltip key="1" title="Сравнение версий">
<Button
onClick={() => handleShowCompareModal(record)}
icon={<SwapOutlined />}
/>
</Tooltip>
<Tooltip key="2" title="Просмотр истории">
<Button
onClick={navigateToAllVersion}
icon={<HistoryOutlined />}
/>
</Tooltip>
</>
<Dropdown dropdownRender={() => renderDropDownActive(record)}>
<Button icon={<EllipsisOutlined />} />
</Dropdown>
)
}
@@ -83,8 +114,8 @@ const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
<Button onClick={() => handleMarkConfigActive(record)} icon={<AlertOutlined />} />
</Tooltip>
</CanEdit>
<Dropdown dropdownRender={() => renderDropDown(record)}>
<Button icon={<EllipsisOutlined />} />
<Dropdown dropdownRender={() => renderDropDownNoActive(record)}>
<Button icon={<EllipsisOutlined />} />
</Dropdown>
</>
)
@@ -92,20 +123,20 @@ const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
return (
<div className="active-configurations-table-actions-field">
<Button.Group className="button_group">
<Tooltip title="Просмотр">
<Button
onClick={() => handleShowConfig(record)}
icon={<EyeOutlined />}
/>
</Tooltip>
<CanEdit>
<Tooltip title="Редактировать">
<Button onClick={() => {
navigate(`/${record.moduleId}/${routePaths.configEditor}/${record.id}`, { state: record })
}} icon={<EditOutlined />} />
<Tooltip title="Просмотр">
<Button
onClick={() => handleShowConfig(record)}
icon={<EyeOutlined />}
/>
</Tooltip>
</CanEdit>
{renderAdditionalButtons()}
<CanEdit>
<Tooltip title="Редактировать">
<Button onClick={() => {
navigate(`/${record.moduleId}/${routePaths.configEditor}/${record.id}`, { state: record })
}} icon={<EditOutlined />} />
</Tooltip>
</CanEdit>
{renderAdditionalButtons()}
</Button.Group>
</div>
)
+4 -3
View File
@@ -13,7 +13,8 @@ const Modal = ({
footer,
title,
children,
onClose = () => {}
onClose = () => {},
loading = false
}: ModalPropsType) => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
@@ -49,10 +50,10 @@ const Modal = ({
<div className="modal__content">{children}</div>
{footer && (
<div className="modal__footer">
<Button type="default" onClick={closeModal}>
<Button type="default" onClick={closeModal} >
{footer.onCanselText}
</Button>
<Button type="primary" onClick={onOk}>
<Button type="primary" onClick={onOk} loading={loading}>
{footer.onOkText}
</Button>
</div>
+1
View File
@@ -7,4 +7,5 @@ export interface ModalPropsType {
title: string
children: ReactNode
footer?: { onOkText: string; onCanselText: string }
loading?: boolean
}