|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
|
import { Button, Checkbox, Form, Input, Row, Typography, App } from 'antd';
|
|
|
|
|
import { Button, Space, Form, Input, Row, Typography, App } from 'antd';
|
|
|
|
|
import { useStore } from '@/stores/StoreContext.js';
|
|
|
|
|
|
|
|
|
|
const { Title } = Typography;
|
|
|
|
@ -8,29 +7,23 @@ function ChangePassword() {
|
|
|
|
|
|
|
|
|
|
const { authStore } = useStore();
|
|
|
|
|
const { notification } = App.useApp();
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
|
|
|
|
|
const onFinish = (values) => {
|
|
|
|
|
authStore.valdateUserPassword(values.username, values.password)
|
|
|
|
|
.then((userId) => {
|
|
|
|
|
authStore.fetchUserDetail(userId)
|
|
|
|
|
.then((user) => {
|
|
|
|
|
// navigate(-1) is equivalent to hitting the back button.
|
|
|
|
|
navigate("/reservation/newest");
|
|
|
|
|
})
|
|
|
|
|
.catch(ex => {
|
|
|
|
|
notification.error({
|
|
|
|
|
message: `Notification`,
|
|
|
|
|
description: ex.message,
|
|
|
|
|
placement: 'top',
|
|
|
|
|
duration: 4,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
console.info(values);
|
|
|
|
|
authStore.changeUserPassword(values.currentPassword, values.newPassword)
|
|
|
|
|
.then(() => {
|
|
|
|
|
notification.success({
|
|
|
|
|
message: `Notification`,
|
|
|
|
|
description: 'Your password has been successfully updated.',
|
|
|
|
|
placement: 'top',
|
|
|
|
|
duration: 4,
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(ex => {
|
|
|
|
|
.catch(() => {
|
|
|
|
|
notification.error({
|
|
|
|
|
message: `Notification`,
|
|
|
|
|
description: ex.message,
|
|
|
|
|
description: 'Failed to change password. Please try again.',
|
|
|
|
|
placement: 'top',
|
|
|
|
|
duration: 4,
|
|
|
|
|
});
|
|
|
|
@ -39,36 +32,32 @@ function ChangePassword() {
|
|
|
|
|
|
|
|
|
|
const onFinishFailed = (errorInfo) => {
|
|
|
|
|
console.log('Failed:', errorInfo);
|
|
|
|
|
// form.resetFields();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Row justify="center" align="middle" style={{ minHeight: 500 }}>
|
|
|
|
|
<Title level={3}>Change your password</Title>
|
|
|
|
|
<>
|
|
|
|
|
<Row justify="center" align="middle" style={{ minHeight: 500 }}>
|
|
|
|
|
<Form
|
|
|
|
|
name="basic"
|
|
|
|
|
labelCol={{
|
|
|
|
|
span: 8,
|
|
|
|
|
}}
|
|
|
|
|
wrapperCol={{
|
|
|
|
|
span: 16,
|
|
|
|
|
}}
|
|
|
|
|
form={form}
|
|
|
|
|
layout="vertical"
|
|
|
|
|
size="large"
|
|
|
|
|
style={{
|
|
|
|
|
maxWidth: 600,
|
|
|
|
|
}}
|
|
|
|
|
initialValues={{
|
|
|
|
|
remember: true,
|
|
|
|
|
}}
|
|
|
|
|
onFinish={onFinish}
|
|
|
|
|
onFinishFailed={onFinishFailed}
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
>
|
|
|
|
|
<Form.Item><Title level={3}>Change your password</Title></Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
label="Current password"
|
|
|
|
|
name="username"
|
|
|
|
|
name="currentPassword"
|
|
|
|
|
rules={[
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: 'Please input your username!',
|
|
|
|
|
message: 'Please input your password!',
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
>
|
|
|
|
@ -76,7 +65,7 @@ function ChangePassword() {
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
label="New password"
|
|
|
|
|
name="password"
|
|
|
|
|
name="newPassword"
|
|
|
|
|
rules={[
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
@ -88,38 +77,29 @@ function ChangePassword() {
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
label="Reenter password"
|
|
|
|
|
name="password"
|
|
|
|
|
name="reenterPassword"
|
|
|
|
|
rules={[
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: 'Please input your password!',
|
|
|
|
|
message: 'Please reenter your password!',
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
>
|
|
|
|
|
<Input.Password />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
wrapperCol={{
|
|
|
|
|
offset: 8,
|
|
|
|
|
span: 16,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<Space size="middle">
|
|
|
|
|
<Button type="primary" htmlType="submit">
|
|
|
|
|
Save
|
|
|
|
|
</Button>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
wrapperCol={{
|
|
|
|
|
offset: 8,
|
|
|
|
|
span: 16,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Button htmlType="submit">
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
</Space>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
|
|
|
|
</Row>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|