Skip to content

Commit 82d6860

Browse files
authored
Add change password form (#159)
* Add change password form * Fix validation callback * Update title
1 parent 4907fb3 commit 82d6860

17 files changed

+106
-3
lines changed

packages/devextreme-cli/templates/react/application/src/NotAuthenticatedContent.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Switch, Route, Redirect } from 'react-router-dom';
33
import { SingleCard } from './layouts';
4-
import { LoginForm, ResetPasswordForm, CreateAccountForm } from './components';
4+
import { LoginForm, ResetPasswordForm, ChangePasswordForm, CreateAccountForm } from './components';
55

66
export default function () {
77
return (
@@ -18,12 +18,17 @@ export default function () {
1818
</Route>
1919
<Route exact path='/reset-password' >
2020
<SingleCard
21-
title="Password Reset"
21+
title="Reset Password"
2222
description="Please enter the email address that you used to register, and we will send you an email with a link to reset your password."
2323
>
2424
<ResetPasswordForm />
2525
</SingleCard>
2626
</Route>
27+
<Route exact path='/change-password/:recoveryCode' >
28+
<SingleCard title="Change Password">
29+
<ChangePasswordForm />
30+
</SingleCard>
31+
</Route>
2732
<Redirect to={'/login'} />
2833
</Switch>
2934
);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React, { useState, useRef, useCallback } from 'react';
2+
import { useHistory, useParams } from 'react-router-dom';
3+
import Form, {
4+
Item,
5+
Label,
6+
ButtonItem,
7+
ButtonOptions,
8+
RequiredRule,
9+
CustomRule,
10+
} from 'devextreme-react/form';
11+
import LoadIndicator from 'devextreme-react/load-indicator';
12+
13+
export default function (props) {
14+
const history = useHistory();
15+
const [loading, setLoading] = useState(false);
16+
const formData = useRef({});
17+
const { recoveryCode } = useParams();
18+
19+
const onSubmit = useCallback(async (e) => {
20+
e.preventDefault();
21+
const { password } = formData.current;
22+
setLoading(true);
23+
24+
// Send reset password request
25+
console.log(password, recoveryCode);
26+
27+
history.push('/login');
28+
}, [history, recoveryCode]);
29+
30+
const confirmPassword = useCallback(
31+
({ value }) => value === formData.current.password,
32+
[]
33+
);
34+
35+
return (
36+
<form onSubmit={onSubmit}>
37+
<Form formData={formData.current} disabled={loading}>
38+
<Item
39+
dataField={'password'}
40+
editorType={'dxTextBox'}
41+
editorOptions={passwordEditorOptions}
42+
>
43+
<RequiredRule message="Password is required" />
44+
<Label visible={false} />
45+
</Item>
46+
<Item
47+
dataField={'confirmedPassword'}
48+
editorType={'dxTextBox'}
49+
editorOptions={confirmedPasswordEditorOptions}
50+
>
51+
<RequiredRule message="Password is required" />
52+
<CustomRule
53+
message={'Passwords do not match'}
54+
validationCallback={confirmPassword}
55+
/>
56+
<Label visible={false} />
57+
</Item>
58+
<ButtonItem>
59+
<ButtonOptions
60+
width={'100%'}
61+
type={'default'}
62+
useSubmitBehavior={true}
63+
>
64+
<span className="dx-button-text">
65+
{
66+
loading
67+
? <LoadIndicator width={'24px'} height={'24px'} visible={true} />
68+
: 'Continue'
69+
}
70+
</span>
71+
</ButtonOptions>
72+
</ButtonItem>
73+
</Form>
74+
</form>
75+
);
76+
}
77+
78+
const passwordEditorOptions = { stylingMode: 'filled', placeholder: 'Password', mode: 'password' };
79+
const confirmedPasswordEditorOptions = { stylingMode: 'filled', placeholder: 'Confirm Password', mode: 'password' };

packages/devextreme-cli/templates/react/application/src/components/create-account-form/create-account-form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function (props) {
2929
}, [history]);
3030

3131
const confirmPassword = useCallback(
32-
({ value }) => value === formData.current.password ? true : false,
32+
({ value }) => value === formData.current.password,
3333
[]
3434
);
3535

packages/devextreme-cli/templates/react/application/src/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export { default as Footer } from './footer/footer';
33
export { default as LoginForm } from './login-form/login-form';
44
export { default as ResetPasswordForm } from './reset-password-form/reset-password-form';
55
export { default as CreateAccountForm } from './create-account-form/create-account-form';
6+
export { default as ChangePasswordForm } from './change-password-form/change-password-form';
67
export { default as SideNavigationMenu } from './side-navigation-menu/side-navigation-menu';
17.2 KB
Loading
-14 Bytes
Loading
11.1 KB
Loading
-10 Bytes
Loading
10.7 KB
Loading
-1 Bytes
Loading

0 commit comments

Comments
 (0)