Skip to content

Commit

Permalink
🐛 거래성사 제안/수락 버그 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
juyeon-park committed Nov 27, 2023
1 parent 96a89b4 commit 4d43b64
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Image from 'next/image'
import Assets from '@/config/assets'

const PokeUnavailableInfo = () => {
return (
<div className="flex flex-col items-center justify-start gap-4 p-8">
<Image
width={200}
height={200}
alt="unavailable"
src={Assets.unavailableIcon}
/>
<p className="text-sm font-normal">찔러보기가 허용되지 않은 물건입니다</p>
</div>
)
}

export default PokeUnavailableInfo
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import Image from 'next/image'
import { useRouter } from 'next/navigation'
import SuggestCard from '@/components/domain/card/suggest-card'
import NoData from '@/components/domain/no-data'
import { Tabs, TabsTrigger, TabsList, TabsContent } from '@/components/ui/tabs'
import Assets from '@/config/assets'
import { AvailableCardSuggestionListRes } from '@/services/suggestion/suggestion'
import PokeUnavailableInfo from './PokeUnavailableInfo'

type SuggestListProps = {
suggestionData: AvailableCardSuggestionListRes[]
pokeAvailable: boolean
toCardId: number
}

/**
* TODO : 스크롤바 디자인 수정
*/
const SuggestList = ({
suggestionData,
pokeAvailable,
toCardId,
}: SuggestListProps) => {
const router = useRouter()
const filterData = (type: string) => {
return suggestionData.filter(
(v) => v.suggestionInfo.suggestionType === type,
)
}

return (
<Tabs defaultValue="OFFER">
<TabsList>
Expand All @@ -31,33 +36,29 @@ const SuggestList = ({
className="flex flex-col data-[state=inactive]:hidden h-[402px] overflow-y-auto"
>
{!pokeAvailable && type === 'POKE' ? (
<div className="flex flex-col items-center justify-start gap-4 p-8">
<Image
width={200}
height={200}
alt="unavailable"
src={Assets.unavailableIcon}
<PokeUnavailableInfo />
) : filterData(type).length ? (
filterData(type).map((v) => (
<SuggestCard
key={v.cardInfo.cardId}
thumbnail={v.cardInfo.thumbnail}
cardTitle={v.cardInfo.cardTitle}
itemName={v.cardInfo.itemName}
priceRange={v.cardInfo.priceRange}
suggestionType={v.suggestionInfo.suggestionType}
fromCardId={v.cardInfo.cardId}
toCardId={toCardId}
suggestionStatus={v.suggestionInfo.suggestionStatus}
/>
<p className="text-sm font-normal">
찔러보기가 허용되지 않은 물건입니다
</p>
</div>
))
) : (
suggestionData
.filter((v) => v.suggestionInfo.suggestionType === type)
.map((v) => (
<SuggestCard
key={v.cardInfo.cardId}
thumbnail={v.cardInfo.thumbnail}
cardTitle={v.cardInfo.cardTitle}
itemName={v.cardInfo.itemName}
priceRange={v.cardInfo.priceRange}
suggestionType={v.suggestionInfo.suggestionType}
fromCardId={v.cardInfo.cardId}
toCardId={toCardId}
suggestionStatus={v.suggestionInfo.suggestionStatus}
/>
))
<div className="h-full relative">
<NoData
title="제안 가능한 내 물건이 없습니다."
onClickButton={() => router.push('/cards/new')}
buttonContent="물건 등록하러 가기"
/>
</div>
)}
</TabsContent>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import AppPath from '@/config/appPath'
import Assets from '@/config/assets'
import { PRICE_RANGE_OBJS, TRADE_TYPE_OBJS } from '@/constants/card'
import { useAuth } from '@/contexts/AuthProvider'
Expand Down Expand Up @@ -77,7 +78,7 @@ const TradeSection = ({

const onClickButton = async () => {
if (isMyItem) {
router.push(`/mypage/suggestions/${cardId}`)
router.push(AppPath.mySuggestions(cardId))
} else {
setOpen(true)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client'

import { useState } from 'react'
import Image from 'next/image'
import Button from '@/components/ui/button'
import {
Expand All @@ -22,9 +23,12 @@ const CompleteRequestButton = ({
myCardId,
otherCardId,
}: CompleteRequestButtonProps) => {
const [isCompleteRequested, setIsCompleteRequested] = useState(false)

const handleRequestButton = async () => {
try {
await postCompleteRequest(myCardId, otherCardId)
setIsCompleteRequested(true)
toast({
title: '거래성사를 요청하였습니다',
variant: 'default',
Expand All @@ -42,9 +46,11 @@ const CompleteRequestButton = ({
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button className="ml-auto" size="icon_sm" variant={null}>
<Image src={Assets.vMoreIcon} alt="more" />
</Button>
{!isCompleteRequested && (
<Button className="ml-auto" size="icon_sm" variant={null}>
<Image src={Assets.vMoreIcon} alt="more" />
</Button>
)}
</DropdownMenuTrigger>
<DropdownMenuContent className="min-w-[8rem]">
<DropdownMenuGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
'use client'

import { useState } from 'react'
import Image from 'next/image'
import Badge from '@/components/ui/badge'
import Button from '@/components/ui/button'
import { Card, CardFlex, CardImage, CardText } from '@/components/ui/card/Card'
import Assets from '@/config/assets'
Expand Down Expand Up @@ -35,14 +39,15 @@ const CompleteRequestCard = ({
myCardData,
otherCardData,
}: CompleteRequestCardProps) => {
const [completeRequestStatus, setCompleteRequestStatus] = useState('')
const handleCompleteRequestUpdate = async (isAccepted: boolean) => {
try {
await putCompleteRequest(
otherCardData.cardId,
myCardData.cardId,
isAccepted,
)
window.location.reload()
setCompleteRequestStatus(isAccepted ? '거래성사 확정' : '거래성사 거절')
toast({
title: `거래성사 요청을 ${isAccepted ? '수락' : '거절'}하였습니다.`,
variant: 'default',
Expand Down Expand Up @@ -71,24 +76,30 @@ const CompleteRequestCard = ({
>
거래성사 요청이 왔습니다. 거래를 하셨나요?
</CardText>
<CardFlex direction={'row'} gap={'space'}>
<Button
className="ml-auto"
size="icon_sm"
variant={null}
onClick={() => handleCompleteRequestUpdate(true)}
>
<Image src={Assets.checkCircle} alt="accept" />
</Button>
<Button
className="ml-auto"
size="icon_sm"
variant={null}
onClick={() => handleCompleteRequestUpdate(false)}
>
<Image src={Assets.quitCircle} alt="refuse" />
</Button>
</CardFlex>
{completeRequestStatus === '' ? (
<CardFlex direction={'row'} gap={'space'}>
<Button
className="ml-auto"
size="icon_sm"
variant={null}
onClick={() => handleCompleteRequestUpdate(true)}
>
<Image src={Assets.checkCircle} alt="accept" />
</Button>
<Button
className="ml-auto"
size="icon_sm"
variant={null}
onClick={() => handleCompleteRequestUpdate(false)}
>
<Image src={Assets.quitCircle} alt="refuse" />
</Button>
</CardFlex>
) : (
<Badge variant={'gradation'} size={'sm'}>
{completeRequestStatus}
</Badge>
)}
</CardFlex>
<CardItem
thumbnail={otherCardData.thumbnail}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ const CompleteReqeustTemplate = ({
currentUser,
completeRequestData: { fromCard, toCard, status },
}: CompleteReqeustTemplateProps) => {
//NOTE - 현재 로그인한 사람이 거래성사 요청 받은 사람인경우 + 요청 상태가 waiting인 경우 - 거래성사요청 카드가 보인다.
const isRequestedUser =
toCard.userInfo.userId === currentUser.userId && status === 'WAITING'
return isRequestedUser ? (
<CompleteRequestCard
myCardData={fromCard.cardInfo}
otherCardData={toCard.cardInfo}
myCardData={toCard.cardInfo}
otherCardData={fromCard.cardInfo}
/>
) : (
<Badge variant={'gradation'} size={'lg'} className="self-end mr-4">
Expand Down
2 changes: 1 addition & 1 deletion src/app/(root)/(routes)/chatrooms/[chatRoomId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const ChatPage = async ({ params }: ChatPageProps) => {
initialChatRoom.fromCardInfo,
initialChatRoom.toCardInfo,
]
console.log(suggestionDataArray)

const myCardId = suggestionDataArray.find(
(obj) => obj.userInfo.userId === initialUserInfo.userId,
).cardInfo.cardId
Expand Down
5 changes: 1 addition & 4 deletions src/hooks/api/mutations/useCardStatusUpdateMutation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
import Cookies from 'js-cookie'
import { Environment } from '@/config/environment'
import { toast } from '@/hooks/useToast'
import { putCardStatus } from '@/services/card/card'
import { TradeStatusObjs } from '@/types/card'
Expand All @@ -10,9 +8,8 @@ const useCardStatusUpdateMutation = (
status: TradeStatusObjs['key'],
) => {
const queryClient = useQueryClient()
const token = Cookies.get(Environment.tokenName())

const queryKey = [cardId, 'cardInfo', token]
const queryKey = [cardId, 'cardInfo']
return useMutation({
mutationFn: putCardStatus,
onMutate: async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/complete-request/completeRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const putCompleteRequest = async (
toCardId: number,
isAccepted: boolean,
) => {
const response = await apiClient.post(
const response = await apiClient.put(
ApiEndPoint.putCompleteRequest(),
{ fromCardId, toCardId, isAccepted },
{},
Expand Down

0 comments on commit 4d43b64

Please sign in to comment.