Skip to content

Commit b0d5534

Browse files
committed
feat: Setup email-change page
1 parent a5b4781 commit b0d5534

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

src/App.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ const EmailLoginPage = loadable(
2828
() => import('./pages/EmailLoginPage'),
2929
loadableConfig,
3030
);
31+
const EmailChangePage = loadable(
32+
() => import('./pages/EmailChangePage'),
33+
loadableConfig,
34+
);
35+
3136
const WritePage = loadable(() => import('./pages/WritePage'));
3237
const SearchPage = loadable(() => import('./pages/SearchPage'), loadableConfig);
3338
const SavesPage = loadable(() => import('./pages/SavesPage'), loadableConfig);
@@ -77,6 +82,7 @@ const App: React.FC<AppProps> = (props) => {
7782
<Route path="/@:username" component={VelogPage} />
7883
{/* <Route path="/@:username/:urlSlug" component={PostPage} /> */}
7984
<Route path="/email-login" component={EmailLoginPage} />
85+
<Route path="/email-change" component={EmailChangePage} />
8086
<Route path="/write" component={WritePage} />
8187
<Route path="/search" component={SearchPage} />
8288
<Route path="/saves" component={SavesPage} />

src/components/setting/SettingEmailRow.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function SettingEmailRow({
2323
const onSubmit = async (e: React.FormEvent) => {
2424
e.preventDefault();
2525
//! TODO: 이메일 형식으로 입력하지 않을 경우 처리
26+
//! TODO: 같은 이메일인 경우 처리
27+
//! TODO: 이메일 중복 체크
2628
await onChangeEmail(value);
2729
setEdit(false);
2830
};

src/containers/etc/EmailChange.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import * as React from 'react';
2+
import { connect } from 'react-redux';
3+
import { withRouter, RouteComponentProps } from 'react-router';
4+
import qs from 'qs';
5+
6+
import { CONFIRM_CHANGE_EMAIL } from '../../lib/graphql/user';
7+
import { RootState } from '../../modules';
8+
import { useApolloClient } from '@apollo/react-hooks';
9+
import styled from 'styled-components';
10+
import { toast } from 'react-toastify';
11+
import SpinnerBlock from '../../components/common/SpinnerBlock';
12+
13+
const mapStateToProps = (state: RootState) => ({});
14+
const mapDispatchToProps = {};
15+
16+
interface OwnProps {}
17+
type StateProps = ReturnType<typeof mapStateToProps>;
18+
type DispatchProps = typeof mapDispatchToProps;
19+
export type EmailChangeProps = OwnProps &
20+
StateProps &
21+
DispatchProps &
22+
RouteComponentProps;
23+
24+
const { useEffect, useCallback } = React;
25+
26+
const EmailChange: React.FC<EmailChangeProps> = ({ location, history }) => {
27+
const query = qs.parse(location.search, { ignoreQueryPrefix: true });
28+
const client = useApolloClient();
29+
useCallback(async () => {
30+
try {
31+
await client.mutate({
32+
mutation: CONFIRM_CHANGE_EMAIL,
33+
variables: {
34+
code: query.code,
35+
},
36+
});
37+
38+
history.replace('/setting');
39+
} catch (e) {
40+
toast.error('잘못된 접근입니다.');
41+
history.replace('/');
42+
}
43+
}, [client, history, query.code]);
44+
45+
useEffect(() => {
46+
if (!query.code) {
47+
// TODO: show 404
48+
toast.error('잘못된 접근입니다.');
49+
history.replace('/');
50+
}
51+
}, [history, location.search, query.code]);
52+
53+
return (
54+
<Fullscreen>
55+
<SpinnerBlock />
56+
</Fullscreen>
57+
);
58+
};
59+
60+
const Fullscreen = styled.div`
61+
width: 100%;
62+
height: 100%;
63+
display: flex;
64+
align-items: center;
65+
justify-content: center;
66+
`;
67+
68+
export default connect<StateProps, DispatchProps, OwnProps, RootState>(
69+
mapStateToProps,
70+
mapDispatchToProps,
71+
)(withRouter(EmailChange));

src/lib/graphql/user.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ export const ACCEPT_INTEGRATION = gql`
170170
}
171171
`;
172172

173+
export const CONFIRM_CHANGE_EMAIL = gql`
174+
mutation ConfirmChangeEmail($email: String!) {
175+
confirm_change_email(email: $email)
176+
}
177+
`;
178+
173179
export type AcceptIntegrationResponse = {
174180
acceptIntegration: string;
175181
};

src/pages/EmailChangePage.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as React from 'react';
2+
import EmailChange from '../containers/etc/EmailChange';
3+
4+
const EmailChangePage: React.FC<{}> = (props) => {
5+
return <EmailChange />;
6+
};
7+
8+
export default EmailChangePage;

0 commit comments

Comments
 (0)