From 14c1f86c0739df50c2958942eb2af8d32468a198 Mon Sep 17 00:00:00 2001 From: Hyun9811 <145583411+Hyun9811@users.noreply.github.com> Date: Sun, 26 Oct 2025 16:25:59 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=EC=B9=9C=EA=B5=AC=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EB=8D=94=EB=AF=B8=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/friendList/page.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/app/friendList/page.tsx b/src/app/friendList/page.tsx index 7652651..b159309 100644 --- a/src/app/friendList/page.tsx +++ b/src/app/friendList/page.tsx @@ -20,14 +20,7 @@ const FriendListPage = () => { const handleFriendPlus = () => { setIsModalOpen(true) } - const friendData = [ - { id: 1, name: '신혜민', tag: 1111, profile: user.user?.profileImage }, - { id: 2, name: '김의진', tag: 1112, profile: user.user?.profileImage }, - { id: 3, name: '강보석', tag: 1113, profile: user.user?.profileImage }, - { id: 4, name: '송수빈', tag: 1114, profile: user.user?.profileImage }, - { id: 5, name: '유성현', tag: 1115, profile: user.user?.profileImage }, - { id: 6, name: '짱똘', tag: 1116, profile: user.user?.profileImage }, - ] + const fetchFriendList = async () => { console.log(user.user?.id) if (user) { From 0cd97e44ab92f46db69ccc03dac670cf0a9f609b Mon Sep 17 00:00:00 2001 From: Hyun9811 <145583411+Hyun9811@users.noreply.github.com> Date: Mon, 27 Oct 2025 13:26:55 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=EC=B9=9C=EA=B5=AC=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20ui=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/friend/FriendCard.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/friend/FriendCard.tsx b/src/components/friend/FriendCard.tsx index 20d7e53..3739f6b 100644 --- a/src/components/friend/FriendCard.tsx +++ b/src/components/friend/FriendCard.tsx @@ -25,6 +25,7 @@ const FriendCard = ({ profile, name, tag }: friendProps) => { )}

{name}

+

#{tag}

Date: Mon, 17 Nov 2025 14:02:23 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=EC=9E=84=EC=8B=9C=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/friendList/page.tsx | 2 +- src/app/notification/page.tsx | 80 ++++++++--- src/components/invite/InviteAcceptModal.tsx | 47 +++++++ src/components/invite/InviteBottomSheet.tsx | 134 +++++++------------ src/components/invite/InviteUserListItem.tsx | 71 +++++++--- src/components/nbread/NbreadDetail.tsx | 3 +- src/lib/friend/getSearchFriend.ts | 81 ++++++++--- src/lib/invite/getInviteUser.ts | 17 ++- src/lib/invite/sendInviteRequest.ts | 60 +++++++++ src/lib/invite/updateInvite.ts | 53 ++++++++ src/lib/nbread/getUserNbread.ts | 3 +- src/lib/notification/getNotifications.ts | 1 + 12 files changed, 408 insertions(+), 144 deletions(-) create mode 100644 src/components/invite/InviteAcceptModal.tsx create mode 100644 src/lib/invite/sendInviteRequest.ts create mode 100644 src/lib/invite/updateInvite.ts diff --git a/src/app/friendList/page.tsx b/src/app/friendList/page.tsx index b159309..d3140ac 100644 --- a/src/app/friendList/page.tsx +++ b/src/app/friendList/page.tsx @@ -24,7 +24,7 @@ const FriendListPage = () => { const fetchFriendList = async () => { console.log(user.user?.id) if (user) { - const friendList = await getFriendList(user.user?.id || null) + const friendList = await getFriendList(user.user?.id || null,null) console.log('제발용',friendList) setFriendsData(friendList) } diff --git a/src/app/notification/page.tsx b/src/app/notification/page.tsx index c5055ef..e816b57 100644 --- a/src/app/notification/page.tsx +++ b/src/app/notification/page.tsx @@ -7,15 +7,23 @@ import { Notification } from '@/types/notification' import Icon from '@/components/common/icon/Icon' import Spinner from '@/components/common/spinner/Spinner' import FriendAcceptModal from '@/components/friend/FriendAcceptModal' +import InviteAcceptModal from '@/components/invite/InviteAcceptModal' const Page = () => { const [notificationData, setNotificationData] = useState([]) - const [selectedNotifycationId,setSelectedNotifycationId] = useState(null) - const [selectedNotifycationType,setSelectedNotifycationType] = useState(null) - const [selectedNotifycationSenderName,setSelectedNotifycationSenderName] = useState(null) - const [selectedNotifycationSenderId,setSelectedNotifycationSenderId] = useState(null) + const [selectedNotifycationId, setSelectedNotifycationId] = useState< + number | null + >(null) + const [selectedNotifycationType, setSelectedNotifycationType] = useState< + string | null + >(null) + const [selectedNotifycationSenderName, setSelectedNotifycationSenderName] = + useState(null) + const [selectedNotifycationSenderId, setSelectedNotifycationSenderId] = + useState(null) const [isLoading, setIsLoading] = useState(true) const userData = useUserStore((state) => state.user) - const [isAcceptModalOpen, setIsAcceptModalOpen]= useState(false) + const [isAcceptModalOpen, setIsAcceptModalOpen] = useState(false) + const [isInviteAcceptModalOpen, setIsInviteAcceptModalOpen] = useState(false) const fetchNotifications = async () => { setIsLoading(true) const data = await getNotification(userData!.id) @@ -53,10 +61,12 @@ const Page = () => { } }, [userData]) useEffect(() => { - if(selectedNotifycationType === 'friend_request'){ + if (selectedNotifycationType === 'friend_request') { setIsAcceptModalOpen(true) + } else if (selectedNotifycationType === 'invite') { + setIsInviteAcceptModalOpen(true) } - },[selectedNotifycationType]) + }, [selectedNotifycationType]) if (isLoading) { return } @@ -78,16 +88,32 @@ const Page = () => { -
+
{notificationData.map((data, index) => ( -
{ - setSelectedNotifycationId(data.id); setSelectedNotifycationType(data.type); setSelectedNotifycationSenderName((data.data as any)?.sender_name ?? null);setSelectedNotifycationSenderId((data.data as any)?.sender_id ?? null)}} + onClick={() => { + setSelectedNotifycationId(data.id) + setSelectedNotifycationType(data.type) + if (data.type === 'invite') { + // 엔빵 초대 알림일 경우 + setSelectedNotifycationSenderName( + (data.data as any)?.nbreadTitle ?? null, + ) + setSelectedNotifycationSenderId( + (data.data as any)?.nbreadId ?? null, + ) + } else if (data.type === 'friend_request') { + // 친구 요청 알림일 경우 + setSelectedNotifycationSenderName( + (data.data as any)?.sender_name ?? null, + ) + setSelectedNotifycationSenderId( + (data.data as any)?.sender_id ?? null, + ) + } + }} >
{data.title}
@@ -115,13 +141,27 @@ const Page = () => { ))}
{setIsAcceptModalOpen(false); setSelectedNotifycationType(null)}} - senderUserName={selectedNotifycationSenderName} - receiverId={userData?.id as string} - /> + senderUserId={selectedNotifycationSenderId} + id={selectedNotifycationId} + isOpen={isAcceptModalOpen} + onClose={() => { + setIsAcceptModalOpen(false) + setSelectedNotifycationType(null) + }} + senderUserName={selectedNotifycationSenderName} + receiverId={userData?.id as string} + /> + { + setIsInviteAcceptModalOpen(false) + setSelectedNotifycationType(null) + }} + senderNbreadId={selectedNotifycationSenderId} + senderNbreadTitle={selectedNotifycationSenderName} + receiverId={userData?.id as string} + />
) } diff --git a/src/components/invite/InviteAcceptModal.tsx b/src/components/invite/InviteAcceptModal.tsx new file mode 100644 index 0000000..5adb893 --- /dev/null +++ b/src/components/invite/InviteAcceptModal.tsx @@ -0,0 +1,47 @@ +import Modal from '../common/modal/Modal' +import { updateAcceptInvite } from '@/lib/invite/updateInvite' +import { updateRejectedInvite } from '@/lib/invite/updateInvite' +interface InviteAcceptModalProps { + id: number | null + isOpen: boolean + onClose: () => void + senderNbreadTitle: string | null + senderNbreadId: string | null + receiverId: string +} +const InviteAcceptModal = ({isOpen,onClose,senderNbreadTitle,senderNbreadId,receiverId} : InviteAcceptModalProps) => { + const fetchInviteAccept = async () => { + const acceptInviteData = await updateAcceptInvite(receiverId,senderNbreadId) + onClose() + } + const fetchInviteReject = async () => { + const rejectInviteData = await updateRejectedInvite(receiverId,senderNbreadId) + onClose() + } + return ( + +
+
+
엔빵 초대를 수락하시겠어요?
+

+ {senderNbreadTitle}의 초대를 수락하시겠어요? +

+
+
+ + +
+
+
+ ) +} +export default InviteAcceptModal diff --git a/src/components/invite/InviteBottomSheet.tsx b/src/components/invite/InviteBottomSheet.tsx index 798634d..0ab057d 100644 --- a/src/components/invite/InviteBottomSheet.tsx +++ b/src/components/invite/InviteBottomSheet.tsx @@ -5,102 +5,45 @@ import InviteUserListItem from './InviteUserListItem' import DefaultAvatar from '@/assets/avatar.svg' import { getInviteUser } from '@/lib/invite/getInviteUser' import { useParams } from 'next/navigation' +import { getFriendList } from '@/lib/friend/getSearchFriend' +import { getInviteFriendList } from '@/lib/friend/getSearchFriend' interface InviteBottomSheetProps { isOpen: boolean onClose: () => void + user: string | null } interface User { avatar: any name: string status: string + userId: string } -const InviteBottomSheet = ({ isOpen, onClose }: InviteBottomSheetProps) => { +interface Friend { + name: string + profileImage: string + inviteState?:string + tag: string + id:string + +} +const InviteBottomSheet = ({ isOpen, onClose,user }: InviteBottomSheetProps) => { const [searchData, setSearchData] = useState('') // 검색칸 입력 데이터 const [fetchSearchData, setFetchSearchData] = useState([]) // Api 반환 데이터 const searchCache = useRef>({}) + const [friendListData, setFriendData] = useState([]) const params = useParams() const [nbreadId, setNbreadId] = useState('') - - const userFollowingData = [ - { id: 0, avatar: DefaultAvatar, name: '유성현', status: '초대 하기' }, - { id: 1, avatar: DefaultAvatar, name: '신혜민', status: '초대 하기' }, - { id: 2, avatar: DefaultAvatar, name: '강보석', status: '초대 하기' }, - { - id: 3, - avatar: DefaultAvatar, - name: '송수빈', - status: '초대 하기', - }, - { - id: 4, - avatar: DefaultAvatar, - name: '빌게이츠', - status: '초대 완료', - }, - { - id: 5, - avatar: DefaultAvatar, - name: '이재용', - status: '참여 중', - }, - { - id: 6, - avatar: DefaultAvatar, - name: '머스크', - status: '초대 하기', - }, - { - id: 7, - avatar: DefaultAvatar, - name: '머스크', - status: '초대 하기', - }, - { - id: 8, - avatar: DefaultAvatar, - name: '머스크', - status: '초대 하기', - }, - { - id: 9, - avatar: DefaultAvatar, - name: '머스크', - status: '초대 하기', - }, - { - id: 10, - avatar: DefaultAvatar, - name: '머스크', - status: '초대 하기', - }, - { - id: 11, - avatar: DefaultAvatar, - name: '머스크', - status: '초대 하기', - }, - { - id: 12, - avatar: DefaultAvatar, - name: '머스크', - status: '초대 하기', - }, - { - id: 13, - avatar: DefaultAvatar, - name: '머스크', - status: '초대 하기', - }, - { - id: 14, - avatar: DefaultAvatar, - name: '머스크', - status: '초대 하기', - }, - ] + const [invitedUserId,setInvitedUserId] = useState('') + const fetchFriendList = async () => { + const fetchFriendListData = await getFriendList(user, params.nbreadId as string) + setFriendData(fetchFriendListData) + console.log('친구ㅡ 목 : ',friendListData) + } + useEffect(() => { if (isOpen) { setSearchData('') + fetchFriendList() } }, [isOpen]) @@ -118,12 +61,15 @@ const InviteBottomSheet = ({ isOpen, onClose }: InviteBottomSheetProps) => { } const apiDataRaw = (await getInviteUser(searchData, params.nbreadId as string)) || [] + console.log('검색 유저! : ',apiDataRaw) const apiData: User[] = apiDataRaw.map((u) => ({ avatar: u.profile_image, // profile_image → avatar로 매핑 name: u.name, status: u.status, - })) + userId:u.id, + })) +console.log('제발 상태야~~ :',apiData) // 캐시에 저장 console.log(apiData) searchCache.current[searchData] = apiData @@ -133,7 +79,23 @@ const InviteBottomSheet = ({ isOpen, onClose }: InviteBottomSheetProps) => { return () => clearTimeout(typingSearchData) } }, [searchData]) +const refreshLists = async () => { + // ✅ 1. 팔로잉 갱신 + await fetchFriendList() + // ✅ 2. 검색 결과 갱신 (검색어가 있을 때만) + if (searchData.length === 4) { + const apiDataRaw = await getInviteUser(searchData, params.nbreadId as string) || [] + const apiData: User[] = apiDataRaw.map((u) => ({ + avatar: u.profile_image, + name: u.name, + status: u.status, + userId: u.id, + })) + + setFetchSearchData(apiData) + } +} return ( <> @@ -165,9 +127,12 @@ const InviteBottomSheet = ({ isOpen, onClose }: InviteBottomSheetProps) => { {fetchSearchData.map((user, index) => ( ))}
@@ -177,12 +142,15 @@ const InviteBottomSheet = ({ isOpen, onClose }: InviteBottomSheetProps) => {

팔로잉

- {userFollowingData.map((user) => ( + {friendListData?.map((user) => ( ))}
diff --git a/src/components/invite/InviteUserListItem.tsx b/src/components/invite/InviteUserListItem.tsx index 37714d9..082d650 100644 --- a/src/components/invite/InviteUserListItem.tsx +++ b/src/components/invite/InviteUserListItem.tsx @@ -1,28 +1,67 @@ import DefaultAvatar from '@/assets/avatar.svg' import Avatar from '../common/avatar/avatar' +import { sendInviteRequest } from '@/lib/invite/sendInviteRequest' +import { useEffect } from 'react' +import { useState } from 'react' interface InviteUserData { avatar: string | null name: string status: string + nbreadId: string + invitedUserId: string + onRefresh?: () => void } -const InviteUserListItem = ({ avatar, name, status }: InviteUserData) => { - const getInviteUserStatus = (status: string) => { - switch (status) { - case '초대 하기': - return { color: 'text-system-blue01', cursor: 'cursor-pointer' } - case '참여 중': - return { color: 'text-gray-400', cursor: null } - case '초대 완료': - return { color: 'text-gray-400', cursor: null } - default: - return { color: 'text-black', cursor: 'cursor-pointer' } +const InviteUserListItem = ({ avatar, name, status,nbreadId,invitedUserId,onRefresh }: InviteUserData) => { + const [sendStatus, setSendStatus] = useState(status) + const [color, setColor] = useState('') + const [cursor, setCursor] = useState('') + // const getInviteUserStatus = (status: string) => { + // switch (status) { + // case '초대 하기': + // return { color: 'text-system-blue01', cursor: 'cursor-pointer' } + // case '참여 중': + // return { color: 'text-gray-400', cursor: null } + // case '초대 완료': + // return { color: 'text-gray-400', cursor: null } + // default: + // return { color: 'text-black', cursor: 'cursor-pointer' } + // } + // } + useEffect(() => { + if (status == '초대 완료') { + setSendStatus('초대 완료') + setColor('text-gray-400') + setCursor('cursor-default') } - } - const { color, cursor } = getInviteUserStatus(status) + else if(status =='초대 하기'){ + setSendStatus('초대 하기') + setColor('text-system-blue01') + setCursor('cursor-pointer') + } + else if(status =='rejected') { + setSendStatus('초대 하기') + setColor('text-system-blue01') + setCursor('cursor-pointer') + } + else { + setSendStatus('') + setColor('') + setCursor('') + } + }, [status]) + // const { color, cursor } = getInviteUserStatus(status) - const handleClick = (status: string) => { - if (status == '초대 하기') { + const handleClick = async(status: string) => { + if (status == '초대 하기' || status == 'rejected') { + console.log('glgl',status) + console.log('현재 엔빵 아디: ',nbreadId) + console.log('초대보낼 유저 아이디 : ', invitedUserId) + const fetchInvite = await sendInviteRequest(nbreadId,invitedUserId,'pending') console.log('초대 보냄') + setSendStatus('요청 완료') + setColor('text-gray-400') + setCursor('cursor-default') + if (onRefresh) onRefresh() } } return ( @@ -45,7 +84,7 @@ const InviteUserListItem = ({ avatar, name, status }: InviteUserData) => { className={`${color} text-body01 ${cursor}`} onClick={() => handleClick(status)} > - {status} + {sendStatus}

diff --git a/src/components/nbread/NbreadDetail.tsx b/src/components/nbread/NbreadDetail.tsx index af4d1c2..08d9518 100644 --- a/src/components/nbread/NbreadDetail.tsx +++ b/src/components/nbread/NbreadDetail.tsx @@ -19,7 +19,7 @@ import useUserStore from '@/stores/useAuthStore' import QuitNbreadModal from '@/components/common/modal/QuitNbreadModal' import Spinner from '@/components/common/spinner/Spinner' import InviteBottomSheet from '@/components/invite/InviteBottomSheet' - +import { getFriendList } from '@/lib/friend/getSearchFriend' interface nbreadDetailProps { nbreadData: Nbread setNbreadData: Dispatch> @@ -207,6 +207,7 @@ const nbreadDetail = ({ nbreadData, setNbreadData }: nbreadDetailProps) => { setIsInviteBottomSheetOpen(false)} + user={userData?.id ?? null} /> { })) } catch (error) {} } -export const getFriendList = async (user: string | null) => { +export const getFriendList = async ( + user: string | null, + nbreadId: string | null, +) => { if (!user) return try { const { data, error } = await supabase @@ -42,31 +45,79 @@ export const getFriendList = async (user: string | null) => { const friends = data?.map((f) => (f.user_id_1 === user ? f.user_id_2 : f.user_id_1)) || [] - console.log('친구리스트 목록', friends) - // return friends if (friends) { const { data, error } = await supabase .from('user') - .select('name,profile_image,tag') + .select('name,profile_image,tag,id') .eq('id', friends) - if(error) { - console.error('error~~~~ : ',error) + if (error) { + console.error('error~~~~ : ', error) + return + } + const friendInfoList = data || [] + + // 필요에 따라 map으로 구조 변환 + let processedFriends = friendInfoList.map((f) => ({ + name: f.name, + profileImage: f.profile_image, + tag: f.tag, + id: f.id, + })) + + const friendIds = processedFriends.map((f) => f.id) + console.log('친구id', friendIds) + console.log('nbread_id : ', nbreadId) + let inviteData: any[] = [] + if (nbreadId) { + const { data, error } = await supabase + .from('nbread_invite') + .select('state,invited_user_id') + .in('invited_user_id', friendIds) + .eq('nbread_id', nbreadId) + if (error) { + console.error('error~~', error) return } - const friendInfoList = data || [] + console.log('state : ', data) + inviteData = data || [] + const mergedFriends = processedFriends.map((friend) => { + const invite = inviteData.find((i) => i.invited_user_id === friend.id) + return { + ...friend, + inviteState: invite + ? invite.state === 'pending' + ? '초대 완료' // ✅ pending → 초대 완료로 변환 + : invite.state // 그 외 상태는 그대로 유지 + : '초대 하기', // 초대 기록 없으면 null + } + }) + return mergedFriends + } - // 필요에 따라 map으로 구조 변환 - const processedFriends = friendInfoList.map(f => ({ - name: f.name, - profileImage: f.profile_image, - tag: f.tag - })) - return processedFriends + return processedFriends } } catch (error) { console.error(error) return [] } - return [] + // return [] +} +export const getInviteFriendList = async ( + userId: string, + inviteNbreadId: string, +) => { + try { + const { data, error } = await supabase + .from('nbread_invite') + .select('invited_user_id,nbread_id,state') + .eq('invited_user_id', userId) + .eq('nbread_id', inviteNbreadId) + + if (!data) { + console.error('error : ', error) + return + } + return data + } catch (error) {} } diff --git a/src/lib/invite/getInviteUser.ts b/src/lib/invite/getInviteUser.ts index a84c9c1..a0833a4 100644 --- a/src/lib/invite/getInviteUser.ts +++ b/src/lib/invite/getInviteUser.ts @@ -27,18 +27,21 @@ export const getInviteUser = async (tag: string, nbreadId: string) => { console.log('nbreadData',nbreadData) const { data: inviteData } = await supabase - .from('invite') - .select('status') - .eq('user_id', user.id) + .from('nbread_invite') + .select('state') + .eq('invited_user_id', user.id) .eq('nbread_id', nbreadId) .maybeSingle() // 없으면 null 반환 - + console.log('검색한 유저 데이터 :' ,inviteData) let status = '초대 하기' - if(nbreadData) { + if(nbreadData === 'accept') { status = '참여 중' } - else if(inviteData) { - status = inviteData.status + else if(inviteData?.state == 'pending') { + status = '초대 완료' + } + else if(inviteData?.state == 'reject') { + status = '초대 하기' } const result = { ...user, diff --git a/src/lib/invite/sendInviteRequest.ts b/src/lib/invite/sendInviteRequest.ts new file mode 100644 index 0000000..91021f4 --- /dev/null +++ b/src/lib/invite/sendInviteRequest.ts @@ -0,0 +1,60 @@ +import { supabase } from "../supabaseClient"; + +export const sendInviteRequest = async (nbreadId:string,invitedUserId:string,state:string) => { + try { + // const {data, error} = await supabase.from('nbread_invite').insert( + // [ + // { + // nbread_id: nbreadId, + // invited_user_id: invitedUserId, + // state: "pending" + // }, + // ], + // ) + const { data, error } = await supabase + .from('nbread_invite') + .select('state') + .eq('nbread_id',nbreadId) + .eq('invited_user_id',invitedUserId) + if (error) { + console.error('error : ', error) + return + } + console.log('data', data) + // return data + if (!data || data.length === 0) { + // 데이터 없으면 insert + const { data: insertedData, error } = await supabase + .from('nbread_invite') + .insert([ + { + nbread_id: nbreadId, + invited_user_id: invitedUserId, + state: state, + }, + ]) + .select('state') + + if (error) console.error(error) + return insertedData + } else if (data.some((item) => item.state === 'rejected')) { + // 기존 데이터 중 rejected이면 update + const { data: updatedData, error } = await supabase + .from('nbread_invite') + .update({ state }) + .eq('nbread_id',nbreadId) + .eq('invited_user_id',invitedUserId) + .select('state') + + if (error) console.error(error) + return updatedData + } + + // 이미 pending이나 accepted 상태라면 그대로 반환 + return data + if(error) throw error + return data + } catch (error) { + console.error("초대 요청 중 오류 발생:", error) + } +} \ No newline at end of file diff --git a/src/lib/invite/updateInvite.ts b/src/lib/invite/updateInvite.ts new file mode 100644 index 0000000..84016a9 --- /dev/null +++ b/src/lib/invite/updateInvite.ts @@ -0,0 +1,53 @@ +import { supabase } from "../supabaseClient" +export const updateAcceptInvite = async ( + receiverId: string, + senderId: string | null, +) => { + let paymentDate = null; + const { data, error } = await supabase + .from('nbread_invite') + .update({ state: 'accepted' }) + .eq('nbread_id', senderId) + .eq('invited_user_id', receiverId) + + if (error) { + console.error('초대 수락 업데이트 실패!', error) + return null + } + console.log('data', data) + if(!error){ + const {data,error} = await supabase.from('nbread_records').select('payment_date').eq('nbread_id',senderId) + + if(error) { + console.error('error : ',error) + return + } + console.log('초대 받은 엔빵 데이터 : ',data) + paymentDate = data?.[0]?.payment_date ?? null + } + if (!error) { + const { data, error } = await supabase + .from('participant') + .insert([{ nbread_id:senderId,user_id:receiverId,is_leader:'FALSE'}]) + + if (error) { + console.error('엔빵 추가 에러 : ', error) + return null + } + console.log(data) + return data + } +} +export const updateRejectedInvite = async ( + receiverId: string, + senderId: string | null, +) => { + const { data, error } = await supabase + .from('nbread_invite') + .update({ state: 'rejected' }) + .eq('nbread_id', senderId) + .eq('invited_user_id', receiverId) + if(error) { + console.error('엔빵 거절 에러 : ',error) + } +} \ No newline at end of file diff --git a/src/lib/nbread/getUserNbread.ts b/src/lib/nbread/getUserNbread.ts index 55c00ad..b8d1388 100644 --- a/src/lib/nbread/getUserNbread.ts +++ b/src/lib/nbread/getUserNbread.ts @@ -10,12 +10,13 @@ export const getUserNbreads = async (userId: string): Promise => { .from('participant') .select('nbread_id') .eq('user_id', userId) - + if (participantError) { console.error( '❌ Failed to fetch participant entries:', participantError.message, ) + return [] } diff --git a/src/lib/notification/getNotifications.ts b/src/lib/notification/getNotifications.ts index 5f0c571..37610a1 100644 --- a/src/lib/notification/getNotifications.ts +++ b/src/lib/notification/getNotifications.ts @@ -32,6 +32,7 @@ export const getNotification = async (userId: string) => { is_read: notification.is_read, }), ) + console.log('notificationsType : ',notifications) return notifications } catch (error) { console.error('Error fetching nbread:', error) From 5e6d6325b3bfed0e75513fe7c4e660d2088c5f02 Mon Sep 17 00:00:00 2001 From: Hyun9811 <145583411+Hyun9811@users.noreply.github.com> Date: Tue, 6 Jan 2026 18:55:58 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=EC=97=94=EB=B9=B5=20=EC=B4=88?= =?UTF-8?q?=EB=8C=80=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/invite/InviteAcceptModal.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/invite/InviteAcceptModal.tsx b/src/components/invite/InviteAcceptModal.tsx index 5adb893..85a9e0c 100644 --- a/src/components/invite/InviteAcceptModal.tsx +++ b/src/components/invite/InviteAcceptModal.tsx @@ -1,4 +1,5 @@ import Modal from '../common/modal/Modal' +import { useRouter } from 'next/navigation' import { updateAcceptInvite } from '@/lib/invite/updateInvite' import { updateRejectedInvite } from '@/lib/invite/updateInvite' interface InviteAcceptModalProps { @@ -10,9 +11,12 @@ interface InviteAcceptModalProps { receiverId: string } const InviteAcceptModal = ({isOpen,onClose,senderNbreadTitle,senderNbreadId,receiverId} : InviteAcceptModalProps) => { + const router = useRouter() const fetchInviteAccept = async () => { const acceptInviteData = await updateAcceptInvite(receiverId,senderNbreadId) onClose() + router.push(`/nbread/${senderNbreadId}`) + } const fetchInviteReject = async () => { const rejectInviteData = await updateRejectedInvite(receiverId,senderNbreadId)