Skip to content

Commit fdcd657

Browse files
committed
feat: confirm change email logic
1 parent b0d5534 commit fdcd657

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/containers/etc/EmailChange.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useApolloClient } from '@apollo/react-hooks';
99
import styled from 'styled-components';
1010
import { toast } from 'react-toastify';
1111
import SpinnerBlock from '../../components/common/SpinnerBlock';
12+
import usePopup from '../../lib/hooks/usePopup';
1213

1314
const mapStateToProps = (state: RootState) => ({});
1415
const mapDispatchToProps = {};
@@ -26,7 +27,9 @@ const { useEffect, useCallback } = React;
2627
const EmailChange: React.FC<EmailChangeProps> = ({ location, history }) => {
2728
const query = qs.parse(location.search, { ignoreQueryPrefix: true });
2829
const client = useApolloClient();
29-
useCallback(async () => {
30+
const popup = usePopup();
31+
32+
const processChangeEmail = useCallback(async () => {
3033
try {
3134
await client.mutate({
3235
mutation: CONFIRM_CHANGE_EMAIL,
@@ -36,19 +39,24 @@ const EmailChange: React.FC<EmailChangeProps> = ({ location, history }) => {
3639
});
3740

3841
history.replace('/setting');
42+
popup.open({
43+
title: '성공',
44+
message: '이메일 변경이 완료 되었습니다.',
45+
});
3946
} catch (e) {
4047
toast.error('잘못된 접근입니다.');
4148
history.replace('/');
4249
}
43-
}, [client, history, query.code]);
50+
}, [client, history, popup, query.code]);
4451

4552
useEffect(() => {
4653
if (!query.code) {
4754
// TODO: show 404
4855
toast.error('잘못된 접근입니다.');
4956
history.replace('/');
5057
}
51-
}, [history, location.search, query.code]);
58+
processChangeEmail();
59+
}, [history, location.search, processChangeEmail, query.code]);
5260

5361
return (
5462
<Fullscreen>

src/containers/setting/hooks/useChangeEmail.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { useMutation } from '@apollo/react-hooks';
22
import gql from 'graphql-tag';
33
import { useCallback } from 'react';
44

5-
const CHANGE_EMAIL = gql`
6-
mutation ChangeEmail($email: String!) {
7-
changeEmail(email: $email)
5+
const TRY_CHANGE_EMAIL = gql`
6+
mutation TRY_CHANGE_EMAIL($email: String!) {
7+
tryChangeEmail(email: $email)
88
}
99
`;
1010

1111
export default function useChangeEmail() {
12-
const [changeEmail, { called }] = useMutation(CHANGE_EMAIL);
12+
const [changeEmail, { called }] = useMutation(TRY_CHANGE_EMAIL);
1313
const change = useCallback(
1414
(email: string) => {
1515
return changeEmail({

src/lib/graphql/user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ export const ACCEPT_INTEGRATION = gql`
171171
`;
172172

173173
export const CONFIRM_CHANGE_EMAIL = gql`
174-
mutation ConfirmChangeEmail($email: String!) {
175-
confirm_change_email(email: $email)
174+
mutation ConfirmChangeEmail($code: String!) {
175+
confirmChangeEmail(code: $code)
176176
}
177177
`;
178178

0 commit comments

Comments
 (0)