Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 5x 7x 7x 4x 3x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x | import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { TeacherAssignmentAPI } from "@/api/teacher/TeacherAssignmentAPI.js";
export const _teacherFetchSpecificAssignment = createAsyncThunk(
"teacher/fetchSpecificAssignment",
async (assignmentUUID, { rejectWithValue }) => {
try {
const response = await TeacherAssignmentAPI.prototype.teacherFetchSpecificAssignment(assignmentUUID);
return response;
} catch (error) {
return rejectWithValue(error.response.data);
}
}
);
const TeacherSpecificAssignment = createSlice({
name: "TeacherSpecificAssignment",
initialState: {
assignmentData: null,
hasErrors: null,
isLoading: false,
},
reducers: {
_setSpecificAssignmentData: (state, action) => {
state.assignmentData = action.payload;
},
},
extraReducers: (builder) => {
builder
// fetch specific assignment
.addCase(_teacherFetchSpecificAssignment.pending, (state) => {
state.assignmentData = null;
state.hasErrors = null;
state.isLoading = true;
})
.addCase(_teacherFetchSpecificAssignment.fulfilled, (state, action) => {
state.assignmentData = { ...action.payload.data.assignment };
state.hasErrors = null;
state.isLoading = false;
})
.addCase(_teacherFetchSpecificAssignment.rejected, (state, action) => {
state.assignmentData = null;
state.hasErrors = action.error.message;
state.isLoading = false;
});
},
});
export const { _setSpecificAssignmentData } = TeacherSpecificAssignment.actions;
export default TeacherSpecificAssignment;
|