@@ -140,22 +140,30 @@ const getExportFileName = () => {
140140 return `stackable-export-${ y } ${ m } ${ d } -${ h } ${ min } ${ s } .json`
141141}
142142
143- const ExportSettings = ( { settings, onClose } ) => {
143+ const ExportSettings = ( {
144+ settings, onClose, setNotice,
145+ } ) => {
144146 const [ exportedSettings , setExportedSettings ] = useState ( { } )
145147
146148 const handleExport = ( ) => {
147- const dataStr = JSON . stringify ( exportedSettings , null , 4 )
148- const blob = new Blob ( [ dataStr ] , { type : 'application/json' } )
149- const url = URL . createObjectURL ( blob )
150- const a = document . createElement ( 'a' )
151- a . href = url
152-
153- a . download = getExportFileName ( )
154- document . body . appendChild ( a )
155- a . click ( )
156- document . body . removeChild ( a )
157- URL . revokeObjectURL ( url )
158- onClose ( )
149+ try {
150+ const dataStr = JSON . stringify ( exportedSettings , null , 4 )
151+ const blob = new Blob ( [ dataStr ] , { type : 'application/json' } )
152+ const url = URL . createObjectURL ( blob )
153+ const a = document . createElement ( 'a' )
154+ a . href = url
155+
156+ a . download = getExportFileName ( )
157+ document . body . appendChild ( a )
158+ a . click ( )
159+ document . body . removeChild ( a )
160+ URL . revokeObjectURL ( url )
161+ onClose ( )
162+ } catch ( e ) {
163+ setNotice ( __ ( 'Failed to export settings.' , i18n ) )
164+ // eslint-disable-next-line no-console
165+ console . error ( sprintf ( __ ( 'Stackable: Export error - %s' , i18n ) , e ) )
166+ }
159167 }
160168
161169 const AllExportSettings = useMemo ( ( ) => applyFilters ( 'stackable.admin-settings.export-settings' , Fragment ) , [ ] )
0 commit comments