-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from js43o/render-detail-buttons
[Feat] 모각코 상세 게시글 페이지 API 일부 구현
- Loading branch information
Showing
12 changed files
with
265 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 46 additions & 41 deletions
87
app/frontend/src/components/MogacoDetail/DetailHeaderButtons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,60 @@ | ||
import { Button } from '@/components'; | ||
|
||
const buttonComponents = { | ||
participating: ( | ||
<Button theme="primary" shape="fill" size="large"> | ||
참석하기 | ||
</Button> | ||
), | ||
participated: ( | ||
<> | ||
<Button theme="primary" shape="fill" size="large"> | ||
채팅 | ||
</Button> | ||
<Button theme="danger" shape="fill" size="large"> | ||
참석 취소 | ||
</Button> | ||
</> | ||
), | ||
hosted: ( | ||
<> | ||
<Button theme="primary" shape="line" size="large"> | ||
수정 | ||
</Button> | ||
<Button theme="danger" shape="line" size="large"> | ||
삭제 | ||
</Button> | ||
</> | ||
), | ||
closed: ( | ||
<Button theme="primary" shape="fill" size="large" disabled> | ||
마감 | ||
</Button> | ||
), | ||
}; | ||
import { mogaco } from '@/services'; | ||
|
||
type DetailHeaderButtonsProps = { | ||
id: string; | ||
userHosted: boolean; | ||
userParticipated: boolean; | ||
status: '모집 중' | '마감' | '종료'; | ||
}; | ||
|
||
export function DetailHeaderButtons({ status }: DetailHeaderButtonsProps) { | ||
const userHosted = false; | ||
const userParticipated = false; | ||
export function DetailHeaderButtons({ | ||
id, | ||
userHosted, | ||
userParticipated, | ||
status, | ||
}: DetailHeaderButtonsProps) { | ||
const onClickJoin = async () => { | ||
await mogaco.join(id); | ||
}; | ||
|
||
const onClickQuit = async () => { | ||
await mogaco.quit(id); | ||
}; | ||
|
||
if (userHosted) { | ||
return buttonComponents.hosted; | ||
return ( | ||
<> | ||
<Button theme="primary" shape="line" size="large"> | ||
수정 | ||
</Button> | ||
<Button theme="danger" shape="line" size="large"> | ||
삭제 | ||
</Button> | ||
</> | ||
); | ||
} | ||
|
||
if (status === '모집 중') { | ||
return userParticipated | ||
? buttonComponents.participated | ||
: buttonComponents.participating; | ||
return userParticipated ? ( | ||
<> | ||
<Button theme="primary" shape="fill" size="large"> | ||
채팅 | ||
</Button> | ||
<Button theme="danger" shape="fill" size="large" onClick={onClickQuit}> | ||
참석 취소 | ||
</Button> | ||
</> | ||
) : ( | ||
<Button theme="primary" shape="fill" size="large" onClick={onClickJoin}> | ||
참석하기 | ||
</Button> | ||
); | ||
} | ||
|
||
return buttonComponents.closed; | ||
return ( | ||
<Button theme="primary" shape="fill" size="large" disabled> | ||
마감 | ||
</Button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { Mogaco } from '@/types'; | ||
import { useState, useEffect } from 'react'; | ||
|
||
import { mogaco } from '@/services'; | ||
import { useUserAtom } from '@/stores'; | ||
import { Mogaco, Participant } from '@/types'; | ||
|
||
import { DetailContents } from './DetailContents'; | ||
import { DetailHeader } from './DetailHeader'; | ||
|
@@ -8,19 +12,60 @@ import * as styles from './index.css'; | |
type MogacoDetailProps = Mogaco; | ||
|
||
export function MogacoDetailPage({ | ||
id, | ||
memberId, | ||
title, | ||
maxHumanCount, | ||
participantList, | ||
date, | ||
address, | ||
contents, | ||
status, | ||
}: MogacoDetailProps) { | ||
const [participantList, setParticipantList] = useState<Participant[] | null>( | ||
null, | ||
); | ||
const [user, setUser] = useUserAtom(); | ||
|
||
if (!user) | ||
setUser({ | ||
providerId: '1', | ||
nickname: '지승', | ||
profilePicture: | ||
'https://avatars.githubusercontent.com/u/50646827?s=40&v=4', | ||
email: '[email protected]', | ||
}); | ||
|
||
const userHosted = user?.providerId === memberId; | ||
const userParticipated = participantList | ||
? !!participantList.find( | ||
(participant) => participant.id === user?.providerId, | ||
) | ||
: false; | ||
|
||
useEffect(() => { | ||
if (participantList) { | ||
return; | ||
} | ||
|
||
const getParticipantList = async () => { | ||
const data = await mogaco.participants(id); | ||
setParticipantList(data); | ||
}; | ||
|
||
getParticipantList(); | ||
}, [id, participantList]); | ||
|
||
return ( | ||
<div className={styles.wrapper}> | ||
<div className={styles.container}> | ||
<DetailHeader title={title} status={status} memberId={memberId} /> | ||
<DetailHeader | ||
id={id} | ||
title={title} | ||
status={status} | ||
memberId={memberId} | ||
userHosted={userHosted} | ||
userParticipated={userParticipated} | ||
/> | ||
<DetailInfo | ||
participantList={participantList} | ||
maxHumanCount={maxHumanCount} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.