Skip to content

Commit 44d5b3c

Browse files
committed
complete rootes
1 parent c90195f commit 44d5b3c

20 files changed

Lines changed: 653 additions & 0 deletions

File tree

src/admin/client/rootReducer.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { combineReducers } from 'redux';
2+
import { reducer as formReducer } from 'redux-form';
3+
4+
import productCategories from 'modules/productCategories/reducer';
5+
import products from 'modules/products/reducer';
6+
import customerGroups from 'modules/customerGroups/reducer';
7+
import customers from 'modules/customers/reducer';
8+
import orders from 'modules/orders/reducer';
9+
import orderStatuses from 'modules/orderStatuses/reducer';
10+
import pages from 'modules/pages/reducer';
11+
import settings from 'modules/settings/reducer';
12+
import apps from 'modules/apps/reducer';
13+
import files from 'modules/files/reducer';
14+
15+
export default combineReducers({
16+
form: formReducer,
17+
productCategories,
18+
products,
19+
settings,
20+
customerGroups,
21+
customers,
22+
orders,
23+
orderStatuses,
24+
pages,
25+
apps,
26+
files
27+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { Switch, Route, NavLink } from 'react-router-dom';
3+
import * as auth from 'lib/webstoreAuth';
4+
import NotFound from 'routes/notFound';
5+
import Login from 'routes/apps/login';
6+
import Account from 'modules/apps/account';
7+
import Services from 'modules/apps/services';
8+
import ServiceDetails from 'modules/apps/serviceDetails';
9+
import AppDetails from 'modules/apps/appDetails';
10+
11+
export default () => (
12+
<Switch>
13+
<Route path="/admin/apps" exact component={Services} />
14+
<Route
15+
path="/admin/apps/service/:serviceId"
16+
exect
17+
component={ServiceDetails}
18+
/>
19+
<Route path="/admin/apps/app/:appKey" exect component={AppDetails} />
20+
<Route path="/admin/apps/login" exact component={Login} />
21+
<Route path="/admin/apps/account" exact component={Account} />
22+
<Route component={NotFound} />
23+
</Switch>
24+
);
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import React from 'react';
2+
import messages from 'lib/text';
3+
import CezerinClient from 'cezerin-client';
4+
import * as auth from 'lib/webstoreAuth';
5+
6+
import RaisedButton from 'material-ui/RaisedButton';
7+
import Paper from 'material-ui/Paper';
8+
import TextField from 'material-ui/TextField';
9+
10+
export default class LoginForm extends React.Component {
11+
constructor(props) {
12+
super(props);
13+
this.state = {
14+
email: localStorage.getItem('webstore_email') || '',
15+
isFetching: false,
16+
emailIsSent: false,
17+
error: null
18+
};
19+
}
20+
21+
handleChange = event => {
22+
this.setState({
23+
email: event.target.value
24+
});
25+
};
26+
27+
handleKeyPress = e => {
28+
if (e.keyCode === 13 || e.which === 13) {
29+
this.handleSubmit();
30+
}
31+
};
32+
33+
handleSubmit = () => {
34+
this.setState({
35+
isFetching: true,
36+
emailIsSent: false,
37+
error: null
38+
});
39+
40+
CezerinClient.authorizeInWebStore(
41+
this.state.email,
42+
location.origin + '/admin'
43+
).then(({ status, json }) => {
44+
this.setState({
45+
isFetching: false,
46+
emailIsSent: status === 200,
47+
error: status !== 200 && json ? json.message : null
48+
});
49+
});
50+
};
51+
52+
componentWillMount() {
53+
auth.checkTokenFromUrl();
54+
}
55+
56+
render() {
57+
const { email, isFetching, emailIsSent, error } = this.state;
58+
59+
let response = null;
60+
if (isFetching) {
61+
response = (
62+
<div className="loginSuccessResponse">{messages.messages_loading}</div>
63+
);
64+
} else if (emailIsSent) {
65+
response = (
66+
<div className="loginSuccessResponse">{messages.loginLinkSent}</div>
67+
);
68+
} else if (emailIsSent === false && error) {
69+
response = <div className="loginErrorResponse">{error}</div>;
70+
}
71+
72+
return (
73+
<div className="row col-full-height center-xs middle-xs">
74+
<div className="col-xs-12 col-sm-8 col-md-6 col-lg-4">
75+
<Paper className="loginBox" zDepth={1}>
76+
<div className="loginTitle">{messages.webstoreLoginTitle}</div>
77+
<div className="loginDescription">{messages.loginDescription}</div>
78+
<div className="loginInput">
79+
<TextField
80+
type="email"
81+
value={email}
82+
onChange={this.handleChange}
83+
onKeyPress={this.handleKeyPress}
84+
label={messages.email}
85+
fullWidth={true}
86+
hintStyle={{ width: '100%' }}
87+
hintText={messages.email}
88+
/>
89+
</div>
90+
<RaisedButton
91+
label={messages.loginButton}
92+
primary={true}
93+
disabled={isFetching || emailIsSent}
94+
onClick={this.handleSubmit}
95+
/>
96+
{response}
97+
</Paper>
98+
</div>
99+
</div>
100+
);
101+
}
102+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import React from 'react';
2+
import CustomerDetails from 'modules/customers/edit';
3+
4+
export default CustomerDetails;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import GroupEdit from 'modules/customerGroups/edit';
3+
import Groups from 'modules/customerGroups/list';
4+
5+
export default () => (
6+
<div className="row row--no-gutter col-full-height">
7+
<div className="col-xs-12 col-sm-4 col-md-3 col--no-gutter scroll col-full-height">
8+
<Groups showAll={false} showRoot={false} showAdd={true} />
9+
</div>
10+
<div className="col-xs-12 col-sm-8 col-md-9 col--no-gutter scroll col-full-height">
11+
<GroupEdit />
12+
</div>
13+
</div>
14+
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import CustomersList from 'modules/customers/list';
3+
import Groups from 'modules/customerGroups/list';
4+
5+
export default () => (
6+
<div className="row row--no-gutter col-full-height">
7+
<div className="col-xs-12 col-sm-4 col-md-3 col--no-gutter scroll col-full-height">
8+
<Groups showAll={true} showRoot={false} showManage={true} />
9+
</div>
10+
<div className="col-xs-12 col-sm-8 col-md-9 col--no-gutter scroll col-full-height">
11+
<CustomersList />
12+
</div>
13+
</div>
14+
);

src/admin/client/routes/files.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import List from 'modules/files/list';
3+
4+
export default () => (
5+
<div className="row row--no-gutter col-full-height scroll">
6+
<div className="col-xs-12 col-sm-12 col-md-10 col-lg-8 col-md-offset-1 col-lg-offset-2">
7+
<List />
8+
</div>
9+
</div>
10+
);

src/admin/client/routes/home.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import OrdersBar from 'modules/reports/ordersBar';
3+
import { defaults } from 'react-chartjs-2';
4+
5+
// Set charts default
6+
defaults.global.responsive = true;
7+
defaults.global.maintainAspectRatio = false;
8+
defaults.global.title.display = false;
9+
defaults.global.legend.position = 'bottom';
10+
defaults.global.legend.labels.boxWidth = 20;
11+
defaults.global.tooltips.mode = 'index';
12+
defaults.global.tooltips.intersect = false;
13+
defaults.global.tooltips.bodySpacing = 8;
14+
defaults.global.tooltips.titleMarginBottom = 16;
15+
16+
export default () => (
17+
<div className="scroll col-full-height">
18+
<OrdersBar />
19+
</div>
20+
);

src/admin/client/routes/login.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import React from 'react';
2+
import messages from 'lib/text';
3+
import CezerinClient from 'cezerin-client';
4+
import settings from 'lib/settings';
5+
import * as auth from 'lib/auth';
6+
7+
import RaisedButton from 'material-ui/RaisedButton';
8+
import Paper from 'material-ui/Paper';
9+
import TextField from 'material-ui/TextField';
10+
11+
export default class LoginForm extends React.Component {
12+
constructor(props) {
13+
super(props);
14+
this.state = {
15+
email: localStorage.getItem('dashboard_email') || '',
16+
isFetching: false,
17+
isAuthorized: false,
18+
emailIsSent: false,
19+
error: null
20+
};
21+
}
22+
23+
handleChange = event => {
24+
this.setState({
25+
email: event.target.value
26+
});
27+
};
28+
29+
handleKeyPress = e => {
30+
if (e.keyCode === 13 || e.which === 13) {
31+
this.handleSubmit();
32+
}
33+
};
34+
35+
handleSubmit = () => {
36+
this.setState({
37+
isFetching: true,
38+
isAuthorized: false,
39+
emailIsSent: false,
40+
error: null
41+
});
42+
43+
CezerinClient.authorize(settings.apiBaseUrl, this.state.email)
44+
.then(authorizeResponse => {
45+
this.setState({
46+
isFetching: false,
47+
isAuthorized: false,
48+
emailIsSent: authorizeResponse.json.sent,
49+
error: authorizeResponse.json.error
50+
});
51+
})
52+
.catch(error => {
53+
this.setState({
54+
isFetching: false,
55+
isAuthorized: false,
56+
emailIsSent: false,
57+
error: error
58+
});
59+
});
60+
};
61+
62+
componentWillMount() {
63+
auth.checkTokenFromUrl();
64+
}
65+
componentDidMount() {}
66+
67+
render() {
68+
const { email, isFetching, isAuthorized, emailIsSent, error } = this.state;
69+
70+
let response = null;
71+
if (isFetching) {
72+
response = (
73+
<div className="loginSuccessResponse">{messages.messages_loading}</div>
74+
);
75+
} else if (emailIsSent) {
76+
response = (
77+
<div className="loginSuccessResponse">{messages.loginLinkSent}</div>
78+
);
79+
} else if (emailIsSent === false && error) {
80+
response = <div className="loginErrorResponse">{error}</div>;
81+
}
82+
83+
return (
84+
<div className="row col-full-height center-xs middle-xs">
85+
<div className="col-xs-12 col-sm-8 col-md-6 col-lg-4">
86+
<Paper className="loginBox" zDepth={1}>
87+
<div className="loginTitle">{messages.loginTitle}</div>
88+
<div className="loginDescription">{messages.loginDescription}</div>
89+
<div className="loginInput">
90+
<TextField
91+
type="email"
92+
value={email}
93+
onChange={this.handleChange}
94+
onKeyPress={this.handleKeyPress}
95+
label={messages.email}
96+
fullWidth={true}
97+
hintStyle={{ width: '100%' }}
98+
hintText={messages.email}
99+
/>
100+
</div>
101+
<RaisedButton
102+
label={messages.loginButton}
103+
primary={true}
104+
disabled={isFetching || emailIsSent}
105+
onClick={this.handleSubmit}
106+
/>
107+
{response}
108+
</Paper>
109+
</div>
110+
</div>
111+
);
112+
}
113+
}

src/admin/client/routes/logout.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import * as auth from 'lib/auth';
3+
4+
export default class Logout extends React.Component {
5+
componentWillMount() {
6+
auth.removeToken();
7+
}
8+
9+
render() {
10+
return null;
11+
}
12+
}

0 commit comments

Comments
 (0)