Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zestlee1106 committed Oct 24, 2023
2 parents c4e9153 + efda469 commit b978475
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 33 deletions.
38 changes: 26 additions & 12 deletions api/userInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UserInfoProps } from '@/context/UserInfoProvider.tsx';
import { RoomSearch } from '@/public/types/room';
import { Profile } from '@/public/types/user';
import { fetchData } from '.';

export const getProfile = async () => {
Expand All @@ -11,6 +12,27 @@ export const getProfile = async () => {
});
};

export const makeLikedRooms = async (id: number) => {
return await fetchData(`/api/v1/rooms/${id}/liked`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
});
}

/**
* @TODO Api 나오면 url 및 params 바꿔줘야함!!
*/
export const makeDisLikedRooms = async (id: number) => {
return await fetchData(`/api/v1/rooms/${id}/disLiked`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
});
}

export const getLikedRooms = async (page: number) => {
let result;
try {
Expand All @@ -27,20 +49,12 @@ export const getLikedRooms = async (page: number) => {
return result;
};

export const makeLikedRooms = async (id: number) => {
return await fetchData(`/api/v1/rooms/${id}/liked`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
});
}

export const makeDisLikedRooms = async (id: number) => {
return await fetchData(`/api/v1/rooms/${id}/disLiked`, {
method: 'DELETE',
export const modifyProfile = async (profileInfo: Profile) => {
return await fetchData(`/api/v1/my/profile`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(profileInfo)
});
}
18 changes: 10 additions & 8 deletions components/Nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ const menus = [
];

export default function Nav({ initMenu, profile }: NavProps) {
// const { setUserInfoData, userInfoState } = useUserInfo();
const [hoverMenu, setHoverMenu] = useState(-1); // 초기화
const router = useRouter();
const { setUserInfoData, userInfoState } = useUserInfo();
const handleNavClicked = (index: number) => {
router.push(
{
pathname: menus[index].router,
query: { data: profile && JSON.stringify(profile) },
},
`${menus[index].router}`
);
if (menus[index].router || '' !== '' ) {
router.push(
{
pathname: menus[index].router,
query: { data: profile && JSON.stringify(profile) },
},
`${menus[index].router}`
);
}
};

return (
Expand Down
37 changes: 24 additions & 13 deletions pages/userInfo/editProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import useModal from '@/hooks/useModal.ts';
import { isValidEmail, isRequired } from '@/utils/validCheck.ts';
import { Textarea, Button, Upload, Input, Calendar } from '@/components/index.tsx';
import ProfileCamera from '@/public/icons/profileCamera.svg';
import { User } from '@/public/types/user';
import { User, Profile } from '@/public/types/user';
import { modifyProfile } from '@/api/userInfo';
import isEmpty from 'lodash-es/isEmpty';

interface ProfileProps {
Expand All @@ -34,21 +35,31 @@ export default function EditProfile({ _imageSrc, userInfo }: ProfileProps) {
} = UseForm({ mode: 'onChange' });

const capitalizeFirstLetter = (str: string) => {
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
return (str || '').charAt(0).toUpperCase() + str.slice(1).toLowerCase();
}

const [buttonState, setButtonState] = useState(capitalizeFirstLetter(userInfo?.gender));

const onSubmit: SubmitHandler<FieldValues> = (data) => {
openModal({
props: {
title: 'My Postings',
size: 'full',
custom: true,
customHeader: true,
},
children: <>hi</>,
});
const onSubmit: SubmitHandler<FieldValues> = async (data) => {
try {
const profileData = data as Profile;
profileData.profileId = userInfo.id || 0;
const result = await modifyProfile(profileData);
console.log("result in editprofile", result);
alert('수정되었습니다');

// openModal({
// props: {
// title: 'My Postings',
// size: 'full',
// custom: true,
// customHeader: true,
// },
// children: <>hi</>,
// });
} catch (error) {
console.error('[ERROR] EDIT PROFILE', error);
}
};

const isPostingComplete = () => {
Expand Down Expand Up @@ -194,7 +205,7 @@ export default function EditProfile({ _imageSrc, userInfo }: ProfileProps) {
<div className="mt-[255px] fixed bottom-0 w-full overflow-x-hidden left-[50%] translate-x-[-50%] px-[20px] max-w-max">
<div className="w-full">
<div className="mb-[13px]">
<Button size="lg" type="submit" disabled={isPostingComplete()} onClick={() => alert('완성!')}>
<Button size="lg" type="submit" disabled={isPostingComplete()}>
Complete
</Button>
</div>
Expand Down
9 changes: 9 additions & 0 deletions public/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ export interface User {
accountNonLocked: boolean;
enabled: boolean;
}

export interface Profile {
profileId : number;
gender: string;
firstName: string;
lastName: string;
birthDate: string;
description: string;
}

0 comments on commit b978475

Please sign in to comment.