Added sagas + pages for password reset. WIP BOD-165
This commit is contained in:
@@ -3,11 +3,14 @@ import { Button, Form, Input, Typography } from "antd";
|
||||
import React from "react";
|
||||
import { useApolloClient } from "react-apollo";
|
||||
import { connect } from "react-redux";
|
||||
import { Redirect } from "react-router-dom";
|
||||
import { Redirect, Link } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import ImEXOnlineLogo from "../../assets/logo240.png";
|
||||
import { UPSERT_USER } from "../../graphql/user.queries";
|
||||
import { emailSignInStart } from "../../redux/user/user.actions";
|
||||
import {
|
||||
emailSignInStart,
|
||||
sendPasswordReset,
|
||||
} from "../../redux/user/user.actions";
|
||||
import {
|
||||
selectCurrentUser,
|
||||
selectSignInError,
|
||||
@@ -24,12 +27,14 @@ const mapStateToProps = createStructuredSelector({
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
emailSignInStart: (email, password) =>
|
||||
dispatch(emailSignInStart({ email, password })),
|
||||
sendPasswordReset: (email) => dispatch(sendPasswordReset(email)),
|
||||
});
|
||||
|
||||
export function SignInComponent({
|
||||
emailSignInStart,
|
||||
currentUser,
|
||||
signInError,
|
||||
sendPasswordReset,
|
||||
}) {
|
||||
const apolloClient = useApolloClient();
|
||||
const { t } = useTranslation();
|
||||
@@ -39,6 +44,7 @@ export function SignInComponent({
|
||||
};
|
||||
const [form] = Form.useForm();
|
||||
|
||||
//TODO - may be able to run this only on new user creation.
|
||||
if (currentUser.authorized === true) {
|
||||
apolloClient
|
||||
.mutate({
|
||||
@@ -55,6 +61,7 @@ export function SignInComponent({
|
||||
}
|
||||
|
||||
if (currentUser.authorized === true) return <Redirect to='/manage' />;
|
||||
|
||||
return (
|
||||
<div className='login-container'>
|
||||
<div className='login-logo-container'>
|
||||
@@ -90,6 +97,9 @@ export function SignInComponent({
|
||||
{t("general.actions.login")}
|
||||
</Button>
|
||||
</Form>
|
||||
<Link to={"/resetpassword"}>
|
||||
<Button>{t("general.actions.resetpassword")}</Button>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import {
|
||||
sendPasswordReset,
|
||||
validatePasswordResetStart,
|
||||
} from "../../redux/user/user.actions";
|
||||
import queryString from "query-string";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import { Input, Form, Button, Result } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import EmailFormItemComponent from "../form-items-formatted/email-form-item.component";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { selectPasswordReset } from "../../redux/user/user.selectors";
|
||||
import AlertComponent from "../alert/alert.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
passwordReset: selectPasswordReset,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
sendPasswordReset: (email) => dispatch(sendPasswordReset(email)),
|
||||
});
|
||||
|
||||
export function UserRequestResetPw({ passwordReset, sendPasswordReset }) {
|
||||
const handleFinish = (values) => {
|
||||
try {
|
||||
sendPasswordReset(values.email);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
const { t } = useTranslation();
|
||||
if (passwordReset.success)
|
||||
return (
|
||||
<Result
|
||||
status='success'
|
||||
title={t("general.labels.passwordresetsuccess")}
|
||||
subTitle={t("general.labels.passwordresetsuccess_sub")}
|
||||
extra={[
|
||||
<Button onClick={() => sendPasswordReset(passwordReset.email)}>
|
||||
{t("general.labels.sendagain")}
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Form onFinish={handleFinish}>
|
||||
<Form.Item
|
||||
label={t("general.labels.email")}
|
||||
name='email'
|
||||
rules={[
|
||||
{
|
||||
type: "email",
|
||||
required: true,
|
||||
message: t("general.validation.required"),
|
||||
},
|
||||
]}>
|
||||
<EmailFormItemComponent />
|
||||
</Form.Item>
|
||||
{passwordReset.error ? (
|
||||
<AlertComponent message={passwordReset.error} type='warning' />
|
||||
) : null}
|
||||
<Button htmlType='submit'>{t("general.actions.submit")}</Button>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(UserRequestResetPw);
|
||||
@@ -0,0 +1,85 @@
|
||||
import { LockOutlined } from "@ant-design/icons";
|
||||
import { Button, Form, Input } from "antd";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { validatePasswordResetStart } from "../../redux/user/user.actions";
|
||||
import { selectPasswordReset } from "../../redux/user/user.selectors";
|
||||
import AlertComponent from "../alert/alert.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
passwordReset: selectPasswordReset,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
validatePasswordReset: (emailAndPin) =>
|
||||
dispatch(validatePasswordResetStart(emailAndPin)),
|
||||
});
|
||||
|
||||
export function UserValidatePwReset({
|
||||
passwordReset,
|
||||
validatePasswordReset,
|
||||
oobCode,
|
||||
}) {
|
||||
console.log("UserValidatePwReset -> oobCode", oobCode);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleFinish = (values) => {
|
||||
validatePasswordReset({ code: oobCode, password: values.password });
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Form onFinish={handleFinish}>
|
||||
<Form.Item
|
||||
label={t("general.labels.password")}
|
||||
name='password'
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: t("general.validation.required"),
|
||||
},
|
||||
]}>
|
||||
<Input
|
||||
prefix={<LockOutlined />}
|
||||
type='password'
|
||||
placeholder={t("general.labels.password")}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t("general.labels.confirmpassword")}
|
||||
name='password-confirm'
|
||||
dependencies={["password"]}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: t("general.validation.required"),
|
||||
},
|
||||
({ getFieldValue }) => ({
|
||||
validator(rule, value) {
|
||||
if (!value || getFieldValue("password") === value) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.reject(t("general.labels.passwordsdonotmatch"));
|
||||
},
|
||||
}),
|
||||
]}>
|
||||
<Input
|
||||
prefix={<LockOutlined />}
|
||||
type='password'
|
||||
placeholder={t("general.labels.password")}
|
||||
/>
|
||||
</Form.Item>
|
||||
{passwordReset.error ? (
|
||||
<AlertComponent message={passwordReset.error} type='warning' />
|
||||
) : null}
|
||||
<Button htmlType='submit'>{t("general.actions.submit")}</Button>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(UserValidatePwReset);
|
||||
Reference in New Issue
Block a user