-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecoveryDialog.re
75 lines (69 loc) · 2.29 KB
/
RecoveryDialog.re
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
open FormData;
let str = ReasonReact.string;
[@react.component]
let make = (~open_, ~onClose) => {
let theme = Mui_Theme.useTheme();
let (state, dispatch) = UserUtils.useReducerSafe(reducer, initState);
let {password, status} = state;
let identity = UserIdentity.Context.useIdentityContext();
let handleSetPassword = _ => {
dispatch(SubmitRequest);
identity.updateUser({"password": password} |> Utils.toJson)
|> Js.Promise.then_(_ => dispatch(SubmitSuccess) |> Js.Promise.resolve)
|> Js.Promise.catch(error => {
Js.log(error);
dispatch(SubmitError(UserUtils.errorToMessage(error)))
|> Js.Promise.resolve;
})
|> ignore;
};
<MaterialUi_Dialog
open_
onClose={(_, _) => onClose()}
scroll=`Body
classes=[PaperScrollBody(Styles.Dialog.root(theme))]>
<MaterialUi_DialogContent className=Styles.Dialog.dialogContent>
<MaterialUi_DialogTitle className=Styles.Dialog.title>
{str("Reset your password")}
</MaterialUi_DialogTitle>
<form
onSubmit={e => {
ReactEvent.Form.preventDefault(e);
handleSetPassword();
}}>
<MaterialUi_FormControl
fullWidth=true classes=[Root(Styles.Form.formElement(theme))]>
<MaterialUi_TextField
label={str("Password")}
type_="password"
value={`String(password)}
name="password"
fullWidth=true
required=true
disabled={status === Submitting}
onChange={e => {
let value = Utils.getInputValue(e);
dispatch(SetPassword(value));
}}
/>
</MaterialUi_FormControl>
<MaterialUi_FormControl
fullWidth=true className={Styles.Form.submitButton(theme)}>
<MaterialUi_Button
color=`Primary
disabled={status === Submitting}
variant=`Contained
type_="submit"
fullWidth=true>
{str("Reset password")}
</MaterialUi_Button>
</MaterialUi_FormControl>
{switch (status) {
| Error(message) => <ErrorMessage message />
| Success => str("Password has been updated.")
| _ => React.null
}}
</form>
</MaterialUi_DialogContent>
</MaterialUi_Dialog>;
};