Skip to content

Commit 21fa7aa

Browse files
committed
fix: Fixed errors
1 parent f82cdf0 commit 21fa7aa

5 files changed

Lines changed: 32 additions & 19 deletions

File tree

src/actions/admin/adminTeamActions.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
"use server";
22

33
import { cookies } from "next/headers";
4-
import { client, addParticipantToTeam, removeParticipantFromTeam, changeTeamCaptain, deleteTeam, changeTeamStatus } from "../../../client";
4+
import { client, addParticipantToTeam, removeParticipantFromTeam, changeTeamCaptain, deleteTeam, changeTeamStatus, type ErrorResponse } from "../../../client";
55
import { multipleRevalidatePaths } from "@/lib/multipleRevalidatePaths";
66

7+
// Type guard to check if error is ErrorResponse
8+
function isErrorResponse(error: unknown): error is ErrorResponse {
9+
return typeof error === "object" && error !== null && "errors" in error;
10+
}
11+
712
export async function updateTeamAction(formDataToSend: FormData) {
813
"use server";
914
const cookie = cookies().get("JWT")?.value;
@@ -96,7 +101,9 @@ export async function addParticipantAction(
96101
});
97102

98103
if (error) {
99-
const errorMessage: string = error.errors?.join(", ") || "Failed to add participant";
104+
const errorMessage: string = isErrorResponse(error)
105+
? (error.errors?.join(", ") || "Failed to add participant")
106+
: "Failed to add participant";
100107
return {
101108
status: false as const,
102109
errorMessage,
@@ -138,7 +145,9 @@ export async function removeParticipantAction(
138145
});
139146

140147
if (error) {
141-
const errorMessage: string = error.errors?.join(", ") || "Failed to remove participant";
148+
const errorMessage: string = isErrorResponse(error)
149+
? (error.errors?.join(", ") || "Failed to remove participant")
150+
: "Failed to remove participant";
142151
return {
143152
status: false as const,
144153
errorMessage,
@@ -180,7 +189,9 @@ export async function changeCaptainAction(
180189
});
181190

182191
if (error) {
183-
const errorMessage: string = error.errors?.join(", ") || "Failed to change captain";
192+
const errorMessage: string = isErrorResponse(error)
193+
? (error.errors?.join(", ") || "Failed to change captain")
194+
: "Failed to change captain";
184195
return {
185196
status: false as const,
186197
errorMessage,
@@ -220,7 +231,9 @@ export async function deleteTeamAction(
220231
});
221232

222233
if (error) {
223-
const errorMessage: string = error.errors?.join(", ") || "Failed to delete team";
234+
const errorMessage: string = isErrorResponse(error)
235+
? (error.errors?.join(", ") || "Failed to delete team")
236+
: "Failed to delete team";
224237
return {
225238
status: false as const,
226239
errorMessage,
@@ -263,7 +276,9 @@ export async function changeTeamStatusAction(
263276
});
264277

265278
if (error) {
266-
const errorMessage: string = error.errors?.join(", ") || "Failed to change team status";
279+
const errorMessage: string = isErrorResponse(error)
280+
? (error.errors?.join(", ") || "Failed to change team status")
281+
: "Failed to change team status";
267282
return {
268283
status: false as const,
269284
errorMessage,

src/app/(main-page)/(withAuth)/dashboard/[tournamentAbbreviation]/settings/page.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ const SettingsPage = () => {
149149
setTournamentData((prev) => {
150150
const prizePool = [...(prev?.prizePool || [])];
151151
if (prizePool[0]) {
152-
prizePool[0] = { ...prizePool[0], prize: prize || 0 };
152+
prizePool[0] = { ...prizePool[0], prize: String(prize || 0) };
153153
} else {
154-
prizePool[0] = { type: 0, prize: prize || 0 };
154+
prizePool[0] = { type: 0, prize: String(prize || 0) };
155155
}
156156
return {
157157
...prev,
@@ -178,9 +178,9 @@ const SettingsPage = () => {
178178
setTournamentData((prev) => {
179179
const prizePool = [...(prev?.prizePool || [])];
180180
if (prizePool[1]) {
181-
prizePool[1] = { ...prizePool[1], prize: prize || 0 };
181+
prizePool[1] = { ...prizePool[1], prize: String(prize || 0) };
182182
} else {
183-
prizePool[1] = { type: 1, prize: prize || 0 };
183+
prizePool[1] = { type: 1, prize: String(prize || 0) };
184184
}
185185
return {
186186
...prev,
@@ -207,9 +207,9 @@ const SettingsPage = () => {
207207
setTournamentData((prev) => {
208208
const prizePool = [...(prev?.prizePool || [])];
209209
if (prizePool[2]) {
210-
prizePool[2] = { ...prizePool[2], prize: prize || 0 };
210+
prizePool[2] = { ...prizePool[2], prize: String(prize || 0) };
211211
} else {
212-
prizePool[2] = { type: 2, prize: prize || 0 };
212+
prizePool[2] = { type: 2, prize: String(prize || 0) };
213213
}
214214
return {
215215
...prev,

src/app/(tournament)/tournament/[tournamentId]/mappool/[stageType]/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ const SingleTournamentMappool = async ({
125125
od: map.beatmapStatistics.od,
126126
cs: map.beatmapStatistics.cs,
127127
}}
128-
tournamentAbbreviation={params.tournamentId}
129-
beatmapId={map.beatmapId}
130-
beatmapsetId={map.beatmapsetId}
128+
_tournamentAbbreviation={params.tournamentId}
129+
_beatmapId={map.beatmapId}
130+
_beatmapsetId={map.beatmapsetId}
131131
/>
132132
))}
133133
</div>

src/app/(tournament)/tournament/[tournamentId]/teams/[teamId]/ChangeTeamNameForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export const ChangeTeamNameForm = ({
113113

114114
const updateTeamResponse = await updateTeamAction(formDataToSend);
115115
if (!updateTeamResponse.status) {
116-
return toast.error(updateTeamResponse.errorMessage || "Failed to update team", {
116+
const errorMsg: string = updateTeamResponse.errorMessage || "Failed to update team";
117+
return toast.error(errorMsg, {
117118
duration: 3000,
118119
});
119120
}

src/ui/molecules/BeatmapListItem/BeatmapListItem.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ export const BeatmapListItem = ({
4040
isCustom,
4141
img,
4242
mapInformation,
43-
_tournamentAbbreviation,
44-
_beatmapId,
45-
_beatmapsetId,
4643
}: BeatmapListItemProps) => {
4744
const formatTime = (seconds: number) => {
4845
const minutes = Math.floor(seconds / 60);

0 commit comments

Comments
 (0)