|
1 | 1 | import gql from 'graphql-tag';
|
2 |
| -import Link from 'next/link'; |
3 | 2 | import { withRouter, NextRouter } from 'next/router';
|
4 |
| -import * as React from 'react'; |
5 |
| -import { graphql } from 'react-apollo'; |
| 3 | +import React, { useState } from 'react'; |
6 | 4 |
|
7 |
| -import { UserLoginErrorCode } from '../src/helpers/user-login-error-code'; |
8 |
| -import { withDataAndRouter, IWithDataContext } from '../src/helpers/with-data'; |
| 5 | +import { withDataAndRouter } from '../src/helpers/with-data'; |
9 | 6 | import { BlankLayout } from '../src/layouts/blank-layout';
|
10 | 7 |
|
11 |
| -interface IForgotPageProps extends IForgotPageOwnProps { |
12 |
| - registerUser: (id: string, password: string) => void; |
13 |
| -} |
14 |
| - |
15 |
| -interface IForgotPageOwnProps { |
| 8 | +export interface IForgotPageProps { |
16 | 9 | router: NextRouter; // { how: UserLoginErrorCode }
|
17 | 10 | }
|
18 | 11 |
|
19 |
| -const ForgotPageView: React.SFC<IForgotPageProps> = ({ registerUser, router }) => { |
20 |
| - let message: string | undefined; |
21 |
| - switch (router && router.query.how) { |
22 |
| - case 'up': |
23 |
| - message = 'You have to be logged in to vote.'; |
24 |
| - break; |
25 |
| - default: |
26 |
| - message = undefined; |
27 |
| - } |
28 |
| - |
29 |
| - let user = ''; |
30 |
| - let pass = ''; |
31 |
| - const onUserChange = (e): void => { |
32 |
| - user = e.target.value; |
33 |
| - }; |
34 |
| - const onPasswordChange = (e): void => { |
35 |
| - pass = e.target.value; |
36 |
| - }; |
| 12 | +function ForgotPageView(props: IForgotPageProps): JSX.Element { |
| 13 | + const [username, setUsername] = useState<string>(''); |
37 | 14 |
|
38 | 15 | return (
|
39 | 16 | <BlankLayout>
|
40 |
| - {message && <div>{message}</div>} |
41 |
| - <b>Login</b> |
| 17 | + <b>Reset your password</b> |
42 | 18 | <br />
|
43 | 19 | <br />
|
44 |
| - <form method="post" action="/login" style={{ marginBottom: '1em' }}> |
45 |
| - <input type="hidden" name="goto" value="news" /> |
46 |
| - <table style={{ border: '0px' }}> |
47 |
| - <tbody> |
48 |
| - <tr> |
49 |
| - <td>username:</td> |
50 |
| - <td> |
51 |
| - <input |
52 |
| - type="text" |
53 |
| - name="username" |
54 |
| - size={20} |
55 |
| - autoCorrect="off" |
56 |
| - spellCheck={false} |
57 |
| - autoCapitalize="off" |
58 |
| - autoFocus |
59 |
| - /> |
60 |
| - </td> |
61 |
| - </tr> |
62 |
| - <tr> |
63 |
| - <td>password:</td> |
64 |
| - <td> |
65 |
| - <input type="password" name="password" size={20} /> |
66 |
| - </td> |
67 |
| - </tr> |
68 |
| - </tbody> |
69 |
| - </table> |
| 20 | + <form method="post" action="/x"> |
| 21 | + <input type="hidden" name="fnid" value="SW3mxENlH7rdjgxwWaobR5" /> |
| 22 | + <input type="hidden" name="fnop" value="forgot-password" /> |
| 23 | + username:{' '} |
| 24 | + <input type="text" name="s" size={20} onChange={(e): void => setUsername(e.target.value)} /> |
70 | 25 | <br />
|
71 |
| - <input type="submit" value="login" /> |
72 |
| - </form> |
73 |
| - <Link href="/forgot"> |
74 |
| - <a>Forgot your password?</a> |
75 |
| - </Link> |
76 |
| - <br /> |
77 |
| - <br /> |
78 |
| - <b>Create Account</b> |
79 |
| - <br /> |
80 |
| - <br /> |
81 |
| - <form |
82 |
| - method="post" |
83 |
| - action="/login" |
84 |
| - /* onSubmit={e => e.preventDefault()} */ style={{ marginBottom: '1em' }} |
85 |
| - > |
86 |
| - <input type="hidden" name="goto" value={`user?id=${user}`} /> |
87 |
| - <input type="hidden" name="creating" value="true" /> |
88 |
| - <table style={{ border: '0px' }}> |
89 |
| - <tbody> |
90 |
| - <tr> |
91 |
| - <td>username:</td> |
92 |
| - <td> |
93 |
| - <input |
94 |
| - type="text" |
95 |
| - name="username" |
96 |
| - onChange={onUserChange} |
97 |
| - size={20} |
98 |
| - autoCorrect="off" |
99 |
| - spellCheck={false} |
100 |
| - autoCapitalize="off" |
101 |
| - /> |
102 |
| - </td> |
103 |
| - </tr> |
104 |
| - <tr> |
105 |
| - <td>password:</td> |
106 |
| - <td> |
107 |
| - <input type="password" name="password" onChange={onPasswordChange} size={20} /> |
108 |
| - </td> |
109 |
| - </tr> |
110 |
| - </tbody> |
111 |
| - </table> |
112 | 26 | <br />
|
113 |
| - <input |
114 |
| - type="submit" |
115 |
| - value="create account" |
116 |
| - onClick={(): void => registerUser(user, pass)} |
117 |
| - /> |
| 27 | + <input type="submit" value="Send reset email" /> |
118 | 28 | </form>
|
119 | 29 | </BlankLayout>
|
120 | 30 | );
|
121 |
| -}; |
122 |
| - |
123 |
| -const registerUserMutation = gql` |
124 |
| - mutation RegisterUser($id: String!, $password: String!) { |
125 |
| - registerUser(id: $id, password: $password) { |
126 |
| - id |
127 |
| - karma |
128 |
| - } |
129 |
| - } |
130 |
| -`; |
131 |
| - |
132 |
| -const ForgotPageWithGraphql = graphql<IForgotPageOwnProps, {}, {}, IForgotPageProps>( |
133 |
| - registerUserMutation, |
134 |
| - { |
135 |
| - props: ({ ownProps, mutate }) => ({ |
136 |
| - ...ownProps, |
137 |
| - registerUser: (id: string, password: string): Promise<any> => { |
138 |
| - return ( |
139 |
| - mutate!({ |
140 |
| - variables: { id, password }, |
141 |
| - }) |
142 |
| - // .then(() => Router.push(`/login?id=${id}&password=${password}`)) |
143 |
| - .catch((reason) => console.error(reason)) |
144 |
| - ); |
145 |
| - }, |
146 |
| - router: ownProps.router, |
147 |
| - }), |
148 |
| - } |
149 |
| -)(ForgotPageView); |
| 31 | +} |
150 | 32 |
|
151 | 33 | export const ForgotPage = withDataAndRouter(
|
152 |
| - withRouter((props) => <ForgotPageWithGraphql router={props.router} />) |
| 34 | + withRouter((props) => <ForgotPageView router={props.router} />) |
153 | 35 | );
|
154 | 36 |
|
155 | 37 | export default ForgotPage;
|
0 commit comments