Skip to content

Commit 8600a8e

Browse files
committed
fix: fix join leaderboard errors
1 parent 56cdf0a commit 8600a8e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

public/locales/en/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"genericError": "Error joining leaderboard",
9797
"join": "Join",
9898
"leaderboardCode": "Leaderboard code",
99-
"leaderboardCodeInvalid": "Leaderboard code must start with \"ttlic_\", and be followed by 24 alphanumeric characters.",
99+
"leaderboardCodeInvalid": "Leaderboard code must start with \"ttlic_\", and be followed by 32 alphanumeric characters.",
100100
"leaderboardCodeRequired": "Leaderboard code is required",
101101
"notFound": "Leaderboard not found"
102102
},

public/locales/fi/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"genericError": "Tulostauluun liittyminen epäonnistui.",
9797
"join": "Liity",
9898
"leaderboardCode": "Tulostaulukoodi",
99-
"leaderboardCodeInvalid": "Kutsukoodin tulee alkaa \"ttlic_\", ja sen jälkeen täytyy olla 24 alphanumeerista kirjainta.",
99+
"leaderboardCodeInvalid": "Kutsukoodin tulee alkaa \"ttlic_\", ja sen jälkeen täytyy olla 32 alphanumeerista kirjainta.",
100100
"leaderboardCodeRequired": "Kutsukoodi vaaditaan.",
101101
"notFound": "Tulostaulua ei löytynyt."
102102
},

src/components/leaderboard/actions.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@ import {
55
postRequestWithoutResponse,
66
postRequestWithResponse,
77
} from "../../api/baseApi";
8+
import { JoinLeaderboardError } from "../../types";
89

9-
export const joinLeaderboard = (inviteCode: string) =>
10-
postRequestWithResponse<{
10+
export const joinLeaderboard = async (inviteCode: string) => {
11+
const response = await postRequestWithResponse<{
1112
name: string;
1213
member_count: number;
1314
}>("/leaderboards/join", {
1415
invite: inviteCode,
1516
});
1617

18+
if ("error" in response) {
19+
if (response.statusCode === 404) {
20+
return { error: JoinLeaderboardError.NotFound };
21+
} else if (response.statusCode === 409) {
22+
return { error: JoinLeaderboardError.AlreadyMember };
23+
}
24+
}
25+
26+
return response;
27+
};
28+
1729
export const leaveLeaderboard = async (leaderboardName: string) => {
1830
const data = await postRequestWithoutResponse(
1931
`/leaderboards/${leaderboardName}/leave`,

0 commit comments

Comments
 (0)