fix(frontend): update password
This commit is contained in:
parent
0d1add60c2
commit
5b299b993a
|
|
@ -9,8 +9,14 @@ import {
|
||||||
Stack,
|
Stack,
|
||||||
TextField
|
TextField
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
import { useBackendContext } from 'src/contexts/backend-context';
|
||||||
|
import { useAlertContext } from 'src/contexts/error-context';
|
||||||
|
|
||||||
export const SettingsPassword = () => {
|
export const SettingsPassword = () => {
|
||||||
|
|
||||||
|
let {httpRequest} = useBackendContext();
|
||||||
|
let {setAlert} = useAlertContext();
|
||||||
|
|
||||||
const [values, setValues] = useState({
|
const [values, setValues] = useState({
|
||||||
password: '',
|
password: '',
|
||||||
confirm: ''
|
confirm: ''
|
||||||
|
|
@ -26,15 +32,8 @@ export const SettingsPassword = () => {
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSubmit = useCallback(
|
|
||||||
(event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit}>
|
<form>
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader
|
<CardHeader
|
||||||
subheader="Update password"
|
subheader="Update password"
|
||||||
|
|
@ -66,7 +65,26 @@ export const SettingsPassword = () => {
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<Divider />
|
<Divider />
|
||||||
<CardActions sx={{ justifyContent: 'flex-end' }}>
|
<CardActions sx={{ justifyContent: 'flex-end' }}>
|
||||||
<Button variant="contained">
|
<Button variant="contained"
|
||||||
|
onClick={async ()=>{
|
||||||
|
if (values.password !== values.confirm) {
|
||||||
|
console.log("Passwords do not match")
|
||||||
|
setAlert({
|
||||||
|
severity: 'error',
|
||||||
|
message: 'Passwords do not match'
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let {status} = await httpRequest('/api/auth/password', 'PUT', JSON.stringify({"password": values.password}))
|
||||||
|
if (status === 204) {
|
||||||
|
console.log("Password updated")
|
||||||
|
setAlert({
|
||||||
|
severity: 'success',
|
||||||
|
message: 'Password updated'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
Update
|
Update
|
||||||
</Button>
|
</Button>
|
||||||
</CardActions>
|
</CardActions>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user