Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { clientApi } from '@/apis/client';
import { ENDPOINTS } from '@/consts/api';
import type { ApiResponseT } from '@/types/api';
import type { PostTournamentItemLinkResponseT } from '@/types/tournament';

import type { PostTournamentItemLinkResponseT } from '../_types/tournament';
import { clientApi } from './client';

export const postTournamentItemLink = async (tournamentId: number, url: string) => {
const { data } = await clientApi.post<ApiResponseT<PostTournamentItemLinkResponseT>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const useDeleteTournamentItem = (tournamentId: number, tournamentItemId:

/** 토너먼트가 시작된 경우 */
if (code === ERROR_CODE.TOURNAMENT_NOT_PENDING) {
toast.error(getApiErrorMessage(error));
queryClient.invalidateQueries({ queryKey: ['tournament', tournamentId] });
if (pathname !== ROUTES.TOURNAMENT_CREATE(tournamentId))
router.replace(ROUTES.TOURNAMENT_CREATE(tournamentId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { ERROR_CODE, ERROR_MESSAGE_MAP } from '@piki/core';
import { useEffect, useMemo, useState } from 'react';
import { toast } from 'sonner';

Expand Down Expand Up @@ -103,7 +104,11 @@ function InviteFriendsDialog({
};

const handleSendInviteLink = async () => {
if (!inviteUrl) return;
/** 이미 시작된 토너먼트인 경우 */
if (!inviteUrl) {
toast.error(ERROR_MESSAGE_MAP[ERROR_CODE.TOURNAMENT_NOT_PENDING]);
return;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const result = await share({
title: 'piki 토너먼트 초대',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const usePatchInviteExpiry = (tournamentId: number) => {

/** 토너먼트가 시작된 경우 */
if (code === ERROR_CODE.TOURNAMENT_NOT_PENDING) {
toast.error(getApiErrorMessage(error));
queryClient.invalidateQueries({ queryKey: ['tournament', tournamentId] });
return;
}
Expand Down
3 changes: 0 additions & 3 deletions apps/web/src/app/tournament/[id]/create/_types/tournament.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRouter } from 'next/navigation';
import { toast } from 'sonner';

import { PREV_ITEM_COUNT_KEY } from '@/app/tournament/[id]/create/_consts/tournamentItemBasket';
import { QUERY_ACTION } from '@/consts/queryAction';
import { ROUTES } from '@/consts/route';
import { useBackWithFallback } from '@/hooks/useBackWithFallback';
import { getApiErrorCode, isGlobalNetError } from '@/utils/apiError';
Expand Down Expand Up @@ -33,13 +34,22 @@ export const usePostTournamentItemsByWish = (tournamentId: number, previousItemC

const code = getApiErrorCode(error);

/** 토너먼트가 시작됐거나 삭제, 존재하지 않는 경우 */
if (code === ERROR_CODE.TOURNAMENT_NOT_PENDING || code === ERROR_CODE.TOURNAMENT_NOT_FOUND) {
/** 토너먼트가 시작된 경우 */
if (code === ERROR_CODE.TOURNAMENT_NOT_PENDING) {
toast.error(getApiErrorMessage(error));
queryClient.invalidateQueries({ queryKey: ['tournament', tournamentId] });
router.replace(ROUTES.TOURNAMENT_CREATE(tournamentId));
return;
}

/** 토너먼트가 삭제된 경우 */
if (code === ERROR_CODE.TOURNAMENT_NOT_FOUND) {
router.replace(
`${ROUTES.HOME}?${QUERY_ACTION.KEY}=${QUERY_ACTION.VALUE.TOURNAMENT_NOT_FOUND}`
);
return;
}

/**
* 400: 아이템 32개 초과
* 403: 토너먼트 참여 권한 없음·위시에 없는 아이템
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useRouter } from 'next/navigation';
import { toast } from 'sonner';

import { QUERY_ACTION } from '@/consts/queryAction';
import { ROUTES } from '@/consts/route';
import { useBackWithFallback } from '@/hooks/useBackWithFallback';
import type { PatchItemRequestT } from '@/types/item';
Expand Down Expand Up @@ -37,16 +38,22 @@ export const usePatchTournamentItem = (tournamentId: number, tournamentItemId: n

const code = getApiErrorCode(error);

/** 토너먼트가 시작됐거나 삭제, 존재하지 않는 경우 */
if (
code === ERROR_CODE.TOURNAMENT_NOT_PENDING ||
code === ERROR_CODE.TOURNAMENT_NOT_FOUND
) {
/** 토너먼트가 시작된 경우 */
if (code === ERROR_CODE.TOURNAMENT_NOT_PENDING) {
toast.error(getApiErrorMessage(error));
queryClient.invalidateQueries({ queryKey: ['tournament', tournamentId] });
router.replace(ROUTES.TOURNAMENT_CREATE(tournamentId));
return;
}

/** 토너먼트가 삭제된 경우 */
if (code === ERROR_CODE.TOURNAMENT_NOT_FOUND) {
router.replace(
`${ROUTES.HOME}?${QUERY_ACTION.KEY}=${QUERY_ACTION.VALUE.TOURNAMENT_NOT_FOUND}`
);
return;
}

/**
* 400: 상품 이름·가격 미입력
* 403: 토너먼트 참여 권한 없음
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/get-item-dialog/ByLinkDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import { useParams } from 'next/navigation';
import { useState } from 'react';

import { usePostTournamentItemLink } from '@/app/tournament/[id]/create/_hooks/usePostTournamentItemLink';
import { LinkIconFill } from '@/assets/icons';
import Button from '@/components/button';
import { Dialog, DialogContent, DialogDescription, DialogTitle } from '@/components/dialog';
import Input from '@/components/input';
import { usePostTournamentItemLink } from '@/hooks/usePostTournamentItemLink';
import { usePostWishLink } from '@/hooks/usePostWishLink';
import type { ItemTypeT } from '@/types/item';
import { isGlobalNetError } from '@/utils/apiError';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useRouter } from 'next/navigation';
import { toast } from 'sonner';

import { postTournamentItemLink } from '@/apis/postTournamentItemLink';
import { QUERY_ACTION } from '@/consts/queryAction';
import { ROUTES } from '@/consts/route';
import { getApiErrorCode, getApiErrorStatus, isGlobalNetError } from '@/utils/apiError';
import { getApiErrorMessage } from '@/utils/getApiErrorMessage';

import { postTournamentItemLink } from '../_apis/postTournamentItemLink';

type UsePostTournamentItemLinkOptionsT = {
/** 입력 폼처럼 에러를 화면 안에서 안내하는 경우 false — 4xx 토스트를 끈다 */
showErrorToast?: boolean;
Expand All @@ -35,6 +34,7 @@ export const usePostTournamentItemLink = (

/** 토너먼트가 시작된 경우 */
if (code === ERROR_CODE.TOURNAMENT_NOT_PENDING) {
if (showErrorToast) toast.error(getApiErrorMessage(error));
queryClient.invalidateQueries({ queryKey: ['tournament', tournamentId] });
return;
}
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/hooks/usePostTournamentOCR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const usePostTournamentOCR = (tournamentId: number) => {

/** 토너먼트가 시작된 경우 */
if (code === ERROR_CODE.TOURNAMENT_NOT_PENDING) {
toast.error(getApiErrorMessage(error));
queryClient.invalidateQueries({ queryKey: ['tournament', tournamentId] });
return;
}
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/types/tournament.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export type PostCreateTournamentResponseT = {
tournamentId: number;
};

export type PostTournamentItemLinkResponseT = {
tournamentItemId: number;
};

/** 초대 코드 / 토너먼트 미리보기 응답 */
export type GetInvitePreviewResponseT = {
tournamentId: number;
Expand Down
Loading