Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1. Index: src/components/UserForm.js
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- src/components/UserForm.js (revision 014fbc30c349feca497916c6912e8da37bdc2af9)
  7. +++ src/components/UserForm.js (date 1542208132427)
  8. @@ -47,10 +47,15 @@
  9. '&:nth-child(6)': {
  10. gridArea: 'lastName'
  11. }
  12. + },
  13. + roleListGrid: {
  14. + display: 'grid',
  15. + gridColumnGap: '15px',
  16. + gridTemplateColumns: '1fr 1fr'
  17. }
  18. });
  19.  
  20. -export default withStyles(styles)(({ classes, handleInputChange, handleSubmit, mode, onTabChange, selectedTab, submitButtonText }) => (
  21. +export default withStyles(styles)(({ classes, handleInputChange, handleSubmit, mode, onTabChange, roles, permissions, uniqueResources, selectedTab, submitButtonText }) => (
  22. <form
  23. autoComplete={"off"}
  24. className={classes.form}
  25. @@ -127,8 +132,15 @@
  26. className={classes.textField}
  27. />
  28. </Typography>}
  29. - {selectedTab === 1 && <RoleList />}
  30. - {selectedTab === 2 && <PermissionList />}
  31. + {selectedTab === 1 && <div className={classes.roleListGrid}>
  32. + <RoleList selectButton resources={uniqueResources} roles={roles} />
  33. + <RoleList removeButton resources={uniqueResources} roles={roles} />
  34. + </div>
  35. + }
  36. + {selectedTab === 2 && <div className={classes.roleListGrid}>
  37. + <PermissionList selectButton permissions={permissions} />
  38. + <PermissionList removeButton permissions={permissions} />
  39. + </div>}
  40. <Button
  41. type={"submit"}
  42. color={"primary"}
  43. Index: src/containers/UserFormContainer.js
  44. IDEA additional info:
  45. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  46. <+>UTF-8
  47. ===================================================================
  48. --- src/containers/UserFormContainer.js (date 1542208042637)
  49. +++ src/containers/UserFormContainer.js (date 1542208042637)
  50. @@ -0,0 +1,154 @@
  51. +import React from 'react';
  52. +import Paper from '@material-ui/core/Paper';
  53. +import Typography from '@material-ui/core/Typography';
  54. +import withStyles from '@material-ui/core/styles/withStyles';
  55. +
  56. +import { findUniqueResources, createPermissions } from '../services/permission-set.service';
  57. +import rolesService from '../services/roles.service';
  58. +import UserForm from '../components/UserForm';
  59. +
  60. +const styles = theme => ({
  61. + paper: {
  62. + width: 1024,
  63. + margin: '64px auto',
  64. + padding: `${theme.spacing.unit * 3}px`
  65. + }
  66. +});
  67. +
  68. +class UserFormContainer extends React.Component {
  69. +
  70. + constructor(props) {
  71. + super(props);
  72. +
  73. + this.state = {
  74. + form: {
  75. + client: '',
  76. + emailAddress: '',
  77. + password: '',
  78. + replicatedPassword: '',
  79. + firstName: '',
  80. + lastName: ''
  81. + },
  82. + modeConfiguration: {
  83. + cardTitle: '',
  84. + submitButtonText: ''
  85. + },
  86. + selectedTab: 0,
  87. + selectedUser: {
  88. + id: '',
  89. + client: '',
  90. + emailAddress: '',
  91. + password: '',
  92. + firstName: '',
  93. + lastName: '',
  94. + permissions: {
  95. + roleSet: [],
  96. + customPermissionSet: [],
  97. + isSuperAdmin: false
  98. + }
  99. + },
  100. + roles: {
  101. + data: [],
  102. + loaded: false,
  103. + loading: false
  104. + },
  105. + permissions: [],
  106. + uniqueResources: []
  107. + };
  108. + }
  109. +
  110. + componentDidMount() {
  111. + if (this.props.mode === 'create') {
  112. + const modeConfiguration = this.state.modeConfiguration;
  113. + modeConfiguration.paperTitle = 'Create user';
  114. + modeConfiguration.submitButtonText = 'Create';
  115. +
  116. + this.setState({
  117. + modeConfiguration: modeConfiguration
  118. + });
  119. + }
  120. +
  121. + if (this.props.mode === 'edit') {
  122. + const modeConfiguration = this.state.modeConfiguration;
  123. + modeConfiguration.paperTitle = 'Edit user';
  124. + modeConfiguration.submitButtonText = 'Edit';
  125. +
  126. + this.setState({
  127. + modeConfiguration: modeConfiguration
  128. + });
  129. + }
  130. +
  131. + rolesService.fetchAll()
  132. + .then(roles => {
  133. + const rolesState = this.state.roles;
  134. + rolesState.data = roles;
  135. + rolesState.loaded = true;
  136. +
  137. + let uniqueResourcesState = findUniqueResources(roles);
  138. +
  139. + this.setState({
  140. + roles: rolesState,
  141. + uniqueResources: uniqueResourcesState
  142. + });
  143. + });
  144. +
  145. + this.setState({
  146. + permissions: createPermissions()
  147. + })
  148. + }
  149. +
  150. + handleInputChange = event => {
  151. + const name = event.target.name;
  152. + const value = event.target.value;
  153. +
  154. + const form = this.state.form;
  155. + form[ name ] = value;
  156. +
  157. + this.setState({
  158. + form: form
  159. + });
  160. + };
  161. +
  162. + handleSubmit = event => {
  163. + event.preventDefault();
  164. +
  165. + if (this.props.mode === 'create') {
  166. + this.handleCreateModeSubmit();
  167. + }
  168. +
  169. + if (this.props.mode === 'edit') {
  170. + this.handleEditModeSubmit();
  171. + }
  172. + };
  173. +
  174. + handleTabChange = (event, value) => {
  175. + this.setState({ selectedTab: value });
  176. + };
  177. +
  178. + handleCreateModeSubmit() {
  179. + }
  180. +
  181. + handleEditModeSubmit() {
  182. + }
  183. +
  184. + render() {
  185. + return (
  186. + <Paper className={this.props.classes.paper}>
  187. + <Typography
  188. + component={"h1"}
  189. + variant={"h5"}>{this.state.modeConfiguration.paperTitle}
  190. + </Typography>
  191. + <UserForm
  192. + roles={this.state.roles.data}
  193. + permissions={this.state.permissions}
  194. + submitButtonText={this.state.modeConfiguration.submitButtonText}
  195. + uniqueResources={this.state.uniqueResources}
  196. + onTabChange={this.handleTabChange}
  197. + selectedTab={this.state.selectedTab}
  198. + />
  199. + </Paper>
  200. + );
  201. + }
  202. +}
  203. +
  204. +export default withStyles(styles)(UserFormContainer);
  205. Index: src/routers/UserRouter.js
  206. IDEA additional info:
  207. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  208. <+>UTF-8
  209. ===================================================================
  210. --- src/routers/UserRouter.js (revision 014fbc30c349feca497916c6912e8da37bdc2af9)
  211. +++ src/routers/UserRouter.js (date 1542198830500)
  212. @@ -3,6 +3,7 @@
  213.  
  214. import NavigationBar from '../components/NavigationBar';
  215.  
  216. +import UserFormContainer from '../containers/UserFormContainer';
  217. import UserListContainer from '../containers/UserListContainer';
  218.  
  219. export default () => (
  220. @@ -10,8 +11,8 @@
  221. <NavigationBar title={"Users"} />
  222. <Switch>
  223. <Route exact path={"/users"} component={UserListContainer} />
  224. - <Route path={"/users/add"} render={{}} />
  225. - <Route path={"/users/detail/:id"} render={{}} />
  226. + <Route path={"/users/add"} render={props => <UserFormContainer mode={"create"} {...props} />} />
  227. + <Route path={"/users/detail/:id"} render={props => <UserFormContainer mode={"edit"} {...props} />} />
  228. </Switch>
  229. </React.Fragment>
  230. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement