diff --git a/src/components/events/partials/ModalTabsAndPages/DetailsTobiraTab.tsx b/src/components/events/partials/ModalTabsAndPages/DetailsTobiraTab.tsx index 3f05a721ac..47cdd1edc5 100644 --- a/src/components/events/partials/ModalTabsAndPages/DetailsTobiraTab.tsx +++ b/src/components/events/partials/ModalTabsAndPages/DetailsTobiraTab.tsx @@ -9,7 +9,7 @@ import { Formik } from "formik"; import { useState } from "react"; import EventDetailsTabHierarchyNavigation from "./EventDetailsTabHierarchyNavigation"; import NewTobiraPage, { TobiraFormProps } from "./NewTobiraPage"; -import { fetchSeriesDetailsTobira, setTobiraTabHierarchy, TobiraData, updateSeriesTobiraPath } from "../../../../slices/seriesDetailsSlice"; +import { fetchSeriesDetailsTobira, removeSeriesTobiraPath, setTobiraTabHierarchy, TobiraData, updateSeriesTobiraPath } from "../../../../slices/seriesDetailsSlice"; import { fetchSeriesDetailsTobiraNew, TobiraPage } from "../../../../slices/seriesSlice"; import ConfirmModal from "../../../shared/ConfirmModal"; import { Tooltip } from "../../../shared/Tooltip"; @@ -95,11 +95,9 @@ const DetailsTobiraTab = ({ kind, id }: DetailsTobiraTabProps) => { }; const handleDelete = async (hostPage: TobiraPage) => { - await dispatch(updateSeriesTobiraPath({ + await dispatch(removeSeriesTobiraPath({ seriesId: id, currentPath: hostPage.path, - breadcrumbs: [], - remove: true, })).then(() => dispatch(fetchSeriesDetailsTobira(id))) } diff --git a/src/slices/seriesDetailsSlice.ts b/src/slices/seriesDetailsSlice.ts index 27365ed442..49f9cc6da0 100644 --- a/src/slices/seriesDetailsSlice.ts +++ b/src/slices/seriesDetailsSlice.ts @@ -429,14 +429,10 @@ export const fetchSeriesDetailsTobira = createAppAsyncThunk('seriesDetails/fetch }); export const updateSeriesTobiraPath = createAppAsyncThunk('series/updateSeriesTobiraData', async ( - params: TobiraFormProps & { - seriesId: string, - remove?: boolean, - }, + params: TobiraFormProps & { seriesId: string }, { dispatch }, ) => { const tobiraParams = new URLSearchParams(); - const operation = params.remove ? "REMOVED" : "UPDATED"; const pathComponents = params.breadcrumbs.slice(1).map(crumb => ({ name: crumb.title, pathSegment: crumb.segment, @@ -467,7 +463,37 @@ export const updateSeriesTobiraPath = createAppAsyncThunk('series/updateSeriesTo console.info(response); dispatch(addNotification({ type: 'success', - key: `SERIES_PATH_${operation}`, + key: 'SERIES_PATH_UPDATED', + context: NOTIFICATION_CONTEXT_TOBIRA, + })); + + return response.data; + } catch (error) { + console.error(error); + dispatch(addNotification({ + type: 'error', + key: 'SERIES_PATH_NOT_UPDATED', + context: NOTIFICATION_CONTEXT_TOBIRA, + })); + throw error; + }} +); + +export const removeSeriesTobiraPath = createAppAsyncThunk('series/removeSeriesTobiraData', async ( + params: Required> & { seriesId: string }, + { dispatch }, +) => { + const path = encodeURIComponent(params.currentPath); + + try { + const response = await axios.delete( + `/admin-ng/series/${params.seriesId}/tobira/${path}`, + ); + + console.info(response); + dispatch(addNotification({ + type: 'success', + key: 'SERIES_PATH_REMOVED', context: NOTIFICATION_CONTEXT_TOBIRA, })); @@ -476,7 +502,7 @@ export const updateSeriesTobiraPath = createAppAsyncThunk('series/updateSeriesTo console.error(error); dispatch(addNotification({ type: 'error', - key: `SERIES_PATH_NOT_${operation}`, + key: 'SERIES_PATH_NOT_REMOVED', context: NOTIFICATION_CONTEXT_TOBIRA, })); throw error;