-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/127/update detail page #130
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
Changes from all commits
d7f47f3
86350f2
6c2ffca
df466a7
a5f89a7
b49e833
847c188
4002590
a34d307
a518393
a196171
06db2a5
60d4a48
1759062
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| import { fetchApi } from '@/src/utils/api'; | ||
| import { User } from '@/src/types/auth'; | ||
|
|
||
| export function getUser(): Promise<{ data: User }> { | ||
| export function getUser(): Promise<User> { | ||
| return fetchApi<{ data: User }>('/auths/user', { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| }).then((response) => response.data); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { fetchApi } from '@/src/utils/api'; | ||
| import { CrewDetail } from '@/src/types/crew-card'; | ||
|
|
||
| // ν¬λ£¨ λν μΌ λ³΄κΈ° | ||
| export async function getCrewDetail(id: number): Promise<CrewDetail> { | ||
| const url = `/api/crews/${id}`; | ||
|
|
||
|
|
@@ -12,3 +13,39 @@ export async function getCrewDetail(id: number): Promise<CrewDetail> { | |
| }); | ||
| return response.data; | ||
| } | ||
|
|
||
| // ν¬λ£¨ μ°Έμ¬ | ||
| export async function joinCrew(crewId: number): Promise<void> { | ||
| const url = `/api/crews/${crewId}/join`; | ||
|
|
||
| await fetchApi<void>(url, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| // μ¬μ©μ ν¬λ£¨ νν΄ | ||
| export async function leaveCrew(crewId: number): Promise<void> { | ||
| const url = `/api/crews/${crewId}/leave`; | ||
|
|
||
| await fetchApi<void>(url, { | ||
| method: 'DELETE', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| // μ£Όμ΅μ ν¬λ£¨ μ·¨μ | ||
| export async function cancelCrew(crewId: number): Promise<void> { | ||
| const url = `/api/crews/${crewId}`; | ||
|
|
||
| await fetchApi<void>(url, { | ||
| method: 'DELETE', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| } | ||
|
Comment on lines
+41
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν¬λ£¨ μ·¨μ μμ μ λν μμ μ₯μΉ νμ μ£Όμ΅μ κΆν νμΈ λ° μ·¨μ μμ μ λν μμ μ₯μΉκ° νμν©λλ€. λ€μ μ¬νλ€μ κ³ λ €ν΄μΌ ν©λλ€:
-export async function cancelCrew(crewId: number): Promise<void> {
+export async function cancelCrew(
+ crewId: number,
+ organizerId: number,
+ confirmation: boolean
+): Promise<void> {
+ if (!confirmation) {
+ throw new Error('ν¬λ£¨ μ·¨μ μμ
μ νμΈμ΄ νμν©λλ€.');
+ }
+
+ // μ£Όμ΅μ κΆν νμΈ
+ const crewDetail = await getCrewDetail(crewId);
+ if (crewDetail.organizerId !== organizerId) {
+ throw new Error('ν¬λ£¨ μ·¨μλ μ£Όμ΅μλ§ κ°λ₯ν©λλ€.');
+ }
const url = `/api/crews/${crewId}`;
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,153 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'use client'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useEffect, useState } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { toast } from 'react-toastify'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useRouter } from 'next/navigation'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useDisclosure } from '@mantine/hooks'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { cancelCrew, joinCrew, leaveCrew } from '@/src/_apis/crew/crew-detail-apis'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useGetCrewDetailQuery } from '@/src/_queries/crew/crew-detail-queries'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useAuthStore } from '@/src/store/use-auth-store'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ApiError } from '@/src/utils/api'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ConfirmCancelModal from '@/src/components/common/modal/confirm-cancel-modal'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { User } from '@/src/types/auth'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import DetailCrewPresenter from './detail-crew-presenter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface DetailCrewContainerProps { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default function DetailCrew({ id }: DetailCrewContainerProps) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isCaptain, setIsCaptain] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isMember, setIsMember] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isJoining, setIsJoining] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [confirmCancelOpened, { open: openConfirmCancel, close: closeConfirmCancel }] = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useDisclosure(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const router = useRouter(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { user } = useAuthStore(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isDataWrappedUser = (value: unknown): value is { data: User } => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return typeof value === 'object' && value !== null && 'data' in value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const currentUserId = isDataWrappedUser(user) ? user.data.id : user?.id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data, isLoading, error: fetchError, refetch } = useGetCrewDetailQuery(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentUserId && data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const captain = data.crewMembers.find((member) => member.captain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const memberExists = data.crewMembers.some((member) => member.id === currentUserId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsCaptain(captain?.id === currentUserId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsMember(memberExists); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [currentUserId, data]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleJoinClick = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isJoining) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsJoining(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await joinCrew(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.success('ν¬λ£¨μ μ°Έμ¬νμμ΅λλ€ π'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsMember(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await refetch(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (joinError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (joinError instanceof ApiError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error(joinError.message); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error('π« ν¬λ£¨ μ°Έμ¬ μ€ μλ¬κ° λ°μνμ΅λλ€.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsJoining(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleLeaveCrew = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await leaveCrew(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.success('ν¬λ£¨λ₯Ό νν΄νμμ΅λλ€π'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await refetch(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (leaveError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (leaveError instanceof ApiError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error(leaveError.message); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error('π« ν¬λ£¨ νν΄ μ€ μλ¬κ° λ°μνμ΅λλ€.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν¬λ£¨ νν΄ ν
μμ μ¬ν: await leaveCrew(id);
toast.success('ν¬λ£¨λ₯Ό νν΄νμμ΅λλ€π');
+ setIsMember(false);
await refetch();π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleDelete = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| openConfirmCancel(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleConfirmCancel = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await cancelCrew(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.success('ν¬λ£¨κ° μ±κ³΅μ μΌλ‘ μμ λμμ΅λλ€.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| router.push('/'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (deleteError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error('ν¬λ£¨ μμ μ€ μλ¬κ° λ°μνμ΅λλ€.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const onShareClick = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const url = window.location.href; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| navigator.clipboard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .writeText(url) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .then(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.success('URLμ΄ λ³΅μ¬λμμ΅λλ€!'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .catch(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error('π« URL 볡μ¬μ μ€ν¨νμ΅λλ€. λ€μ μλν΄μ£ΌμΈμ.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO: λ‘λ©, μλ¬μ²λ¦¬ μΆν κ°μ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isLoading) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <p>Loading...</p>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (fetchError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (fetchError instanceof ApiError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const errorData = JSON.parse(fetchError.message); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (errorData.status === 'NOT_FOUND') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <p>ν¬λ£¨ μ 보λ₯Ό μ°Ύμ μ μμ΅λλ€</p>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (parseError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <p>{`Error ${fetchError.status}: ${fetchError.message}`}</p>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <p>λ°μ΄ν° ν΅μ μ μ€ν¨νμ΅λλ€.</p>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+112
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion μλ¬ μ²λ¦¬ λ‘μ§ κ°μ μΌλ‘ μμ μ± ν₯μ
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <p>λ°μ΄ν°λ₯Ό λΆλ¬μ¬ μ μμ΅λλ€.</p>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DetailCrewPresenter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data={data} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isCaptain={isCaptain} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isMember={isMember} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isJoining={isJoining} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleJoinClick={handleJoinClick} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleLeaveCrew={handleLeaveCrew} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleDelete={handleDelete} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onShareClick={onShareClick} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ConfirmCancelModal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| opened={confirmCancelOpened} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClose={closeConfirmCancel} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onConfirm={handleConfirmCancel} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| μ λ§ μμ νμκ² μ΅λκΉ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </ConfirmCancelModal> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
μλ¬ μ²λ¦¬ λ° μλ΅ νμ λͺ μ νμ
API νΈμΆ μ€ν¨ μμ μλ¬ μ²λ¦¬μ μλ΅ νμ μ λν λͺ νν μ μκ° νμν©λλ€.
λ€μκ³Ό κ°μ΄ μμ νλ κ²μ μ μν©λλ€:
π Committable suggestion