Skip to content

Commit c523e5e

Browse files
committed
fixup! change Forgot Password to Component
1 parent aa64fde commit c523e5e

File tree

5 files changed

+42
-22
lines changed

5 files changed

+42
-22
lines changed

src/app/apiFetch/User.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/* tslint:disable:no-console*/
2-
import { HeadReqType, headResponseWrapper, jsonResponseWrapper } from 'app/apiFetch/utils';
2+
import {
3+
HeadReqType,
4+
headResponseWrapper,
5+
jsonResponseWrapper,
6+
textResponseWrapper,
7+
} from 'app/apiFetch/utils';
38
import * as UserInterfaces from 'app/types/User';
49
import { API_BASE_URL } from '../../config/config';
510

@@ -140,7 +145,7 @@ export const changeUserPassword = (body: UserInterfaces.ChangeUserPassword) => {
140145
method: 'POST',
141146
})
142147
.then((response) => {
143-
return jsonResponseWrapper(response);
148+
return textResponseWrapper(response);
144149
})
145150
.then((data) => {
146151
return data;

src/app/apiFetch/utils/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ export function textResponseWrapper(response: any) {
9090
case 302:
9191
case 409:
9292
case 401:
93+
case 404:
94+
case 403:
9395
case 500:
9496
case 403:
97+
case 501:
9598
error = 'Oops! Something went wrong.';
9699
type = resType.ERROR;
97100
}

src/app/components/Authentication/ForgotPassword.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1+
import { Routes } from 'app/routes';
12
import * as styles from 'app/styles/Authentication.module.css';
3+
import * as registerStyles from 'app/styles/Register.module.css';
4+
import { AuthType } from 'app/types/Authentication';
5+
import * as LoginInterfaces from 'app/types/Authentication/Login';
26
import classnames from 'classnames';
37
import * as React from 'react';
48
import { Col, Row } from 'react-bootstrap';
5-
import * as registerStyles from 'app/styles/Register.module.css';
6-
import { Routes } from 'app/routes';
7-
import * as LoginInterfaces from 'app/types/Authentication/Login';
8-
import { AuthType } from 'app/types/Authentication';
99

1010
// tslint:disable-next-line: variable-name
1111
const ForgotPassword = (props: LoginInterfaces.ForgotPasswordProps) => {
1212
const forgotPasswordRef = React.createRef<HTMLFormElement>();
13-
const [username, setUsername] = React.useState('');
1413

1514
const handleForgotPassword = (event: React.FormEvent<HTMLFormElement>) => {
1615
const form = forgotPasswordRef.current;
1716

1817
event.preventDefault();
1918
if (form) {
2019
if (form.checkValidity()) {
21-
props.forgotPassword(username);
20+
props.forgotPassword(props.username);
2221
}
2322
form.classList.add('was-validated');
2423
}
@@ -62,8 +61,8 @@ const ForgotPassword = (props: LoginInterfaces.ForgotPasswordProps) => {
6261
id="validationUsername"
6362
aria-describedby="inputGroupPrepend"
6463
required
65-
value={username}
66-
onChange={(e) => setUsername(e.target.value)}
64+
value={props.username}
65+
onChange={(e) => props.setUsername(e.target.value)}
6766
/>
6867
<div className={classnames('invalid-feedback', styles['login-error'])}>
6968
{' '}

src/app/components/Authentication/Login.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { faSpinner } from '@fortawesome/free-solid-svg-icons';
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
33
import { API_BASE_URL } from 'app/../config/config';
44
import ForgotPassword from 'app/components/Authentication/ForgotPassword';
5+
import PopUpMenu from 'app/components/PopUpMenu';
56
import { Routes } from 'app/routes';
67
import * as styles from 'app/styles/Authentication.module.css';
78
import * as registerStyles from 'app/styles/Register.module.css';
@@ -65,7 +66,7 @@ export class Login extends React.Component<LoginInterfaces.Props, LoginInterface
6566
if (isLoggedIn) {
6667
return <Redirect to={Routes.ROOT} />;
6768
}
68-
if (this.props.errorMessage === ' ' && this.state.isForgotPasswordOpen) {
69+
if (errorMessage === ' ' && isForgotPasswordOpen) {
6970
this.setState({
7071
isForgotPasswordOpen: false,
7172
});
@@ -247,21 +248,31 @@ export class Login extends React.Component<LoginInterfaces.Props, LoginInterface
247248
</div>
248249
</Col>
249250
</Row>
251+
<PopUpMenu />
250252
</div>
251253
);
252254
}
253255
return (
254-
<ForgotPassword
255-
updateErrorMessage={updateErrorMessage}
256-
handleSelectPanel={this.props.handleSelectPanel}
257-
errorMessage={this.props.errorMessage}
258-
forgotPassword={this.props.forgotPassword}
259-
closeForgotPassword={() =>
260-
this.setState({
261-
isForgotPasswordOpen: false,
262-
})
263-
}
264-
/>
256+
<div>
257+
<ForgotPassword
258+
updateErrorMessage={updateErrorMessage}
259+
handleSelectPanel={this.props.handleSelectPanel}
260+
errorMessage={this.props.errorMessage}
261+
forgotPassword={this.props.forgotPassword}
262+
username={username}
263+
setUsername={(newUsername) =>
264+
this.setState({
265+
username: newUsername,
266+
})
267+
}
268+
closeForgotPassword={() =>
269+
this.setState({
270+
isForgotPasswordOpen: false,
271+
})
272+
}
273+
/>
274+
<PopUpMenu />
275+
</div>
265276
);
266277
}
267278

src/app/types/Authentication/Login.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export interface ForgotPasswordProps {
2626
handleSelectPanel: (authType: AuthType) => void;
2727
closeForgotPassword: () => void;
2828
errorMessage: string;
29+
username: string;
30+
setUsername: (username: string) => void;
2931
forgotPassword: (email: string) => void;
3032
}
3133

0 commit comments

Comments
 (0)