Skip to content

Commit

Permalink
๐Ÿ› fix: ๊ณ ์šฉ์ฃผ ํ”„๋กœํ•„ API ์ˆ˜์ • Team-inglo#73
Browse files Browse the repository at this point in the history
  • Loading branch information
naarang committed Oct 31, 2024
1 parent ba3c733 commit 65add69
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 14 deletions.
85 changes: 85 additions & 0 deletions src/components/Employer/Profile/EmployerProfileMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { useEffect, useState } from 'react';
import { IconType } from '@/constants/profile';
import ProfileIcon from '@/assets/icons/Profile/ProfileIcon.svg?react';
import NotificationIcon from '@/assets/icons/Profile/NotificationIcon.svg?react';
import LogoutIcon from '@/assets/icons/Profile/LogoutIcon.svg?react';
import ToggleBar from '@/assets/icons/Profile/ToggleBar.svg?react';
import ToggleButton from '@/assets/icons/Profile/ToggleButton.svg?react';
import { usePatchNotificationAllowed } from '@/hooks/api/useSetting';
import { usegetOwnerSummaries } from '@/hooks/api/useProfile';

type EmployerProfileMenuProps = {
title: string;
iconType: IconType;
onClick?: () => void;
isToggle?: boolean;
};

const EmployerProfileMenu = ({
title,
iconType,
onClick,
isToggle,
}: EmployerProfileMenuProps) => {
const { mutate: patchNotificationAllowed } = usePatchNotificationAllowed();
const { data: notificaionAllowed } = usegetOwnerSummaries();

const [toggleOn, setToggleOn] = useState<boolean>(false);

useEffect(() => {
// ์•Œ๋ฆผ ์„ค์ • ์ƒํƒœ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
if (isToggle && notificaionAllowed) {
setToggleOn(notificaionAllowed.data.is_notification_allowed);
}
}, []);

const handleToggleChange = () => {
// ์•Œ๋ฆผ ์„ค์ • ๋ณ€๊ฒฝ
patchNotificationAllowed(!toggleOn, {
onSuccess: () => {
setToggleOn(!toggleOn);
},
});
};

const iconMapping = (iconType: IconType) => {
switch (iconType) {
case IconType.PROFILE:
return <ProfileIcon />;
case IconType.NOTIFICATION:
return <NotificationIcon />;
case IconType.LOGOUT:
return <LogoutIcon />;
default:
return null;
}
};

const Icon = iconMapping(iconType);

return (
<div
onClick={onClick}
className="flex items-center justify-between cursor-pointer p-6 rounded-[1.375rem] bg-EmployerProfileMenuGradient bg-cover bg-no-repeat bg-center"
>
<div className="flex justify-center items-center gap-4">
{Icon}
<div className="body-2 text-[#1E1926]">{title}</div>
</div>
{isToggle && (
<div className="relative flex items-center">
<ToggleBar fill="#00D1A033" />
<ToggleButton
fill={toggleOn ? '#00D1A0' : '#DCDCDC'}
className={`absolute transform transition-transform duration-300 ease-in-out ${
toggleOn ? 'translate-x-4' : 'translate-x-0'
}`}
onClick={handleToggleChange}
/>
</div>
)}
</div>
);
};

export default EmployerProfileMenu;
8 changes: 4 additions & 4 deletions src/components/Employer/Profile/EmployerProfileMenuList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ProfileMenu from '@/components/Profile/ProfileMenu';
import { IconType } from '@/constants/profile';
import { useNavigate } from 'react-router-dom';
import EmployerProfileMenu from './EmployerProfileMenu';

type EmployerProfileMenuListProps = {
handleBottomSheetOpen: () => void;
Expand All @@ -17,17 +17,17 @@ const EmployerProfileMenuList = ({

return (
<div className="flex flex-col gap-9 pt-9">
<ProfileMenu
<EmployerProfileMenu
title="ํšŒ์‚ฌ/์ ํฌ ์ •๋ณด ์ˆ˜์ •"
iconType={IconType.PROFILE}
onClick={handleEditProfileClick}
/>
<ProfileMenu
<EmployerProfileMenu
title="์•Œ๋ฆผ ์ˆ˜์‹ "
iconType={IconType.NOTIFICATION}
isToggle={true}
/>
<ProfileMenu
<EmployerProfileMenu
title="๋กœ๊ทธ์•„์›ƒ"
iconType={IconType.LOGOUT}
onClick={handleBottomSheetOpen}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ManageResume/ProfilePicture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ProfilePicture = ({ name, profileImg }: ProfilePictureProps) => {
/>
</div>
<span className="py-2 px-3 head-3 text-[#1E1926] text-center">
{name}
{name.replace('-', ' ')}
</span>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/api/useProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const usePatchUserProfile = () => {
});
};

// 3.5 (์œ ํ•™์ƒ) ํ”„๋กœํ•„ ์ˆ˜์ •
// 3.6 (๊ณ ์šฉ์ฃผ) ํšŒ์‚ฌ ์ •๋ณด ์ˆ˜์ •ํ•˜๊ธฐ
export const usePatchOwnerProfile = () => {
const navigate = useNavigate();
return useMutation({
Expand Down
24 changes: 16 additions & 8 deletions src/pages/Employer/EditProfile/EmployerEditProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ const EmployerEditProfilePage = () => {
const { mutate } = usePatchOwnerProfile();

useEffect(() => {
if (data && data.success) {
if (data) {
setOriginalData(data.data); // ์ˆ˜์ • ์ „ ๋ฐ์ดํ„ฐ

// get ํƒ€์ž…์—์„œ patch ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜
setNewEmployData(transformToEmployerProfileRequest(data.data)); // ์ˆ˜์ • ๋ฐ์ดํ„ฐ
}
}, []);
}, [data]);

useEffect(() => {
setIsValid(isValidEmployerProfile(newEmployData));
Expand All @@ -52,12 +52,20 @@ const EmployerEditProfilePage = () => {
setNewEmployData({ ...newEmployData, is_icon_img_changed: true });
}
// patch ํ›… ํ˜ธ์ถœ
mutate({
image: logoFile,
body: {
...newEmployData,
},
});

const formData = new FormData();
// ์ด๋ฏธ์ง€๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ FormData์— ์ถ”๊ฐ€
if (logoFile) {
formData.append('image', logoFile);
}
// JSON ๋ฐ์ดํ„ฐ๋ฅผ Blob์œผ๋กœ ๋ณ€ํ™˜ ํ›„ FormData์— ์ถ”๊ฐ€
formData.append(
'body',
new Blob([JSON.stringify(newEmployData)], {
type: 'application/json',
}),
);
mutate(formData);
}
};

Expand Down

0 comments on commit 65add69

Please sign in to comment.