u
This commit is contained in:
@@ -189,6 +189,24 @@ export const reorderCategories = createAsyncThunk(
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Move a category under a new parent (drop into subcategory).
|
||||
* Backend: PATCH /api/category/:id Body: { parentId } → { category }.
|
||||
* (Vorschlag — Route fehlt noch in dashback; siehe TODO.md.)
|
||||
*/
|
||||
export const moveCategory = createAsyncThunk(
|
||||
'category/move',
|
||||
async ({ categoryId, parentId }, { rejectWithValue }) => {
|
||||
try {
|
||||
const data = await category.move(categoryId, parentId);
|
||||
requireObject(data.category, 'PATCH /api/category/:id.category');
|
||||
return normalizeCategoryNode(data.category);
|
||||
} catch (err) {
|
||||
return catchBackendError(rejectWithValue)(err);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export const deleteCategory = createAsyncThunk(
|
||||
'category/delete',
|
||||
async (categoryId, { rejectWithValue }) => {
|
||||
@@ -350,6 +368,14 @@ const categorySlice = createSlice({
|
||||
}
|
||||
}
|
||||
})
|
||||
.addCase(moveCategory.fulfilled, (state, action) => {
|
||||
const moved = action.payload;
|
||||
if (moved == null || state.categories == null) return;
|
||||
state.categories[String(moved.id)] = {
|
||||
...(state.categories[String(moved.id)] ?? {}),
|
||||
...moved,
|
||||
};
|
||||
})
|
||||
.addCase(createArticle.fulfilled, (state, action) => {
|
||||
const created = action.payload;
|
||||
if (created == null) return;
|
||||
|
||||
Reference in New Issue
Block a user