Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐ŸŽ‰ ๊ฑฐ๋ž˜์„ฑ์‚ฌ์š”์ฒญ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์™„๋ฃŒ #98

Merged
merged 11 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions public/images/check-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions public/images/quit-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/app/(root)/(routes)/chat/components/CompleteRequestSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import CompleteRequestCard from './complete-request-card/CompleteRequestCard'

type CompleteReqeustSectionProps = {
completeRequestId: number
}

const CompleteReqeustSection = ({
completeRequestId,
}: CompleteReqeustSectionProps) => {
/**
* TODO - ์ฑ„ํŒ…๋ฐฉ ๋‹จ๊ฑด์กฐํšŒ์—์„œ ์–ป์€ completeRequestId๋กœ ๊ฑฐ๋ž˜์„ฑ์‚ฌ ์š”์ฒญ api ํ˜ธ์ถœ ์ถ”๊ฐ€
* TODO - ํ˜„์žฌ ๋กœ๊ทธ์ธํ•œ ์‚ฌ๋žŒ์ด toCardID์˜ userId์™€ ๊ฐ™์€ ๊ฒฝ์šฐ + status๊ฐ€ WAITING์ธ ๊ฒฝ์šฐ CompleteRequestCard๊ฐ€ ๋ณด์ž„
* TODO - ํ˜„์žฌ ๋กœ๊ทธ์ธํ•œ ์‚ฌ๋žŒ์ด fromCardID์˜ userId์™€ ๊ฐ™์€ ๊ฒฝ์šฐ ๋ฐฐ์ง€๊ฐ€ ๋ณด์ž„
*
*/
return <CompleteRequestCard />
}

export default CompleteReqeustSection
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Image from 'next/image'
import Button from '@/components/ui/button'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import Assets from '@/config/assets'

interface CompleteRequestButtonProps {
onClickButton: () => Promise<void>
}

const CompleteRequestButton = ({
onClickButton,
}: CompleteRequestButtonProps) => {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button className="ml-auto" size="icon_sm" variant={null}>
<Image src={Assets.vMoreIcon} alt="more" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="min-w-[8rem]">
<DropdownMenuGroup>
<DropdownMenuItem onClick={onClickButton}>
๊ฑฐ๋ž˜์„ฑ์‚ฌ ์š”์ฒญ
</DropdownMenuItem>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
)
}
export default CompleteRequestButton
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Image from 'next/image'
import Button from '@/components/ui/button'
import { Card, CardFlex, CardImage, CardText } from '@/components/ui/card/Card'
import Assets from '@/config/assets'
import { Card as CardType } from '@/types/card'

const CardItem = ({
thumbnail,
itemName,
}: Pick<CardType, 'thumbnail' | 'itemName'>) => (
<CardFlex direction={'col'} justify={'center'} align={'center'} gap={'space'}>
<div className="h-11 w-20 relative">
<CardImage
alt="card-thumbnail"
src={thumbnail}
layout="fill"
objectFit="cover"
className="rounded"
/>
</div>
<CardText className="font-bold text-[12px] whitespace-nowrap overflow-hidden overflow-ellipsis">
{itemName}
</CardText>
</CardFlex>
)

const CompleteRequestCard = () => {
return (
<div>
<Card className="p-2 flex items-center border-0" size={'sm'}>
<CardFlex justify={'between'} className="gap-4">
<CardItem
thumbnail={
'https://team-01-bucket.s3.ap-northeast-2.amazonaws.com/633faaee-0210-4ffb-8085-569374a26d70-214e000d15fc5a3a.jpeg'
}
itemName={'์กฐ์„ธํ˜ธ ์งค'}
/>
<CardFlex direction={'col'} align={'center'} justify={'center'}>
<CardText
type={'description'}
className="text-[12px] max-w-[125px] text-center"
>
๊ฑฐ๋ž˜์„ฑ์‚ฌ ์š”์ฒญ์ด ์™”์Šต๋‹ˆ๋‹ค. ๊ฑฐ๋ž˜๋ฅผ ํ•˜์…จ๋‚˜์š”?
</CardText>
<CardFlex direction={'row'} gap={'space'}>
<Button className="ml-auto" size="icon_sm" variant={null}>
<Image src={Assets.checkCircle} alt="accept" />
</Button>
<Button className="ml-auto" size="icon_sm" variant={null}>
<Image src={Assets.quitCircle} alt="refuse" />
</Button>
</CardFlex>
</CardFlex>
<CardItem
thumbnail={
'https://team-01-bucket.s3.ap-northeast-2.amazonaws.com/fdd01120-4443-4643-9d6b-6140b75d0b98-230222112308_1_3034298.jpeg'
}
itemName={'๊ฐค๋Ÿญ์‹œ23'}
/>
</CardFlex>
</Card>
</div>
)
}

export default CompleteRequestCard
25 changes: 23 additions & 2 deletions src/app/(root)/(routes)/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { useAuth } from '@/contexts/AuthProvider'
import useFirestoreQuery from '@/hooks/useFirestoreQuery'
import { useToast } from '@/hooks/useToast'
import { getMessageRef } from '@/lib/firebase'
import { postCompleteRequest } from '@/services/card/card'
import ChatInput from './components/ChatInput'
import ChatList from './components/ChatList'
import CompleteReqeustSection from './components/CompleteRequestSection'
import CompleteRequestButton from './components/complete-request-button/CompleteRequestButton'

const ChatPage = () => {
const { currentUser } = useAuth()
Expand Down Expand Up @@ -46,9 +49,27 @@ const ChatPage = () => {
}
}

const handleRequestButton = async () => {
try {
await postCompleteRequest(1, 2) //FIXME - api ๋‚˜์˜ค๋ฉด ์‹ค์ œ cardId๋กœ ๋ณ€๊ฒฝ ์˜ˆ์ •
} catch (error) {
toast({
title: '๊ฑฐ๋ž˜์„ฑ์‚ฌ ์š”์ฒญ์ด ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.',
variant: 'destructive',
duration: 2000,
})
}
}
//TODO - completeRequestId๊ฐ€ null์ด ์•„๋‹Œ ๊ฒฝ์šฐ๋Š” CompleteRequestButton์ด ๋ณด์ด์ง€ X
//TODO - completeRequestId๊ฐ€ null์ธ ๊ฒฝ์šฐ CompleteRequestSection์ด ๋ณด์ด์ง€ X

return (
<main className="relative flex flex-col items-center w-full gap-10 h-page pb-chat_input">
<PageTitle title="์ฑ„ํŒ…๋ฐฉ" />
<main className="relative flex flex-col items-center w-full gap-4 h-page pb-chat_input">
<header className="w-full flex flex-row items-center px-4">
<PageTitle title="์ฑ„ํŒ…๋ฐฉ" />
<CompleteRequestButton onClickButton={handleRequestButton} />
</header>
<CompleteReqeustSection completeRequestId={1} />
<section className="flex flex-col items-center px-2 overflow-scroll overflow-x-hidden">
<ChatList
messages={messages}
Expand Down
4 changes: 4 additions & 0 deletions src/config/apiEndPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const ApiEndPoint = {
putCardStatus: (cardId: number) => `/cards/status/${cardId}`,
getPopularCardList: () => '/cards/popular',
putMySuggestionStatus: () => `/suggestions/decision`,
getCompleteRequest: (completeRequestId: number) =>
`/complete-reqeusts/${completeRequestId}`,
postCompleteRequest: () => '/complete-requests',
putCompleteRequest: () => '/complete-requests/confirm',
} as const

export default ApiEndPoint
7 changes: 7 additions & 0 deletions src/constants/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ const CATEGORY_BUTTON_LIST = [
{ key: 'ALL_CARD', value: '์ „์ฒด๋ณด๊ธฐ', image: Assets.allCardIcon },
] as const

const COMPLETE_REQUEST_TYPE_OBJS = [
{ key: 'WAITING', value: '๊ฑฐ๋ž˜์„ฑ์‚ฌ ๋Œ€๊ธฐ์ค‘' },
{ key: 'ACCEPTED', value: '๊ฑฐ๋ž˜์„ฑ์‚ฌ ํ™•์ •' },
{ key: 'REFUSED', value: '๊ฑฐ๋ž˜์„ฑ์‚ฌ ๊ฑฐ์ ˆ๋จ' },
]

export {
PRICE_RANGE,
CATEGORY,
Expand All @@ -109,4 +115,5 @@ export {
CATEGORY_OBJS,
TRADE_TYPE_OBJS,
TRADE_STATUS_OBJS,
COMPLETE_REQUEST_TYPE_OBJS,
}
48 changes: 48 additions & 0 deletions src/services/card/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
TradeStatus,
PriceRangeObjs,
TradeStatusObjs,
CompleteRequestTypeObjs,
} from '@/types/card'
import { User } from '@/types/user'
import apiClient from '../apiClient'
Expand Down Expand Up @@ -168,6 +169,50 @@ const putCardStatus = async ({ cardId, status }: PutCardStatusReq) => {
return response
}

const getCompleteRequest = async (
completeRequestId: number,
): Promise<{
data: {
fromCard: CardDetail
toCard: CardDetail
status: CompleteRequestTypeObjs['key']
}
}> => {
const response = await apiClient.get(
ApiEndPoint.getCompleteRequest(completeRequestId),
)

return response
}

const postCompleteRequest = async (fromCardId: number, toCardId: number) => {
const response = await apiClient.post(
ApiEndPoint.postCompleteRequest(),
{ fromCardId, toCardId },
{},
{
'Content-Type': 'application/json',
},
)
return response
}

const putCompleteRequest = async (
fromCardId: number,
toCardId: number,
isAccepted: boolean,
) => {
const response = await apiClient.post(
ApiEndPoint.putCompleteRequest(),
{ fromCardId, toCardId, isAccepted },
{},
{
'Content-Type': 'application/json',
},
)
return response
}

export {
getCardList,
getCardInfo,
Expand All @@ -180,4 +225,7 @@ export {
putCard,
getPopularCardList,
putCardStatus,
getCompleteRequest,
postCompleteRequest,
putCompleteRequest,
}
3 changes: 3 additions & 0 deletions src/types/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PRICE_RANGE_OBJS,
TRADE_STATUS_OBJS,
TRADE_TYPE_OBJS,
COMPLETE_REQUEST_TYPE_OBJS,
} from '@/constants/card'

interface Card {
Expand Down Expand Up @@ -51,6 +52,7 @@ type CategoryObjs = (typeof CATEGORY_OBJS)[number]
type PriceRangeObjs = (typeof PRICE_RANGE_OBJS)[number]
type TradeStatusObjs = (typeof TRADE_STATUS_OBJS)[number]
type TradeTypeObjs = (typeof TRADE_TYPE_OBJS)[number]
type CompleteRequestTypeObjs = (typeof COMPLETE_REQUEST_TYPE_OBJS)[number]

export type {
Category,
Expand All @@ -64,4 +66,5 @@ export type {
PriceRangeObjs,
TradeStatusObjs,
TradeTypeObjs,
CompleteRequestTypeObjs,
}