Remove deleted articles from the category list cache.
After DELETE, the category view kept showing the article until a full reload because Redux still held it.
This commit is contained in:
@@ -179,6 +179,7 @@ export const article = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* DELETE /api/article/:sku → 204
|
* DELETE /api/article/:sku → 204
|
||||||
|
* Errors: 400 Article has children, 401, 403, 404 Article not found
|
||||||
*/
|
*/
|
||||||
delete(sku) {
|
delete(sku) {
|
||||||
return http(`/api/article/${encodeURIComponent(sku)}`, {
|
return http(`/api/article/${encodeURIComponent(sku)}`, {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Link as RouterLink, useNavigate } from 'react-router-dom';
|
import { Link as RouterLink, useNavigate } from 'react-router-dom';
|
||||||
import { useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Link from '@mui/material/Link';
|
import Link from '@mui/material/Link';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
@@ -22,7 +22,10 @@ import {
|
|||||||
buildCategoryPath,
|
buildCategoryPath,
|
||||||
defaultCategoryPath,
|
defaultCategoryPath,
|
||||||
} from '../../pages/artikel/categoryRoute';
|
} from '../../pages/artikel/categoryRoute';
|
||||||
import { selectCategoryRootId } from '../../store/categorySlice';
|
import {
|
||||||
|
removeArticleBySku,
|
||||||
|
selectCategoryRootId,
|
||||||
|
} from '../../store/categorySlice';
|
||||||
|
|
||||||
function PanelValue({ label, children }) {
|
function PanelValue({ label, children }) {
|
||||||
if (children == null || children === '') return null;
|
if (children == null || children === '') return null;
|
||||||
@@ -107,6 +110,7 @@ const articleNameFieldHiddenSx = {
|
|||||||
|
|
||||||
export default function ArticleView({ article: articleData, onArticleUpdated }) {
|
export default function ArticleView({ article: articleData, onArticleUpdated }) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const dispatch = useDispatch();
|
||||||
const categories = useSelector((state) => state.category.categories);
|
const categories = useSelector((state) => state.category.categories);
|
||||||
const rootCategoryId = useSelector(selectCategoryRootId);
|
const rootCategoryId = useSelector(selectCategoryRootId);
|
||||||
const basePrice = primaryPrice(articleData);
|
const basePrice = primaryPrice(articleData);
|
||||||
@@ -126,6 +130,7 @@ export default function ArticleView({ article: articleData, onArticleUpdated })
|
|||||||
articleData.categoryIds?.[0],
|
articleData.categoryIds?.[0],
|
||||||
'article.categoryIds[0]',
|
'article.categoryIds[0]',
|
||||||
);
|
);
|
||||||
|
dispatch(removeArticleBySku(articleData.sku));
|
||||||
if (categories && rootCategoryId != null) {
|
if (categories && rootCategoryId != null) {
|
||||||
navigate(buildCategoryPath(categories, rootCategoryId, categoryId));
|
navigate(buildCategoryPath(categories, rootCategoryId, categoryId));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -217,6 +217,12 @@ const categorySlice = createSlice({
|
|||||||
resetCategoryState() {
|
resetCategoryState() {
|
||||||
return initialState;
|
return initialState;
|
||||||
},
|
},
|
||||||
|
removeArticleBySku(state, action) {
|
||||||
|
const sku = action.payload;
|
||||||
|
state.articles = state.articles.filter((row) => row.sku !== sku);
|
||||||
|
state.articlesTotal = state.articles.length;
|
||||||
|
state.rootArticles = state.rootArticles.filter((row) => row.sku !== sku);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
extraReducers: (builder) => {
|
extraReducers: (builder) => {
|
||||||
builder
|
builder
|
||||||
@@ -298,6 +304,7 @@ export const {
|
|||||||
navigateToCategory,
|
navigateToCategory,
|
||||||
navigateBack,
|
navigateBack,
|
||||||
resetCategoryState,
|
resetCategoryState,
|
||||||
|
removeArticleBySku,
|
||||||
} = categorySlice.actions;
|
} = categorySlice.actions;
|
||||||
|
|
||||||
export const selectCategoryMap = (state) => state.category.categories;
|
export const selectCategoryMap = (state) => state.category.categories;
|
||||||
|
|||||||
Reference in New Issue
Block a user