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

#156 [REFACTOR] 프로필 관련 파일 내부 코드 분리 #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions src/components/full-modal/ProfileInfoItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ProfileInfoProps } from '@/types/profile-modal';
import Input from '../ui/Input';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

폴더명 바뀌어서 Input이 아니라 input일거에요!

import * as S from './ProfileModal.styles';

const ProfileInfoItem = (props: ProfileInfoProps) => {
const { title, name, value, onChange, disabled } = props;

return (
<S.ProfileInfoItem>
<S.ProfileInfoTitle>{title}</S.ProfileInfoTitle>
<Input
name={name}
disabled={disabled}
onChange={onChange}
value={value}
style={{
backgroundColor: disabled ? '#eee' : '#fff',
}}
/>
</S.ProfileInfoItem>
);
};

export default ProfileInfoItem;
85 changes: 44 additions & 41 deletions src/components/full-modal/ProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import Button from '../ui/button/Button';
import * as S from './ProfileModal.styles';
import { useToggleModal } from '@/hooks/useToggleModal';
import { EDIT_PROFILE_MODAL_ID } from '@/constants/constant';
import Input from '../ui/input';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { fetchUserData, updateUserData } from '@/api/profileApi';
import { DocumentData } from 'firebase/firestore';
import { ChildProps } from '@/types/profile-modal';
import ProfileInfoItem from './ProfileInfoItem';

const ProfileModal = ({ onSendData }: ChildProps) => {
const navigate = useNavigate();
Expand Down Expand Up @@ -40,20 +40,14 @@ const ProfileModal = ({ onSendData }: ChildProps) => {
}
}, [userData, onSendData]);

const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { value, name } = e.target;

if (name === 'name') {
setName(value);
} else if (name === 'email') {
setEmail(value);
} else if (name === 'phone') {
setPhone(value);
} else if (name === 'account') {
setAccount(value);
} else if (name === 'bankName') {
setBankName(value);
}
if (name === 'name') setName(value);
else if (name === 'email') setEmail(value);
else if (name === 'phone') setPhone(value);
else if (name === 'account') setAccount(value);
else if (name === 'bankName') setBankName(value);
};

const onClick = async () => {
Expand Down Expand Up @@ -85,34 +79,43 @@ const ProfileModal = ({ onSendData }: ChildProps) => {
</S.ProfileHeader>
<S.ProfileInfo>
<S.ProfileInfoUl>
<S.ProfileInfoItem>
<S.ProfileInfoTitle>사번</S.ProfileInfoTitle>
<Input
disabled
style={{ backgroundColor: '#eee' }}
value={userData?.userSn}
/>
</S.ProfileInfoItem>
<S.ProfileInfoItem>
<S.ProfileInfoTitle>이름</S.ProfileInfoTitle>
<Input onChange={onChange} value={name} name="name" />
</S.ProfileInfoItem>
<S.ProfileInfoItem>
<S.ProfileInfoTitle>이메일</S.ProfileInfoTitle>
<Input onChange={onChange} value={email} name="email" />
</S.ProfileInfoItem>
<S.ProfileInfoItem>
<S.ProfileInfoTitle>연락처</S.ProfileInfoTitle>
<Input onChange={onChange} value={phone} name="phone" />
</S.ProfileInfoItem>
<S.ProfileInfoItem>
<S.ProfileInfoTitle>은행</S.ProfileInfoTitle>
<Input onChange={onChange} value={bankName} name="bankName" />
</S.ProfileInfoItem>
<S.ProfileInfoItem>
<S.ProfileInfoTitle>계좌번호</S.ProfileInfoTitle>
<Input onChange={onChange} value={account} name="account" />
</S.ProfileInfoItem>
<ProfileInfoItem
title="사번"
name=""
value={userData?.userSn}
disabled={true}
onChange={handleInputChange}
/>
<ProfileInfoItem
title="이름"
name="name"
value={name}
onChange={handleInputChange}
/>
<ProfileInfoItem
title="이메일"
name="email"
value={email}
onChange={handleInputChange}
/>
<ProfileInfoItem
title="연락처"
name="phone"
value={phone}
onChange={handleInputChange}
/>
<ProfileInfoItem
title="은행"
name="bankName"
value={bankName}
onChange={handleInputChange}
/>
<ProfileInfoItem
title="계좌번호"
name="account"
value={account}
onChange={handleInputChange}
/>
</S.ProfileInfoUl>
</S.ProfileInfo>
<S.ProfileButtons>
Expand Down
8 changes: 8 additions & 0 deletions src/types/profile-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ import { DocumentData } from 'firebase/firestore';
export type ChildProps = {
onSendData: (data: DocumentData | null) => void;
};

export type ProfileInfoProps = {
title: string;
name: string;
value: string;
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
disabled?: boolean;
};
Loading