Skip to content

Commit a5b4781

Browse files
committed
feat: add email sending logic
1 parent e1979b9 commit a5b4781

File tree

6 files changed

+57
-6
lines changed

6 files changed

+57
-6
lines changed

src/components/setting/SettingEmailRow.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ import useInput from '../../lib/hooks/useInput';
44
import SettingInput from './SettingInput';
55
import styled from 'styled-components';
66
import Button from '../common/Button';
7+
import SettingEmailSuccess from './SettingEmailSuccess';
78

89
export type SettingEmailRowProps = {
910
email: string;
11+
isEmailSent: boolean;
1012
onChangeEmail: (email: string) => Promise<void>;
1113
};
1214

13-
function SettingEmailRow({ email, onChangeEmail }: SettingEmailRowProps) {
15+
function SettingEmailRow({
16+
email,
17+
isEmailSent,
18+
onChangeEmail,
19+
}: SettingEmailRowProps) {
1420
const [edit, setEdit] = useState(false);
1521
const [value, onChange] = useInput(email);
1622

@@ -26,6 +32,7 @@ function SettingEmailRow({ email, onChangeEmail }: SettingEmailRowProps) {
2632
title="이메일 주소"
2733
description="회원 인증 또는 시스템에서 발송하는 이메일을 수신하는 주소입니다."
2834
editButton={!edit}
35+
showEditButton={!isEmailSent}
2936
onClickEdit={() => setEdit(true)}
3037
editButtonText="변경"
3138
>
@@ -38,6 +45,8 @@ function SettingEmailRow({ email, onChangeEmail }: SettingEmailRowProps) {
3845
/>
3946
<Button>변경</Button>
4047
</Form>
48+
) : isEmailSent ? (
49+
<SettingEmailSuccess />
4150
) : (
4251
email
4352
)}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import { MdCheck } from 'react-icons/md';
3+
import styled from 'styled-components';
4+
import palette from '../../lib/styles/palette';
5+
6+
function SettingEmailSuccess() {
7+
return (
8+
<SettingEmailSuccessBlock>
9+
<MdCheck className="icon" />
10+
<div className="text">
11+
메일이 전송되었습니다. 받은 편지함을 확인하세요.
12+
</div>
13+
</SettingEmailSuccessBlock>
14+
);
15+
}
16+
17+
const SettingEmailSuccessBlock = styled.div`
18+
display: flex;
19+
align-items: center;
20+
padding-left: 0.75rem;
21+
padding-right: 0.75rem;
22+
color: ${palette.teal6};
23+
white-space: pre;
24+
.icon {
25+
margin-right: 10px;
26+
}
27+
.description {
28+
font-size: 0.875rem;
29+
text-align: center;
30+
}
31+
`;
32+
33+
export default SettingEmailSuccess;

src/components/setting/SettingRow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type SettingRowProps = {
1010
onClickEdit?: () => void;
1111
editButton?: boolean;
1212
description?: string;
13+
showEditButton?: boolean;
1314
editButtonText?: string;
1415
};
1516

@@ -18,6 +19,7 @@ function SettingRow({
1819
children,
1920
editButton,
2021
description,
22+
showEditButton = true,
2123
onClickEdit,
2224
editButtonText,
2325
}: SettingRowProps) {
@@ -29,7 +31,7 @@ function SettingRow({
2931
</div>
3032
<div className="block-for-mobile">
3133
<div className="contents">{children}</div>
32-
{editButton && (
34+
{editButton && showEditButton && (
3335
<div className="edit-wrapper">
3436
<SettingEditButton
3537
onClick={onClickEdit}

src/components/setting/SettingRows.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type SettingRowsProps = {
1313
title: string | null;
1414
username: string;
1515
email: string;
16+
isEmailSent: boolean;
1617
onUpdateTitle: (title: string) => Promise<any>;
1718
onChangeEmail: (email: string) => Promise<any>;
1819
onUpdateSocialInfo: (profileLinks: ProfileLinks) => Promise<any>;
@@ -46,6 +47,7 @@ function SettingRows({
4647
onUpdateSocialInfo,
4748
onUpdateEmailRules,
4849
onUnregister,
50+
isEmailSent,
4951
}: SettingRowsProps) {
5052
return (
5153
<Rows>
@@ -54,7 +56,11 @@ function SettingRows({
5456
onUpdateTitle={onUpdateTitle}
5557
/>
5658
<SettingSocialInfoRow {...profileLinks} onUpdate={onUpdateSocialInfo} />
57-
<SettingEmailRow email={email} onChangeEmail={onChangeEmail} />
59+
<SettingEmailRow
60+
email={email}
61+
onChangeEmail={onChangeEmail}
62+
isEmailSent={isEmailSent}
63+
/>
5864
{userMeta && (
5965
<SettingEmailRulesRow
6066
notification={userMeta.email_notification}

src/containers/setting/SettingRowsContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function SettingRowsContainer(props: SettingRowsContainerProps) {
1717
const user = useSelector((state: RootState) => state.core.user);
1818
const updateSocialInfo = useUpdateSocialInfo();
1919
const { update: updateEmailRules } = useUpdateEmailRules();
20-
const { change: changeEmail } = useChangeEmail();
20+
const { change: changeEmail, called: isEmailSent } = useChangeEmail();
2121
const unregister = useUnregister();
2222

2323
const onUpdateEmailRules = useCallback(
@@ -50,6 +50,7 @@ function SettingRowsContainer(props: SettingRowsContainerProps) {
5050
onUpdateEmailRules={onUpdateEmailRules}
5151
onUnregister={unregister}
5252
userMeta={meta}
53+
isEmailSent={isEmailSent}
5354
/>
5455
);
5556
}

src/containers/setting/hooks/useChangeEmail.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const CHANGE_EMAIL = gql`
99
`;
1010

1111
export default function useChangeEmail() {
12-
const [changeEmail] = useMutation(CHANGE_EMAIL);
13-
12+
const [changeEmail, { called }] = useMutation(CHANGE_EMAIL);
1413
const change = useCallback(
1514
(email: string) => {
1615
return changeEmail({
@@ -24,5 +23,6 @@ export default function useChangeEmail() {
2423

2524
return {
2625
change,
26+
called,
2727
};
2828
}

0 commit comments

Comments
 (0)