add info pannel
This commit is contained in:
@@ -28,6 +28,7 @@ export interface Mission {
|
||||
|
||||
interface MissionsState {
|
||||
missions: Mission[];
|
||||
newMissions: Mission[];
|
||||
currentMission: Mission | null;
|
||||
hasNextPage: boolean;
|
||||
create: {
|
||||
@@ -47,6 +48,7 @@ interface MissionsState {
|
||||
|
||||
const initialState: MissionsState = {
|
||||
missions: [],
|
||||
newMissions: [],
|
||||
currentMission: null,
|
||||
hasNextPage: false,
|
||||
create: {},
|
||||
@@ -65,6 +67,33 @@ const initialState: MissionsState = {
|
||||
// GET /missions
|
||||
export const fetchMissions = createAsyncThunk(
|
||||
'missions/fetchMissions',
|
||||
async (
|
||||
{
|
||||
page = 0,
|
||||
pageSize = 100,
|
||||
tags = [],
|
||||
}: { page?: number; pageSize?: number; tags?: string[] },
|
||||
{ rejectWithValue },
|
||||
) => {
|
||||
try {
|
||||
const params: any = { page, pageSize };
|
||||
if (tags.length) params.tags = tags;
|
||||
const response = await axios.get('/missions', {
|
||||
params,
|
||||
paramsSerializer: {
|
||||
indexes: null,
|
||||
},
|
||||
});
|
||||
return response.data; // { missions, hasNextPage }
|
||||
} catch (err: any) {
|
||||
return rejectWithValue(err.response?.data);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// GET /missions
|
||||
export const fetchNewMissions = createAsyncThunk(
|
||||
'missions/fetchNewMissions',
|
||||
async (
|
||||
{
|
||||
page = 0,
|
||||
@@ -211,6 +240,42 @@ const missionsSlice = createSlice({
|
||||
},
|
||||
);
|
||||
|
||||
// ─── FETCH NEW MISSIONS ───
|
||||
builder.addCase(fetchNewMissions.pending, (state) => {
|
||||
state.statuses.fetchList = 'loading';
|
||||
state.error = null;
|
||||
});
|
||||
builder.addCase(
|
||||
fetchNewMissions.fulfilled,
|
||||
(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
missions: Mission[];
|
||||
hasNextPage: boolean;
|
||||
}>,
|
||||
) => {
|
||||
state.statuses.fetchList = 'successful';
|
||||
state.newMissions = action.payload.missions;
|
||||
state.hasNextPage = action.payload.hasNextPage;
|
||||
},
|
||||
);
|
||||
builder.addCase(
|
||||
fetchNewMissions.rejected,
|
||||
(state, action: PayloadAction<any>) => {
|
||||
state.statuses.fetchList = 'failed';
|
||||
|
||||
const errors = action.payload.errors as Record<
|
||||
string,
|
||||
string[]
|
||||
>;
|
||||
Object.values(errors).forEach((messages) => {
|
||||
messages.forEach((msg) => {
|
||||
toastError(msg);
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// ─── FETCH MISSION BY ID ───
|
||||
builder.addCase(fetchMissionById.pending, (state) => {
|
||||
state.statuses.fetchById = 'loading';
|
||||
|
||||
Reference in New Issue
Block a user