Skip to content

Commit

Permalink
fix: Admin user filterList
Browse files Browse the repository at this point in the history
  • Loading branch information
liiil825 committed Jan 31, 2019
1 parent 0794856 commit 1ce8426
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/locales/zh/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Normal Role Title Count": "终端角色({{count}})",
"Operation list": "操作列表",
"Edit info": "编辑信息",
"Change password successful": "修改密码成功",
"isv": "应用服务商",
"user": "用户",
"Set permission": "设置权限",
Expand All @@ -33,6 +34,8 @@
"Selected": "所选",
"of setting": "的设置",
"ISV": "应用服务商",
"Activation": "激活",
"Not activation": "非激活",
"Parent group groupName": "上一级组织名:{{groupName}}",
"Create role success": "角色创建成功",
"Create_Role_Success_Tip": "新角色默认是停用状态,请完成权限设置后再启用。",
Expand Down
31 changes: 28 additions & 3 deletions src/portals/admin/pages/Users/ModalActions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { Input, Select } from 'components/Base';
import { Dialog } from 'components/Layout';
import EnhanceTable from 'components/EnhanceTable';

import columns from '../columns';
import columns, { filterList } from '../columns';

import styles from '../index.scss';

const emailRegexp = '^[A-Za-z0-9._%-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$';
Expand Down Expand Up @@ -106,7 +107,8 @@ export default class UserModalActions extends Component {
isLoading={groupStore.isLoading}
store={groupStore}
data={users}
columns={columns(t)}
columns={columns()}
filterList={filterList(groupStore)}
/>
</Dialog>
);
Expand Down Expand Up @@ -151,7 +153,7 @@ export default class UserModalActions extends Component {
const { userStore, modalStore, t } = this.props;
const { isOpen, hide, item } = modalStore;
const { setRole, roles, userNames } = userStore;
const roleId = _.get(item, 'role');
const roleId = _.get(item, 'role[0].role_id', '');
const userId = _.get(item, 'user_id') || userStore.selectIds.join(',');
const names = userId ? item.username : userNames;
const text = userId
Expand Down Expand Up @@ -209,6 +211,7 @@ export default class UserModalActions extends Component {
defaultValue={username}
required
/>
<Input name="user_id" type="hidden" defaultValue={user_id} />
</div>
)}
<div className={styles.formItem}>
Expand Down Expand Up @@ -248,6 +251,28 @@ export default class UserModalActions extends Component {
);
}

renderModalResetPassword() {
const { t, modalStore, userStore } = this.props;
const { hide, isOpen, item } = modalStore;
const { changePwd } = userStore;

return (
<Dialog
title={t('Change Password')}
visible={isOpen}
width={744}
onSubmit={changePwd}
onCancel={hide}
>
<div className={styles.formItem}>
<label>{t('Password')}</label>
<Input name="user_id" type="hidden" defaultValue={item.user_id} />
<Input name="password" type="password" maxLength={50} />
</div>
</Dialog>
);
}

renderModalDeleteUser() {
const { t, modalStore, userStore } = this.props;
const { hide, isOpen, item } = modalStore;
Expand Down
15 changes: 14 additions & 1 deletion src/portals/admin/pages/Users/columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import _ from 'lodash';
import Status from 'components/Status';
import TimeShow from 'components/TimeShow';
import LessText from 'components/LessText';
import { t } from 'i18next';

export default (t, renderHandleMenu) => {
export default renderHandleMenu => {
const columns = [
{
title: t('Status'),
Expand Down Expand Up @@ -57,3 +58,15 @@ export default (t, renderHandleMenu) => {

return columns;
};

export const filterList = store => [
{
key: 'status',
conditions: [
{ name: t('Activation'), value: 'active' },
{ name: t('Not activation'), value: 'deleted' }
],
onChangeFilter: store.onChangeStatus,
selectValue: store.selectStatus
}
];
8 changes: 6 additions & 2 deletions src/portals/admin/pages/Users/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Layout, {
import EnhanceTable from 'components/EnhanceTable';
import Toolbar from 'components/Toolbar';
import ModalActions from './ModalActions';
import columns from './columns';
import columns, { filterList } from './columns';

import styles from './index.scss';

Expand Down Expand Up @@ -148,6 +148,9 @@ export default class Users extends Component {
{_.isArray(group_id) && (
<span onClick={() => leaveGroupOnce(user)}>{t('Leave group')}</span>
)}
<span onClick={() => modalStore.show('renderModalResetPassword', user)}>
{t('Change Password')}
</span>
<span
onClick={() => modalStore.show(
'renderModalDeleteUser',
Expand Down Expand Up @@ -276,7 +279,8 @@ export default class Users extends Component {
isLoading={userStore.isLoading}
store={userStore}
data={userStore.users}
columns={columns(t, this.renderUserHandleMenu)}
columns={columns(this.renderUserHandleMenu)}
filterList={filterList(userStore)}
/>
</Card>
</Section>
Expand Down
17 changes: 12 additions & 5 deletions src/stores/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,15 @@ export default class UserStore extends Store {
if (!params.email) {
return this.error('Empty email');
}
if (!params.role) {
return this.error('Empty role');
}

if (params.user_id) {
if (!params.password) {
delete params.password;
}
await this.modify(params);
} else {
// create user
if (!params.role) {
return this.error('Empty role');
}
if (!params.password) {
return this.error('Empty password');
}
Expand Down Expand Up @@ -238,6 +236,15 @@ export default class UserStore extends Store {
return result;
};

@action
changePwd = async (e, data) => {
const result = await this.changePassword(data);
if (_.get(result, 'user_id')) {
this.success('Change password successful');
this.modal.hide();
}
};

@action
remove = async () => {
const result = await this.request.delete('users', {
Expand Down

0 comments on commit 1ce8426

Please sign in to comment.