Skip to content

Commit ad93a35

Browse files
committed
Merge remote-tracking branch 'origin/master' into 506-salesforce-message-publisher
2 parents 699e716 + 0931219 commit ad93a35

File tree

13 files changed

+872
-17
lines changed

13 files changed

+872
-17
lines changed

src/client/package-lock.json

Lines changed: 109 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@hookform/resolvers": "^3.1.0",
67
"@material-ui/core": "^4.9.14",
78
"@material-ui/icons": "^4.9.1",
89
"@material-ui/lab": "^4.0.0-alpha.53",
@@ -15,8 +16,10 @@
1516
"moment": "^2.29.1",
1617
"react": "^16.13.1",
1718
"react-dom": "^16.13.1",
19+
"react-hook-form": "^7.43.9",
1820
"react-router-dom": "^5.2.0",
19-
"react-scripts": "3.4.1"
21+
"react-scripts": "3.4.1",
22+
"yup": "^1.1.1"
2023
},
2124
"scripts": {
2225
"start": "IS_LOCAL=false react-scripts start",

src/client/src/App.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Refresh from './components/Refresh';
1818
import useToken from './pages/Login/useToken';
1919
import Box from "@material-ui/core/Box";
2020
import {RFM} from "./pages/RFM/RFM";
21+
import UserManagement from './pages/UserManagement/UserManagement';
2122

2223
let jwt = require('jsonwebtoken');
2324

@@ -157,6 +158,11 @@ function AuthenticatedApp() {
157158
<Refresh/>
158159
</Route>
159160

161+
<Route path="/users">
162+
<UserManagement access_token={access_token}/>
163+
</Route>
164+
165+
160166
</Switch>
161167
}
162168

src/client/src/components/Header.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class Header extends Component {
2626
{this.props.headerType === 'Admin' &&
2727
<Button size="large" component={RouterLink} to="/admin">Admin</Button>}
2828

29+
{this.props.headerType === 'Admin' &&
30+
<Button size="large" component={RouterLink} to="/users">Users</Button>}
31+
2932
{this.props.headerType !== 'Login' && <Button size="large" component={RouterLink} to="/360view/search">360
3033
DataView</Button>
3134
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { yupResolver } from "@hookform/resolvers/yup";
2+
import {
3+
Button,
4+
Dialog,
5+
DialogActions,
6+
DialogContent,
7+
DialogTitle,
8+
TextField,
9+
Typography
10+
} from '@material-ui/core';
11+
import React from 'react';
12+
import { useForm } from 'react-hook-form';
13+
import * as Yup from 'yup';
14+
import { updateUser } from "../../../../utils/api";
15+
import { buildPasswordValidation } from '../../Validations';
16+
17+
18+
export default function ChangePasswordDialog(props) {
19+
const {
20+
onClose,
21+
notifyResult,
22+
token,
23+
user
24+
} = props;
25+
const { username } = user;
26+
27+
const validationSchema = Yup.object().shape({
28+
password: buildPasswordValidation(username),
29+
confirmPassword: Yup.string().oneOf([Yup.ref("password")], "Passwords must match"),
30+
});
31+
32+
const { register, handleSubmit, formState: { errors }, trigger } = useForm({
33+
resolver: yupResolver(validationSchema),
34+
});
35+
36+
const onSubmitHandler = (data) => {
37+
const { password } = data;
38+
39+
updateUser({ username, password }, token)
40+
.then((res) => {
41+
if (res === "Updated") {
42+
notifyResult({ success: true, message: `Password for user ${username} successfully changed!` });
43+
} else {
44+
notifyResult({ success: false, message: res });
45+
}
46+
})
47+
.catch(e => {
48+
console.warn(e)
49+
notifyResult({ success: false, message: e })
50+
});
51+
onClose();
52+
}
53+
54+
return (
55+
<Dialog
56+
hideBackdrop
57+
fullWidth
58+
open
59+
>
60+
<DialogTitle style={{ fontSize: "20px" }}>Change Password</DialogTitle>
61+
<form onSubmit={handleSubmit(onSubmitHandler)}>
62+
<DialogContent>
63+
<Typography>
64+
{`Fill out the fields below to update the password for user with username: ${user.username}.`}
65+
</Typography>
66+
<TextField
67+
{...register("password")}
68+
margin="dense"
69+
id="password-input"
70+
label="Password"
71+
onBlur={() => trigger("password")}
72+
type="password"
73+
fullWidth
74+
/>
75+
{errors.password &&
76+
<Typography color="error">{errors.password.message}</Typography>
77+
}
78+
<TextField
79+
{...register("confirmPassword")}
80+
margin="dense"
81+
id="confirm-password-input"
82+
label="Confirm Password"
83+
onBlur={() => trigger("confirmPassword")}
84+
type="password"
85+
fullWidth
86+
/>
87+
{errors.confirmPassword &&
88+
<Typography color="error">{errors.confirmPassword.message}</Typography>
89+
}
90+
<DialogActions>
91+
<Button
92+
onClick={onClose}
93+
>
94+
Cancel
95+
</Button>
96+
<Button
97+
type="submit"
98+
>
99+
Submit
100+
</Button>
101+
</DialogActions>
102+
</DialogContent>
103+
</form>
104+
</Dialog>
105+
)
106+
}

0 commit comments

Comments
 (0)