@@ -51,7 +51,7 @@ type SeriesDetailsState = {
5151 metadata : MetadataCatalog ,
5252 extendedMetadata : MetadataCatalog [ ] ,
5353 acl : TransformedAcl [ ] ,
54- theme : string ,
54+ theme : { id : string , value : string } | null ,
5555 themeNames : { id : string , value : string } [ ] ,
5656 fetchingStatisticsInProgress : boolean ,
5757 statistics : Statistics [ ] ,
@@ -83,7 +83,7 @@ const initialState: SeriesDetailsState = {
8383 } ,
8484 extendedMetadata : [ ] ,
8585 acl : [ ] ,
86- theme : "" ,
86+ theme : null ,
8787 themeNames : [ ] ,
8888 fetchingStatisticsInProgress : false ,
8989 statistics : [ ] ,
@@ -165,12 +165,12 @@ export const fetchSeriesDetailsTheme = createAppAsyncThunk('seriesDetails/fetchS
165165 const res = await axios . get ( `/admin-ng/series/${ id } /theme.json` ) ;
166166 const themeResponse = res . data ;
167167
168- let seriesTheme = "" ;
168+ let seriesTheme : SeriesDetailsState [ "theme" ] = null ;
169169
170170 // check if series has a theme
171171 if ( ! _ . isEmpty ( themeResponse ) ) {
172172 // transform response for further use
173- seriesTheme = transformToIdValueArray ( themeResponse ) [ 0 ] . value ;
173+ seriesTheme = transformToIdValueArray ( themeResponse ) [ 0 ] ;
174174 }
175175
176176 return seriesTheme ;
@@ -302,67 +302,55 @@ export const updateSeriesAccess = createAppAsyncThunk('seriesDetails/updateSerie
302302export const updateSeriesTheme = createAppAsyncThunk ( 'seriesDetails/updateSeriesTheme' , async ( params : {
303303 id : string ,
304304 values : { theme : SeriesDetailsState [ "theme" ] } ,
305- } , { dispatch, getState } ) => {
305+ } , { dispatch} ) => {
306306 const { id, values } = params ;
307307
308- let themeNames = getSeriesDetailsThemeNames ( getState ( ) ) ;
309-
310- let themeId = themeNames . find ( ( theme ) => theme . value === values . theme ) ?. id ;
311-
312- if ( ! values . theme ) {
313- axios
314- . delete ( `/admin-ng/series/${ id } /theme` )
315- . then ( ( response ) => {
316- dispatch (
317- addNotification ( {
318- type : "warning" ,
319- key : "SERIES_THEME_REPROCESS_EXISTING_EVENTS" ,
320- duration : 10 ,
321- parameter : undefined ,
322- context : NOTIFICATION_CONTEXT
323- } )
324- ) ;
325- } )
326- . catch ( ( response ) => {
327- console . error ( response ) ;
328- } ) ;
329- } else if ( ! themeId ) {
330- console . error ( "Can't update series theme. " + values . theme + " not found" ) ;
331- dispatch (
332- addNotification ( {
333- type : "error" ,
334- key : "SERIES_NOT_SAVED" ,
335- duration : 10 ,
336- parameter : undefined ,
337- context : NOTIFICATION_CONTEXT
338- } )
339- ) ;
340- } else {
341- let data = new URLSearchParams ( ) ;
342- data . append ( "themeId" , themeId ) ;
343-
344- axios
345- . put ( `/admin-ng/series/${ id } /theme` , data )
346- . then ( ( response ) => {
347- let themeResponse = response . data ;
348-
349- let seriesTheme = transformToIdValueArray ( themeResponse ) [ 0 ] . value ;
350-
351- dispatch ( setSeriesDetailsTheme ( seriesTheme ) ) ;
352- dispatch (
353- addNotification ( {
354- type : "warning" ,
355- key : "SERIES_THEME_REPROCESS_EXISTING_EVENTS" ,
356- duration : 10 ,
357- parameter : undefined ,
358- context : NOTIFICATION_CONTEXT
359- } )
360- ) ;
361- } )
362- . catch ( ( response ) => {
363- console . error ( response ) ;
364- } ) ;
365- }
308+ let themeId = values . theme ?. id ;
309+
310+ if ( ! themeId || themeId === '' ) {
311+ axios
312+ . delete ( `/admin-ng/series/${ id } /theme` )
313+ . then ( ( response ) => {
314+ dispatch ( setSeriesDetailsTheme ( values . theme ) ) ;
315+ dispatch (
316+ addNotification ( {
317+ type : "warning" ,
318+ key : "SERIES_THEME_REPROCESS_EXISTING_EVENTS" ,
319+ duration : 10 ,
320+ parameter : undefined ,
321+ context : NOTIFICATION_CONTEXT
322+ } )
323+ ) ;
324+ } )
325+ . catch ( ( response ) => {
326+ console . error ( response ) ;
327+ } ) ;
328+ } else {
329+ let data = new URLSearchParams ( ) ;
330+ data . append ( "themeId" , themeId ) ;
331+
332+ axios
333+ . put ( `/admin-ng/series/${ id } /theme` , data )
334+ . then ( ( response ) => {
335+ let themeResponse = response . data ;
336+
337+ let seriesTheme = transformToIdValueArray ( themeResponse ) [ 0 ] ;
338+
339+ dispatch ( setSeriesDetailsTheme ( seriesTheme ) ) ;
340+ dispatch (
341+ addNotification ( {
342+ type : "warning" ,
343+ key : "SERIES_THEME_REPROCESS_EXISTING_EVENTS" ,
344+ duration : 10 ,
345+ parameter : undefined ,
346+ context : NOTIFICATION_CONTEXT
347+ } )
348+ ) ;
349+ } )
350+ . catch ( ( response ) => {
351+ console . error ( response ) ;
352+ } ) ;
353+ }
366354} ) ;
367355
368356// fetch Tobira data of certain series from server
0 commit comments