Skip to content

Commit 55c5c19

Browse files
committed
Code refactoring
1 parent da7d164 commit 55c5c19

File tree

5 files changed

+46
-31
lines changed

5 files changed

+46
-31
lines changed

reactjs/src/components/LanguageSelect/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,25 @@ import { Menu, Dropdown, Icon } from 'antd';
33
import classNames from 'classnames';
44
import './index.less';
55
import 'famfamfam-flags/dist/sprite/famfamfam-flags.css';
6+
import UserStore from 'src/stores/userStore';
7+
import { inject } from 'mobx-react';
8+
import Stores from 'src/stores/storeIdentifier';
9+
import { L } from 'src/lib/abpUtility';
610

7-
class LanguageSelect extends React.Component {
11+
export interface ILanguageSelectProps {
12+
userStore?: UserStore;
13+
}
14+
15+
@inject(Stores.UserStore)
16+
class LanguageSelect extends React.Component<ILanguageSelectProps> {
817
get languages() {
918
return abp.localization.languages.filter(val => {
1019
return !val.isDisabled;
1120
});
1221
}
1322

14-
changeLanguage(languageName: string) {
23+
async changeLanguage(languageName: string) {
24+
await this.props.userStore!.changeLanguage(languageName);
1525
abp.utils.setCookieValue(
1626
'Abp.Localization.CultureName',
1727
languageName,
@@ -38,7 +48,7 @@ class LanguageSelect extends React.Component {
3848
);
3949
return (
4050
<Dropdown overlay={langMenu} placement="bottomRight">
41-
<Icon type="global" className={classNames('dropDown', 'className')} title={'Diller'} />
51+
<Icon type="global" className={classNames('dropDown', 'className')} title={L('Languages')} />
4252
</Dropdown>
4353
);
4454
}

reactjs/src/components/Router/ProtectedRoute.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import { Route, Redirect } from 'react-router-dom';
3+
import { isGranted } from 'src/lib/abpUtility';
34
// import { Alert } from 'antd';
45
// import { isGranted } from 'src/lib/abpUtility';
56

@@ -18,18 +19,16 @@ const ProtectedRoute = ({ path, component: Component, permission, render, ...res
1819
/>
1920
);
2021

21-
// if (permission && !isGranted(permission)) {
22-
// console.log('Not authorized!');
23-
// return (
24-
// <Alert message="No permission." type="error" showIcon />
25-
// // <Redirect
26-
// // to={{
27-
// // pathname: '/error-403', //TODO: implement NotAuthorized component
28-
// // state: { from: props.location },
29-
// // }}
30-
// // />
31-
// );
32-
// }
22+
if (permission && !isGranted(permission)) {
23+
return (
24+
<Redirect
25+
to={{
26+
pathname: '/exception?type=401',
27+
state: { from: props.location },
28+
}}
29+
/>
30+
);
31+
}
3332

3433
return Component ? <Component {...props} /> : render(props);
3534
}}

reactjs/src/components/Router/router.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ export const appRouters: any = [
8484
showInMenu: false,
8585
component: LoadableComponent(() => import('src/components/Logout')),
8686
},
87+
{
88+
path: '/exception',
89+
permission: '',
90+
title: 'exception',
91+
name: 'exception',
92+
icon: 'info-circle',
93+
showInMenu: false,
94+
component: LoadableComponent(() => import('src/scenes/Exception')),
95+
},
8796
];
8897

8998
export const routers = [...userRouter, ...appRouters];

reactjs/src/scenes/Exception/index.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
2-
3-
4-
51
import error404 from 'src/images/404.png';
62
import error401 from 'src/images/401.png';
73
import error500 from 'src/images/500.png';
84
import { Link } from 'react-router-dom';
95

106
import './index.css';
11-
import * as React from 'react';
7+
import * as React from 'react';
128
import { Row, Col, Avatar, Button } from 'antd';
139

14-
1510
const exception = [
1611
{
1712
errorCode: '404',
@@ -97,7 +92,7 @@ class Exception extends React.Component<any, any> {
9792
<Button type={'primary'}>
9893
<Link
9994
to={{
100-
pathname: '/dashboard',
95+
pathname: '/',
10196
}}
10297
>
10398
Back to Home

reactjs/src/stores/userStore.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { action, observable } from 'mobx';
1+
import { action, observable } from 'mobx';
22

33
import userService from 'src/services/user/userService';
44
import { PagedResultDto } from 'src/services/dto/pagedResultDto';
@@ -9,12 +9,9 @@ import { CreateOrUpdateUserInput } from 'src/services/user/dto/createOrUpdateUse
99
import { GetRoles } from 'src/services/user/dto/getRolesOuput';
1010

1111
class UserStore {
12-
@observable
13-
users: PagedResultDto<GetUserOutput>;
14-
@observable
15-
editUser: CreateOrUpdateUserInput;
16-
@observable
17-
roles: GetRoles[]=[];
12+
@observable users: PagedResultDto<GetUserOutput>;
13+
@observable editUser: CreateOrUpdateUserInput;
14+
@observable roles: GetRoles[] = [];
1815

1916
@action
2017
async create(createUserInput: CreateOrUpdateUserInput) {
@@ -54,7 +51,7 @@ class UserStore {
5451
async get(entityDto: EntityDto) {
5552
var result = await userService.get(entityDto);
5653
console.log(result);
57-
this.editUser=result;
54+
this.editUser = result;
5855
}
5956

6057
@action
@@ -69,14 +66,19 @@ class UserStore {
6966
password: '',
7067
id: 0,
7168
};
72-
this.roles=[];
69+
this.roles = [];
7370
}
71+
7472
@action
7573
async getAll(pagedFilterAndSortedRequest: PagedFilterAndSortedRequest) {
7674
var result = await userService.getAll(pagedFilterAndSortedRequest);
7775
console.log(result);
7876
this.users = result;
7977
}
78+
79+
async changeLanguage(languageName: string) {
80+
await userService.changeLanguage({ languageName: languageName });
81+
}
8082
}
8183

8284
export default UserStore;

0 commit comments

Comments
 (0)