Skip to content

Commit 9012444

Browse files
committed
Setup ES and TS versions of project
1 parent 9567ed0 commit 9012444

File tree

231 files changed

+4558
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+4558
-44
lines changed

package-lock.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
"start": "react-app-rewired start",
77
"build": "react-app-rewired build",
88
"test": "react-app-rewired test",
9-
"eject": "react-scripts eject",
109
"deploy": "npm run build-preview && npm run build-docs && gh-pages -d build --repo git@github.com:modularcode/modular-admin-react.git --branch gh-pages",
10+
1111
"build-preview": "cross-env PUBLIC_PATH='/' npm run build && echo modular-admin-react.modularcode.io > ./build/CNAME",
1212
"build-docs": "build-storybook --docs -s ./public -o build/docs",
1313
"build-storybook": "build-storybook",
14-
"storybook": "start-storybook -p 6060"
14+
"storybook": "start-storybook -p 6060",
15+
16+
"es:init": "npm run es:clean && npm run es:build && npm run es:prettify",
17+
"es:clean": "rimraf src-es/",
18+
"es:build": "tsc --project ./tsconfig.to-es.json",
19+
"es:prettify": "prettier --config ./.prettierrc.js --write \"src-es/**/*.(js|jsx)\"",
20+
21+
"eject": "react-scripts eject"
1522
},
1623
"homepage": "http://modular-admin-react.modularcode.io",
1724
"dependencies": {
@@ -63,6 +70,7 @@
6370
"prettier": "2.2.1",
6471
"react-app-rewired": "^2.1.8",
6572
"react-docgen-typescript-loader": "^3.7.2",
73+
"rimraf": "^3.0.2",
6674
"ts-loader": "^9.1.1"
6775
},
6876
"eslintConfig": {

src

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src-ts

src-es/Account/Account.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'use strict'

src-es/Account/Profile/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const ProfileModule = {
2+
init() {},
3+
}
4+
export default ProfileModule

src-es/Account/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const AccountModule = {
2+
init() {},
3+
}
4+
export default AccountModule
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
import { Route } from 'react-router-dom'
3+
import UsersList from './Users/UsersList'
4+
import UserEditor from './Users/UsersEditor/UsersEditor'
5+
const Administration = ({ match }) => {
6+
return (
7+
<>
8+
<Route exact path={`${match.path}/users`} component={UsersList} />
9+
<Route
10+
path={`${match.path}/users/new`}
11+
render={(props) => <UserEditor {...props} />}
12+
/>
13+
<Route
14+
path={`${match.path}/users/:userId/edit`}
15+
render={(props) => (
16+
<UserEditor {...props} userId={parseInt(props.match.params.userId)} />
17+
)}
18+
/>
19+
</>
20+
)
21+
}
22+
Administration.propTypes = {}
23+
export default Administration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import React, { useEffect, useState } from 'react'
2+
import PropTypes from 'prop-types'
3+
import api from '@/_api'
4+
import BasePageContainer from '@/_common/BasePageContainer'
5+
import BasePageToolbar from '@/_common/BasePageToolbar'
6+
import { Save as SaveIcon } from '@material-ui/icons/'
7+
import {
8+
Input,
9+
Select,
10+
MenuItem,
11+
Paper,
12+
Button,
13+
FormControl,
14+
InputLabel,
15+
makeStyles,
16+
Grid,
17+
} from '@material-ui/core'
18+
const UserEditor = (props) => {
19+
const classes = useStyles()
20+
const { userId } = props
21+
const [user, setUser] = useState({
22+
avatarUrl: '',
23+
email: '',
24+
firstName: '',
25+
globalRole: '',
26+
lastName: '',
27+
userToOrganizations: [{}],
28+
username: '',
29+
})
30+
useEffect(() => {
31+
if (!userId) {
32+
return
33+
}
34+
async function fetchUser() {
35+
try {
36+
const userDataRes = await api.users.getOne(userId)
37+
setUser(userDataRes)
38+
} catch (err) {
39+
console.log('error', err.message)
40+
}
41+
}
42+
fetchUser()
43+
}, [userId])
44+
const onChangeHandler = (e) =>
45+
setUser({
46+
...user,
47+
[e.target.name]: e.target.value,
48+
})
49+
const setGlobalRole = (e) =>
50+
setUser({
51+
...user,
52+
globalRole: e.target.value,
53+
})
54+
const handleSubmit = async (e) => {
55+
e.preventDefault()
56+
try {
57+
if (userId) {
58+
await api.users.update(userId, user)
59+
} else {
60+
await api.users.create(user)
61+
}
62+
} catch (e) {
63+
console.log(e)
64+
}
65+
}
66+
return (
67+
<BasePageContainer>
68+
<BasePageToolbar title={'Edit user'}></BasePageToolbar>
69+
<Grid container xs={12} component={Paper} className={classes.box}>
70+
<form onSubmit={handleSubmit}>
71+
<FormControl className={classes.control}>
72+
<InputLabel>First Name</InputLabel>
73+
<Input
74+
value={user.firstName}
75+
name="firstName"
76+
className={classes.width}
77+
onChange={(e) => onChangeHandler(e)}
78+
/>
79+
</FormControl>
80+
<FormControl className={classes.control}>
81+
<InputLabel>Last Name</InputLabel>
82+
<Input
83+
value={user.lastName}
84+
name="lastName"
85+
className={classes.width}
86+
onChange={(e) => onChangeHandler(e)}
87+
/>
88+
</FormControl>
89+
<FormControl className={classes.control}>
90+
<InputLabel>User Name</InputLabel>
91+
<Input
92+
value={user.username}
93+
name="username"
94+
className={classes.width}
95+
onChange={(e) => onChangeHandler(e)}
96+
/>
97+
</FormControl>
98+
<FormControl className={classes.control}>
99+
<InputLabel>Email</InputLabel>
100+
<Input
101+
value={user.email}
102+
name="email"
103+
className={classes.width}
104+
onChange={(e) => onChangeHandler(e)}
105+
/>
106+
</FormControl>
107+
<FormControl className={classes.control}>
108+
<InputLabel>Global Role</InputLabel>
109+
<Select
110+
labelId="Set Global Role"
111+
id="globalRole"
112+
value={user.globalRole}
113+
onChange={setGlobalRole}
114+
className={classes.width}
115+
>
116+
<MenuItem value={user.globalRole}>{user.globalRole}</MenuItem>
117+
<MenuItem value="user">user</MenuItem>
118+
<MenuItem value="support">support</MenuItem>
119+
</Select>
120+
</FormControl>
121+
<Button
122+
variant="contained"
123+
color="primary"
124+
type="submit"
125+
className={`${classes.margin} ${classes.width}`}
126+
startIcon={<SaveIcon />}
127+
>
128+
Edit User
129+
</Button>
130+
</form>
131+
</Grid>
132+
</BasePageContainer>
133+
)
134+
}
135+
UserEditor.propTypes = {
136+
userId: PropTypes.number,
137+
}
138+
const useStyles = makeStyles((theme) => ({
139+
box: {
140+
padding: 16,
141+
},
142+
control: {
143+
display: 'block',
144+
marginTop: 16,
145+
},
146+
margin: {
147+
marginTop: 16,
148+
},
149+
width: {
150+
minWidth: 200,
151+
},
152+
}))
153+
export default UserEditor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'use strict'

0 commit comments

Comments
 (0)