Skip to content

Commit

Permalink
feat: 인사말 api 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
wokbjso authored Oct 28, 2024
1 parent 795a6bb commit 2a54cdc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
13 changes: 13 additions & 0 deletions app/api/greeting/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NextResponse } from 'next/server';

import { Response } from '@/apis';
import { fetchData } from '@/apis/fetch-data';

export async function GET() {
const data = await fetchData<Response<{ message: string }>>(
'/greeting',
'GET',
);

return NextResponse.json(data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useAtomValue } from 'jotai';

import { Image } from '@/components/atoms';
import { useCurrentMemberInfo } from '@/hooks';
import { useCurrentMemberInfo, useGreetingText } from '@/hooks';
import SwimieCharacterImage from '@/public/images/swimie-character.png';
import { calendarSwimCountAtom } from '@/store';
import { css, cx } from '@/styled-system/css';
Expand All @@ -14,12 +14,17 @@ import { Calendar } from '../molecules';

export const UserCalendarProfile = () => {
const { data, isLoading } = useCurrentMemberInfo();
const {
data: greetingTextData,
isLoading: isGreetingTextDataLoading,
isSuccess: isGreetingTextDataSuccess,
} = useGreetingText();
const totalSwimCount = useAtomValue(calendarSwimCountAtom);
const isEmptyCount = totalSwimCount === 0;

return (
<>
{isLoading ? (
{isLoading || isGreetingTextDataLoading ? (
<UserProfileSkeleton />
) : (
<div className={cx(profileContainerStyles, profileColorStyle)}>
Expand All @@ -33,9 +38,11 @@ export const UserCalendarProfile = () => {
<div className={userInfoStyles}>
<p className={nicknameStyles}>{data?.data.nickname}님,</p>
<p className={descriptionStyles}>
{isEmptyCount
? '이번달 수영 기록을 해볼까요?'
: `이번달 수영을 ${totalSwimCount}번 다녀왔어요!`}
{isGreetingTextDataSuccess
? greetingTextData.data.message
: isEmptyCount
? '이번달 수영 기록을 해볼까요?'
: `이번달 수영을 ${totalSwimCount}번 다녀왔어요!`}
</p>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions hooks/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './use-cheer-eligibility';
export * from './use-current-member-info';
export * from './use-follow-mutate';
export * from './use-following-state';
export * from './use-greeting-text';
21 changes: 21 additions & 0 deletions hooks/apis/use-greeting-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useQuery } from '@tanstack/react-query';

import { Response } from '@/apis';

export const getGreetingText = async () => {
const res = await fetch(`/api/greeting`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

return res.json();
};

export const useGreetingText = () => {
return useQuery<Response<{ message: string }>>({
queryKey: ['greetingText'],
queryFn: () => getGreetingText(),
});
};

0 comments on commit 2a54cdc

Please sign in to comment.