u
This commit is contained in:
@@ -15,6 +15,7 @@ export function normalizeCategoryNode(item) {
|
||||
id: item.id,
|
||||
parentId: item.parentId,
|
||||
name: item.name == null ? null : String(item.name).trim() || null,
|
||||
posterminalIds: Array.isArray(item.posterminalIds) ? item.posterminalIds : [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -219,6 +220,24 @@ export const deleteCategory = createAsyncThunk(
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Toggle the POS (Point of Sale) flag on a category.
|
||||
* Backend: PATCH /api/category/:id Body: { pos: boolean } → { category }.
|
||||
* PROPOSED — backend needs to implement this field.
|
||||
*/
|
||||
export const toggleCategoryPos = createAsyncThunk(
|
||||
'category/togglePos',
|
||||
async ({ categoryId, pos }, { rejectWithValue }) => {
|
||||
try {
|
||||
const data = await category.updatePos(categoryId, pos);
|
||||
requireObject(data.category, 'PATCH /api/category/:id.category (pos)');
|
||||
return normalizeCategoryNode(data.category);
|
||||
} catch (err) {
|
||||
return catchBackendError(rejectWithValue)(err);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const initialState = {
|
||||
companyId: null,
|
||||
languageId: null,
|
||||
@@ -403,6 +422,15 @@ const categorySlice = createSlice({
|
||||
state.articlesStatus = 'succeeded';
|
||||
}
|
||||
})
|
||||
.addCase(toggleCategoryPos.fulfilled, (state, action) => {
|
||||
const updated = action.payload;
|
||||
if (updated == null || state.categories == null) return;
|
||||
const key = String(updated.id);
|
||||
const existing = state.categories[key];
|
||||
if (existing) {
|
||||
state.categories[key] = { ...existing, pos: updated.pos };
|
||||
}
|
||||
})
|
||||
.addCase(loadCurrentCompany.fulfilled, (state, action) => {
|
||||
const nextCompanyId = action.payload?.id ?? null;
|
||||
if (nextCompanyId != null && nextCompanyId !== state.companyId) {
|
||||
|
||||
Reference in New Issue
Block a user