Skip to content

Commit

Permalink
fix: some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuhengtan committed Apr 27, 2023
1 parent 98a5663 commit 0ee30bc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/lang/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"Admin list": "Admin list",
"Filter with admin name or email": "Filter with admin name or email",
"Add admin": "Add admin",
"Edit admin": "Edit admin",
"Id": "ID",
"Adminname": "Adminname",
"Admin": "Admin",
Expand Down
1 change: 1 addition & 0 deletions src/lang/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Admin list": "用户管理",
"Filter with admin name or email": "筛选用户名或邮箱",
"Add admin": "添加用户",
"Edit admin": "编辑用户",
"Id": "ID",
"Adminname": "用户名",
"Admin": "用户",
Expand Down
18 changes: 10 additions & 8 deletions src/pages/auth/admin/add-admin-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const {
interface Props {
id: number
visible: boolean
setVisible: Dispatch<SetStateAction<boolean>>
onCancel: () => void
onSuccess?: () => void
}

const AddAdminForm: React.FC<Props> = (props: Props) => {
const {
id, visible, setVisible, onSuccess,
id, visible, onCancel, onSuccess,
} = props
const { t } = useTranslation()

Expand All @@ -49,7 +49,7 @@ const AddAdminForm: React.FC<Props> = (props: Props) => {
if (onSuccess) {
onSuccess()
}
setVisible(false)
onCancel()
},
},
)
Expand All @@ -63,7 +63,7 @@ const AddAdminForm: React.FC<Props> = (props: Props) => {
if (onSuccess) {
onSuccess()
}
setVisible(false)
onCancel()
},
},
)
Expand All @@ -88,8 +88,8 @@ const AddAdminForm: React.FC<Props> = (props: Props) => {
)

const handleCancel = useCallback(() => {
setVisible(false)
}, [setVisible])
onCancel()
}, [onCancel])

const onClickConfirm = useCallback(async () => {
await form.validateFields()
Expand All @@ -105,12 +105,14 @@ const AddAdminForm: React.FC<Props> = (props: Props) => {
if (id) {
getAdminDetail(id)
getAllRoles()
} else {
form.resetFields()
}
}, [getAllRoles, getAdminDetail, id])
}, [getAllRoles, getAdminDetail, id, form])

return (
<Modal
title={t('Add admin')}
title={id ? t('Edit admin') : t('Add admin')}
visible={visible}
onCancel={handleCancel}
onOk={onClickConfirm}
Expand Down
7 changes: 5 additions & 2 deletions src/pages/auth/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const Admins: React.FC = () => {
}}
/>
</div>
<AuthFragment authKey="add">
<AuthFragment authKey="create">
<Button
type="primary"
onClick={() => {
Expand All @@ -216,7 +216,10 @@ const Admins: React.FC = () => {
<AddAdminForm
id={selectedAdminId}
visible={addPanelVisible}
setVisible={setAddPanelVisible}
onCancel={() => {
setSelectedAdminId(0)
setAddPanelVisible(false)
}}
onSuccess={() => {
setSelectedAdminId(0)
getAdmins({ ...pagination }, filter)
Expand Down
14 changes: 9 additions & 5 deletions src/pages/auth/role/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useTranslation } from 'react-i18next'
import AuthFragment from '@/components/auth-fragment'
import api from '@/service'

import { showMessage } from '@/utils'
import RoleDetailDrawer from './role-detail-drawer'

const { getRoles: getRolesRequest, deleteRole: deleteRoleRequest } = api
Expand Down Expand Up @@ -119,7 +120,7 @@ const Roles: React.FC = () => {

return (
<div>
<AuthFragment authKey="add">
<AuthFragment authKey="create">
<Button
type="primary"
size="small"
Expand All @@ -145,10 +146,13 @@ const Roles: React.FC = () => {
visible={drawerVisible}
id={selectedRoleId}
setVisible={setDrawerVisible}
onSuccess={() => getRoles({
current: pagination.current,
pageSize: pagination.pageSize,
})}
onSuccess={() => {
setDrawerVisible(false)
getRoles({
current: pagination.current,
pageSize: pagination.pageSize,
})
}}
/>
</div>
)
Expand Down

0 comments on commit 0ee30bc

Please sign in to comment.