Pass the errors directly to NewPasswordPage component
This commit is contained in:
parent
06e78acbf6
commit
3ee7ce5777
1 changed files with 2 additions and 10 deletions
|
@ -8,18 +8,12 @@ import NewPasswordPage, {
|
||||||
NewPasswordPageFormData
|
NewPasswordPageFormData
|
||||||
} from "../components/NewPasswordPage";
|
} from "../components/NewPasswordPage";
|
||||||
import { SetPasswordMutation } from "../mutations";
|
import { SetPasswordMutation } from "../mutations";
|
||||||
import {
|
import { SetPassword } from "../types/SetPassword";
|
||||||
SetPassword,
|
|
||||||
SetPassword_setPassword_errors
|
|
||||||
} from "../types/SetPassword";
|
|
||||||
import { NewPasswordUrlQueryParams } from "../urls";
|
import { NewPasswordUrlQueryParams } from "../urls";
|
||||||
|
|
||||||
const NewPassword: React.FC<RouteComponentProps> = ({ location }) => {
|
const NewPassword: React.FC<RouteComponentProps> = ({ location }) => {
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
const { loginByToken } = useUser();
|
const { loginByToken } = useUser();
|
||||||
const [errors, setErrors] = React.useState<
|
|
||||||
SetPassword_setPassword_errors[]
|
|
||||||
>();
|
|
||||||
|
|
||||||
const params: NewPasswordUrlQueryParams = parseQs(location.search.substr(1));
|
const params: NewPasswordUrlQueryParams = parseQs(location.search.substr(1));
|
||||||
|
|
||||||
|
@ -27,8 +21,6 @@ const NewPassword: React.FC<RouteComponentProps> = ({ location }) => {
|
||||||
if (data.setPassword.errors.length === 0) {
|
if (data.setPassword.errors.length === 0) {
|
||||||
loginByToken(data.setPassword.token, data.setPassword.user);
|
loginByToken(data.setPassword.token, data.setPassword.user);
|
||||||
navigate("/", true);
|
navigate("/", true);
|
||||||
} else {
|
|
||||||
setErrors(data.setPassword.errors);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -46,7 +38,7 @@ const NewPassword: React.FC<RouteComponentProps> = ({ location }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NewPasswordPage
|
<NewPasswordPage
|
||||||
errors={errors}
|
errors={setPasswordOpts.data?.setPassword.errors || []}
|
||||||
disabled={setPasswordOpts.loading}
|
disabled={setPasswordOpts.loading}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue