Skip to content

Commit

Permalink
Merge branch 'feat/#142/store-page-api' of https://github.com/SOPT-al…
Browse files Browse the repository at this point in the history
…l/35-APPJAM-WEB-CAKEY into feat/#142/store-page-api
  • Loading branch information
youtheyeon committed Jan 21, 2025
2 parents e6b363c + 79b1e0f commit d486bac
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 55 deletions.
4 changes: 4 additions & 0 deletions src/apis/likes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { usePostStoreLikes } from './usePostStoreLikes';
import { usePostCakeLikes } from './usePostCakeLikes';

export { usePostStoreLikes, usePostCakeLikes };
22 changes: 22 additions & 0 deletions src/apis/likes/usePostCakeLikes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useMutation } from '@tanstack/react-query';

import { instance } from '@apis/instance';

import { END_POINT } from '@constants';

import { MutateResposneType } from '@types';

const postCakeLikes = async (cakeId: number): Promise<MutateResposneType> => {
try {
const response = await instance.post(END_POINT.POST_CAKE_LIKES(cakeId));
return response.data;
} catch (error) {
console.log(error);
throw error;
}
};
export const usePostCakeLikes = () => {
return useMutation({
mutationFn: (cakeId: number) => postCakeLikes(cakeId),
});
};
23 changes: 23 additions & 0 deletions src/apis/likes/usePostStoreLikes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useMutation } from '@tanstack/react-query';

import { instance } from '@apis/instance';

import { END_POINT } from '@constants';

import { MutateResposneType } from '@types';

const postStoreLikes = async (storeId: number): Promise<MutateResposneType> => {
try {
const response = await instance.post(END_POINT.POST_STORE_LIKES(storeId));
return response.data;
} catch (error) {
console.log(error);
throw error;
}
};

export const usePostStoreLikes = () => {
return useMutation({
mutationFn: (storeId: number) => postStoreLikes(storeId),
});
};
Empty file removed src/apis/myPage/.keep
Empty file.
3 changes: 3 additions & 0 deletions src/apis/myPage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { useFetchUser } from './useFetchUser';

export { useFetchUser };
26 changes: 26 additions & 0 deletions src/apis/myPage/useFetchUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useSuspenseQuery } from '@tanstack/react-query';

import { instance } from '@apis/instance';

import { END_POINT, queryKey } from '@constants';

import { ApiResponseType, UserResponse } from '@types';

const fetchUser = async (): Promise<UserResponse> => {
try {
const response = await instance.get<ApiResponseType<UserResponse>>(
END_POINT.FETCH_USER
);
return response.data.data;
} catch (error) {
console.log(error);
throw error;
}
};

export const useFetchUser = () => {
return useSuspenseQuery({
queryKey: [queryKey.USER],
queryFn: fetchUser,
});
};
29 changes: 13 additions & 16 deletions src/components/common/IconButton/IconButton.css.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';

import { flexGenerator } from '@styles/generator.css';
Expand All @@ -24,29 +23,27 @@ export const buttonStyle = recipe({
gap: 0,
},
like20: {
width: '2rem',
gap: '0.6rem',
},
like36: {
width: '3.6rem',
gap: 0,
},
},
onMap: {
true: {
width: '4rem',
height: '4rem',
borderRadius: '50%',
backgroundColor: vars.colors.white,
},
false: {},
},
},
});

export const countStyle = style([
vars.fonts.body08_r_12,
{
display: 'block',
height: '1.4rem',
export const countStyle = recipe({
base: {
color: vars.colors.gray400,
},
]);
variants: {
buttonType: {
save24: [vars.fonts.body08_r_12],
save28: [vars.fonts.body07_r_14],
like20: [vars.fonts.body08_r_12],
like36: [],
},
},
});
27 changes: 18 additions & 9 deletions src/components/common/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { ButtonHTMLAttributes } from 'react';

import { usePostCakeLikes, usePostStoreLikes } from '@apis/likes';

import {
IcFillLikeOff36,
IcFillLikeOn36,
Expand All @@ -16,8 +18,7 @@ export interface IconButtonProps
buttonType: 'save24' | 'save28' | 'like20' | 'like36';
isActive?: boolean;
count?: number;
itemId?: number; // storeId | cakeIdλ₯Ό λ°›μ•„μ„œ api μš”μ²­μ— μ‚¬μš©ν•©λ‹ˆλ‹€
onMap?: boolean;
itemId?: number;
}

const buttonIcon = {
Expand All @@ -44,21 +45,29 @@ const IconButton = ({
isActive,
count,
itemId,
onMap = false,
}: IconButtonProps) => {
const { mutate: postCakeLikes } = usePostCakeLikes();
const { mutate: postStoreLikes } = usePostStoreLikes();

const handleButtonClick = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
console.log('iconClick', itemId);

if (itemId !== undefined) {
if (buttonType === 'save24' || buttonType === 'save28') {
postStoreLikes(itemId);
} else {
postCakeLikes(itemId);
}
}
};
return (
<button
className={buttonStyle({ buttonType, onMap })}
onClick={handleButtonClick}
>
<button className={buttonStyle({ buttonType })} onClick={handleButtonClick}>
{isActive
? buttonIcon[buttonType]?.active
: buttonIcon[buttonType]?.inactive}
{count !== undefined && <span className={countStyle}>{count}</span>}
{count !== undefined && (
<span className={countStyle({ buttonType })}>{count}</span>
)}
</button>
);
};
Expand Down
17 changes: 2 additions & 15 deletions src/components/common/Image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface ImageProps extends HTMLAttributes<HTMLDivElement> {
hasIcon?: boolean;
isActive?: boolean;
itemId?: number;
onIconClick?: () => void;
}

const Image = ({
Expand All @@ -25,26 +24,14 @@ const Image = ({
hasIcon = false,
isActive,
itemId, // storeId | cakeIdλ₯Ό λ°›μ•„μ„œ IconButton으둜 λ„˜κ²¨μ€λ‹ˆλ‹€
onIconClick,
}: ImageProps) => {
return (
<div className={divStyle}>
{numberLabel && <div className={numberLabelStyle}>{numberLabel}</div>}
<img src={src} className={imageStyle({ variant })} />
{hasIcon && (
<div
className={iconButtonStyle}
onClick={(e) => {
e.stopPropagation();
if (onIconClick) onIconClick();
}}
>
<IconButton
buttonType="like36"
onMap={false}
isActive={isActive}
itemId={itemId}
/>
<div className={iconButtonStyle}>
<IconButton buttonType="like36" isActive={isActive} itemId={itemId} />
</div>
)}
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/constants/apis/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ export const END_POINT = {
FETCH_STORE_DETAIL_INFO: (storeId: number) =>
`/api/v1/store/${storeId}/information`,
FETCH_STORE_LINK: (storeId: number) => `/api/v1/store/kakaoLink/${storeId}`,
FETCH_USER: '/api/v1/user',
FETCH_CAKE_RANK: '/api/v1/cake/rank',
POST_CAKE_LIKES: (cakeId: number) => `/api/v1/cake/likes/${cakeId}`,
POST_STORE_LIKES: (storeId: number) => `/api/v1/store/likes/${storeId}`,
} as const;
1 change: 1 addition & 0 deletions src/constants/apis/queryKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const queryKey = {
STORE_COORDINATE_LIST: 'storeCoordinateList',
STORE_STATIONS: 'storeStations',
CAKE_RANK: 'cakeRank',
USER: 'user',
} as const;
10 changes: 5 additions & 5 deletions src/pages/home/page/HomePage/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useState } from 'react';

import { useFetchCakeRank } from '@apis/home';

import { DesignCard } from '@components';
import { CATEGORY, MainKeyVisual } from '@constants';
import { useEasyNavigate } from '@hooks';
import { StoreRankingButton } from '@pages/home/components';
import CategoryCard from '@pages/home/components/CategoryCard/CategoryCard';
import { isLoggedIn } from '@utils';

import { IcHomeArrow } from '@svgs';

Expand Down Expand Up @@ -62,12 +61,13 @@ const storeRankingData = [
},
];

const user = { userName: '박채연' };

const HomePage = () => {
const [isLogin] = useState(true);
const isLogin = isLoggedIn();
const { goViewPage } = useEasyNavigate();
const { data: cakeRankData } = useFetchCakeRank();
const user = isLogin
? JSON.parse(localStorage.getItem('user') || '{}')
: null;

return (
<div className={homePageLayout}>
Expand Down
17 changes: 8 additions & 9 deletions src/pages/myPage/page/Mypage/MyPage.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { useFetchUser } from '@apis/myPage';

import { AuthModal, Modal, TextButton } from '@components';
import { WHIPEE_CONTACT_FORM } from '@constants';
import { useEasyNavigate, useModal } from '@hooks';
import { LetsGoButton, ProfileCard } from '@pages/myPage/components';
import { isLoggedIn } from '@utils';

import {
letsGoButtonWrapper,
loginButton,
profileCardStyle,
} from './MyPage.css';

const user = {
userId: 1,
userName: 'μ₯¬λ¨μ΄',
userEmail: '[email protected]',
};

const MyPage = () => {
const isLogin = true; //μΆ”ν›„ μ‚­μ œ ν›„ localStorage.getItem둜 μˆ˜μ •ν•  μ˜ˆμ •
const isLogin = isLoggedIn();

const { isModalOpen, openModal, closeModal } = useModal();

Expand All @@ -26,13 +23,15 @@ const MyPage = () => {
window.open(WHIPEE_CONTACT_FORM, '_blank');
};

const { data: userData } = useFetchUser();

return (
<>
<section className={profileCardStyle[isLogin ? 'login' : 'logout']}>
<ProfileCard
isLogin={isLogin}
userName={user.userName}
userEmail={user.userEmail}
userName={userData.userName}
userEmail={userData.userEmail}
/>
</section>

Expand Down
1 change: 1 addition & 0 deletions src/pages/store/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const Banner = ({ storeData }: BannerProps) => {
<IconButton
buttonType={'save28'}
isActive={storeData.isLiked}
itemId={storeData.storeId}
count={32}
/>
</div>
Expand Down
7 changes: 6 additions & 1 deletion src/pages/store/components/StoreDesign/StoreDesign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ const StoreDesign = ({ storeId }: StoreDesignProps) => {
key={design.cakeId}
onClick={() => handleImageClick(design.imageUrl)}
>
<Image src={design.imageUrl} hasIcon isActive={design.isLiked} />
<Image
src={design.cakeImageUrl}
hasIcon
isActive={design.isLiked}
itemId={design.cakeId}
/>
</li>
))}
</ul>
Expand Down
5 changes: 5 additions & 0 deletions src/types/apis/commonType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ export interface ApiResponseType<T> {
message: string;
data: T;
}

export interface MutateResposneType {
code: number;
message: string;
}
4 changes: 4 additions & 0 deletions src/types/apis/myPage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface UserResponse {
userName: string;
userEmail: string;
}

0 comments on commit d486bac

Please sign in to comment.