Skip to content

Commit

Permalink
feat: ai 인삿말 홈 달력 헤더에 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
wokbjso committed Oct 25, 2024
1 parent 19ec703 commit a13bf6f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 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
@@ -1,11 +1,8 @@
'use client';

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';
import { flex } from '@/styled-system/patterns';

Expand All @@ -14,8 +11,7 @@ import { Calendar } from '../molecules';

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

return (
<>
Expand All @@ -33,9 +29,7 @@ export const UserCalendarProfile = () => {
<div className={userInfoStyles}>
<p className={nicknameStyles}>{data?.data.nickname}님,</p>
<p className={descriptionStyles}>
{isEmptyCount
? '이번달 수영 기록을 해볼까요?'
: `이번달 수영을 ${totalSwimCount}번 다녀왔어요!`}
{greetingTextData?.data.message}
</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 a13bf6f

Please sign in to comment.