Add attempts
This commit is contained in:
@@ -201,6 +201,14 @@ interface ContestsState {
|
||||
status: Status;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
fetchParticipating: {
|
||||
contests: Contest[],
|
||||
hasNextPage: boolean,
|
||||
status: Status,
|
||||
error?: string,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
const emptyContest: Contest = {
|
||||
@@ -244,6 +252,13 @@ const initialState: ContestsState = {
|
||||
|
||||
checkRegistration: { registered: false, status: 'idle' },
|
||||
fetchUpcomingEligible: { contests: [], status: 'idle' },
|
||||
fetchParticipating: {
|
||||
contests: [],
|
||||
hasNextPage: false,
|
||||
status: 'idle',
|
||||
error: undefined,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
// =====================
|
||||
@@ -252,6 +267,29 @@ const initialState: ContestsState = {
|
||||
|
||||
// Existing ----------------------------
|
||||
|
||||
export const fetchParticipatingContests = createAsyncThunk(
|
||||
'contests/fetchParticipating',
|
||||
async (
|
||||
params: { page?: number; pageSize?: number } = {},
|
||||
{ rejectWithValue },
|
||||
) => {
|
||||
try {
|
||||
const { page = 0, pageSize = 10 } = params;
|
||||
const response = await axios.get<ContestsResponse>(
|
||||
'/contests/participating',
|
||||
{ params: { page, pageSize } }
|
||||
);
|
||||
return response.data;
|
||||
} catch (err: any) {
|
||||
return rejectWithValue(
|
||||
err.response?.data?.message || 'Failed to fetch participating contests'
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
export const fetchMySubmissions = createAsyncThunk(
|
||||
'contests/fetchMySubmissions',
|
||||
async (contestId: number, { rejectWithValue }) => {
|
||||
@@ -889,6 +927,26 @@ const contestsSlice = createSlice({
|
||||
state.fetchUpcomingEligible.error = action.payload;
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
builder.addCase(fetchParticipatingContests.pending, (state) => {
|
||||
state.fetchParticipating.status = 'loading';
|
||||
});
|
||||
|
||||
builder.addCase(
|
||||
fetchParticipatingContests.fulfilled,
|
||||
(state, action: PayloadAction<ContestsResponse>) => {
|
||||
state.fetchParticipating.status = 'successful';
|
||||
state.fetchParticipating.contests = action.payload.contests;
|
||||
state.fetchParticipating.hasNextPage = action.payload.hasNextPage;
|
||||
}
|
||||
);
|
||||
|
||||
builder.addCase(fetchParticipatingContests.rejected, (state, action: any) => {
|
||||
state.fetchParticipating.status = 'failed';
|
||||
state.fetchParticipating.error = action.payload;
|
||||
});
|
||||
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user