Skip to content

Commit 111b450

Browse files
committed
Updated graphql mutations
1 parent 26eebfe commit 111b450

17 files changed

+288
-486
lines changed

pages/forgot.tsx

Lines changed: 14 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,37 @@
11
import gql from 'graphql-tag';
2-
import Link from 'next/link';
32
import { withRouter, NextRouter } from 'next/router';
4-
import * as React from 'react';
5-
import { graphql } from 'react-apollo';
3+
import React, { useState } from 'react';
64

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';
96
import { BlankLayout } from '../src/layouts/blank-layout';
107

11-
interface IForgotPageProps extends IForgotPageOwnProps {
12-
registerUser: (id: string, password: string) => void;
13-
}
14-
15-
interface IForgotPageOwnProps {
8+
export interface IForgotPageProps {
169
router: NextRouter; // { how: UserLoginErrorCode }
1710
}
1811

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>('');
3714

3815
return (
3916
<BlankLayout>
40-
{message && <div>{message}</div>}
41-
<b>Login</b>
17+
<b>Reset your password</b>
4218
<br />
4319
<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)} />
7025
<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>
11226
<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" />
11828
</form>
11929
</BlankLayout>
12030
);
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+
}
15032

15133
export const ForgotPage = withDataAndRouter(
152-
withRouter((props) => <ForgotPageWithGraphql router={props.router} />)
34+
withRouter((props) => <ForgotPageView router={props.router} />)
15335
);
15436

15537
export default ForgotPage;

0 commit comments

Comments
 (0)