-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestorePasswordForm.tsx
142 lines (120 loc) · 4.1 KB
/
RestorePasswordForm.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import "./assets/forms.scss";
import { stringifyQuery } from "@getpack/core";
import { AppForm } from "@getpack/core-components";
import { I18nContextConsumer } from "@getpack/core-locales";
import { memoize } from "lodash-es";
import React from "react";
import { Route } from "react-router";
import { Link } from "react-router-dom";
import { TextFormField } from "../form/TextFormField";
import { InputTypes } from "../ui/TextField";
export interface RestorePasswordFormValues {
code: string;
password: string;
confirmPassword?: string;
}
type RestorePasswordFormErrors = {
[P in keyof RestorePasswordFormValues]?: null | string | boolean
};
interface Props {
phone: string;
submitError?: Error;
initialValues?: Partial<RestorePasswordFormValues>;
onResendClick: () => void;
submitting: boolean;
onSubmit: (values: RestorePasswordFormValues) => void;
}
const validateForm = memoize(ctx => (values: RestorePasswordFormValues) => {
const errors: RestorePasswordFormErrors = {};
if (!values.code) {
errors.code = ctx.RegisterVerificationFormValidCode;
}
if (values.password !== values.confirmPassword) {
errors.confirmPassword = ctx.RegisterCompleteFormValidConfirmPassword;
}
return errors;
});
export function RestorePasswordForm(props: Props) {
const { submitting } = props;
return (
<I18nContextConsumer>
{ctx => (
<AppForm
onSubmit={props.onSubmit}
validate={validateForm(ctx)}
keepDirtyOnReinitialize={true}
render={({ handleSubmit }) => (
<form
className="d-flex flex-column auth-form"
onSubmit={handleSubmit}
>
<span className="info-content">
<span>{ctx.RegisterVerificationFormEnterTheCode}</span>
<span className="info-number">{props.phone}</span>
</span>
<TextFormField
name="code"
className="mb-3"
disabled={submitting}
label={ctx.RegisterVerificationFormVerificationCode}
/>
<TextFormField
name="password"
className="mb-3"
disabled={submitting}
type={InputTypes.Password}
label={ctx.RegisterCompleteFormEnterNewPassword}
/>
<TextFormField
className="mb-3"
disabled={submitting}
name="confirmPassword"
type={InputTypes.Password}
label={ctx.RegisterCompleteFormConfirmPassword}
/>
<button
type="submit"
disabled={submitting}
className="btn btn-lg btn-secondary mb-5 text-uppercase"
>
{ctx.GenericContinue}
</button>
<span className="help-content text-sm-left">
<div className="d-flex flex-column flex-sm-row align-items-center">
<span className="help-text">
{ctx.RegisterVerificationFormDidNotSms}
</span>
<button
type="button"
disabled={submitting}
onClick={props.onResendClick}
className="btn btn-sm btn-link help-link"
>
{ctx.RegisterVerificationFormResend}
</button>
</div>
<Route
render={({ location }) => (
<Link
to={{
...location,
hash: "forgot-password",
search: stringifyQuery({
reset: true,
phone: props.phone,
}),
}}
className="help-link"
>
{ctx.RegisterVerificationFormUpdateMobileNumber}
</Link>
)}
/>
</span>
</form>
)}
/>
)}
</I18nContextConsumer>
);
}