Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

이메일 유저이름과 도메인 통합시키기 #214

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 10 additions & 51 deletions src/components/organisms/MyPage/MemberInfoEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { use, useCallback, useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';

import styled from '@emotion/styled';

Expand All @@ -8,7 +8,6 @@ import { UserBackgroundStatus } from '#/types';
import { isUserStudent, isUserWorker } from '#/utilities/user';
import { CheckBox } from '#atoms/CheckBox';
import { Input } from '#atoms/Input';
import { Select } from '#atoms/Select';
import { Txt } from '#atoms/Text';
import { BasicInfoEdit } from '#molecules/MyPage/BasicInfoEdit';
import { MyInfoBlock } from '#molecules/MyPage/MyInfoBlock';
Expand All @@ -34,10 +33,6 @@ const StyledTextarea = styled.textarea`
color: #bdbdbd;
}
`;
const EmailBlock = styled.div`
display: flex;
gap: 3px;
`;
const Hyphen = styled.div`
width: 10px;
border: 1px solid #424242;
Expand Down Expand Up @@ -69,10 +64,6 @@ const isUserStudentOrWorker = (backgroundStatus: UserBackgroundStatus) => {

export const MemberInfoEdit = () => {
const tempUser = useTempAuthStore((state) => state.tempUser);
const [tempEmail, setTempEmail] = useState<{ id: string; domain: string }>({
id: '',
domain: '',
});
const [tempPhone, setTempPhone] = useState<{ first: string; second: string; third: string }>({
first: '',
second: '',
Expand All @@ -86,27 +77,11 @@ export const MemberInfoEdit = () => {
alert('최대 글자수를 초과하였습니다.');
return;
}
if (tempUser !== null) setTempUser({ ...tempUser, [key]: value });
},
[tempUser, setTempUser]
);

const handleUpdateTempEmail = useCallback(
(key: 'id' | 'domain', value: string, maxLength?: number) => {
if (maxLength && value.length > maxLength) {
alert('최대 글자수를 초과하였습니다.');
return;
}
if (tempUser === null) return;
if (key === 'id') {
setTempEmail({ ...tempEmail, id: value });
setTempUser({ ...tempUser, email: `${value}@${tempEmail.domain}` });
} else {
setTempEmail({ ...tempEmail, domain: value });
setTempUser({ ...tempUser, email: `${tempEmail.id}@${value}` });
if (tempUser !== null) {
setTempUser({ ...tempUser, [key]: value });
}
},
[setTempUser, tempEmail, tempUser]
[tempUser, setTempUser]
);

const handleUpdateTempPhone = useCallback(
Expand Down Expand Up @@ -141,10 +116,6 @@ export const MemberInfoEdit = () => {

// init
useEffect(() => {
if (tempUser !== null && tempUser.email !== null) {
const email = tempUser.email.split('@');
setTempEmail({ id: email[0], domain: email[1] });
}
if (tempUser !== null && tempUser.phoneNumber !== null) {
const phone = tempUser.phoneNumber.split('-');
setTempPhone({ first: phone[0], second: phone[1], third: phone[2] });
Expand Down Expand Up @@ -172,27 +143,15 @@ export const MemberInfoEdit = () => {
/>
</BasicInfoEdit>
<BasicInfoEdit title={'이메일'} titleWidth={97} essential>
<EmailBlock>
<Input
value={tempEmail.id}
onChange={(e) => handleUpdateTempEmail('id', e.target.value, 20)}
width="118px"
placeholder="이메일 입력"
/>
<Select
value={tempEmail.domain}
onChange={(e) => handleUpdateTempEmail('domain', e.target.value)}
width="128px"
placeholder="선택하세요"
>
<Select.Option value="google.com">google.com</Select.Option>
<Select.Option value="naver.com">naver.com</Select.Option>
</Select>
</EmailBlock>
<Input
value={tempUser.email ?? ''}
onChange={(e) => handleUpdateTempUser('email', e.target.value, 100)}
placeholder="이메일 입력"
/>
</BasicInfoEdit>
<BasicInfoEdit title={'닉네임'} titleWidth={97} essential>
<Input
value={tempUser.nickname === null ? '' : tempUser.nickname}
value={tempUser.nickname ?? ''}
onChange={(e) => handleUpdateTempUser('nickname', e.target.value, 20)}
width="207px"
placeholder="닉네임 입력"
Expand Down
27 changes: 19 additions & 8 deletions src/components/templates/MyPage/InfoEditSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from '@emotion/styled';
import { usePresignedUrlLazyQuery } from '#/hooks/use-file';
import { useMeMutation, useMeQuery } from '#/hooks/use-user';
import { useTempAuthStore } from '#/stores/tempAuth';
import { Me } from '#/types';
import { Me, User } from '#/types';
import { uploadFile } from '#/utilities/storage';
import { Button } from '#atoms/Button';
import { ActivityEdit } from '#organisms/MyPage/ActivityEdit';
Expand Down Expand Up @@ -33,11 +33,7 @@ const checkRequiredValue = (tempUser: Me | null) => {
if (tempUser.username === '' || tempUser.username === null) {
alert('이름을 입력해주세요.');
return false;
} else if (
tempUser.email === null ||
tempUser.email.split('@')[0] === '' ||
tempUser.email.split('@')[1] === ''
) {
} else if (tempUser.email === null) {
alert('이메일을 입력해주세요.');
return false;
} else if (tempUser.nickname === '' || tempUser.nickname === null) {
Expand All @@ -61,7 +57,20 @@ const checkRequiredValue = (tempUser: Me | null) => {
} else if (tempUser.skillIdList === null || tempUser.skillIdList.length === 0) {
alert('사용 가능한 기술/툴을 선택해주세요.');
return false;
} else return true;
} else {
return true;
}
};

const checkValidation = (user: User) => {
if (user.email) {
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailRegex.test(user.email)) {
alert('이메일 형식이 올바르지 않습니다.');
return false;
}
}
return true;
};

export const InfoEditSection = ({ handleEditing }: InfoEditSectionProps) => {
Expand All @@ -75,7 +84,9 @@ export const InfoEditSection = ({ handleEditing }: InfoEditSectionProps) => {
const { trigger: mutateUser } = useMeMutation();

const submitModifyHandler = async () => {
if (!checkRequiredValue(tempUser)) return;
if (!tempUser || !checkRequiredValue(tempUser) || !checkValidation(tempUser)) {
return;
}
let profileImageUrl = me?.profileImageUrl;
let portfolioUrl = me?.portfolioUrl;
if (tempImage !== null) {
Expand Down
Loading