@@ -140,6 +140,12 @@ function isUnionBranchNoise(error: DashboardWidgetConfigValidationError) {
140140 || error . message === 'must have required property "pivot"'
141141}
142142
143+ function getAdminForthPublicPath ( ) {
144+ const publicPath = ( ( import . meta as ImportMeta & { env ?: { VITE_ADMINFORTH_PUBLIC_PATH ?: string } } ) . env ?. VITE_ADMINFORTH_PUBLIC_PATH || '' ) . replace ( / \/ $ / , '' )
145+
146+ return publicPath === '/' ? '' : publicPath
147+ }
148+
143149async function parseDashboardResponse ( rawResponse : Response ) {
144150 const responseText = await rawResponse . text ( )
145151
@@ -156,8 +162,8 @@ async function parseDashboardResponse(rawResponse: Response) {
156162 }
157163}
158164
159- async function callDashboardApi ( path : string , body : Record < string , unknown > ) : Promise < DashboardResponse > {
160- const rawResponse = await fetch ( path , {
165+ async function postDashboardEndpoint ( path : string , body : Record < string , unknown > ) {
166+ const rawResponse = await fetch ( ` ${ getAdminForthPublicPath ( ) } /adminapi/v1 ${ path } ` , {
161167 method : 'POST' ,
162168 headers : {
163169 'Content-Type' : 'application/json' ,
@@ -166,7 +172,14 @@ async function callDashboardApi(path: string, body: Record<string, unknown>): Pr
166172 body : JSON . stringify ( body ) ,
167173 } )
168174
169- const response = await parseDashboardResponse ( rawResponse )
175+ return {
176+ rawResponse,
177+ response : await parseDashboardResponse ( rawResponse ) ,
178+ }
179+ }
180+
181+ async function callDashboardApi ( path : string , body : Record < string , unknown > ) : Promise < DashboardResponse > {
182+ const { rawResponse, response } = await postDashboardEndpoint ( path , body )
170183
171184 if ( ! rawResponse . ok ) {
172185 throw new DashboardApiError (
@@ -189,16 +202,7 @@ async function callDashboardApi(path: string, body: Record<string, unknown>): Pr
189202}
190203
191204async function callDashboardMutationApi ( path : string , body : Record < string , unknown > ) : Promise < DashboardMutationResponse > {
192- const rawResponse = await fetch ( path , {
193- method : 'POST' ,
194- headers : {
195- 'Content-Type' : 'application/json' ,
196- 'accept-language' : localStorage . getItem ( 'af_lang' ) || 'en' ,
197- } ,
198- body : JSON . stringify ( body ) ,
199- } )
200-
201- const response = await parseDashboardResponse ( rawResponse )
205+ const { rawResponse, response } = await postDashboardEndpoint ( path , body )
202206
203207 if ( ! rawResponse . ok ) {
204208 throw new DashboardApiError (
@@ -222,16 +226,7 @@ async function callDashboardWidgetDataApi(
222226 path : string ,
223227 body : Record < string , unknown > ,
224228) : Promise < DashboardWidgetDataResponse > {
225- const rawResponse = await fetch ( path , {
226- method : 'POST' ,
227- headers : {
228- 'Content-Type' : 'application/json' ,
229- 'accept-language' : localStorage . getItem ( 'af_lang' ) || 'en' ,
230- } ,
231- body : JSON . stringify ( body ) ,
232- } )
233-
234- const response = await parseDashboardResponse ( rawResponse )
229+ const { rawResponse, response } = await postDashboardEndpoint ( path , body )
235230
236231 if ( ! rawResponse . ok ) {
237232 throw new DashboardApiError (
@@ -252,42 +247,42 @@ async function callDashboardWidgetDataApi(
252247
253248export const dashboardApi = {
254249 async getDashboardConfig ( slug : string ) : Promise < DashboardResponse > {
255- return callDashboardApi ( '/adminapi/v1/ dashboard/get-config' , { slug } )
250+ return callDashboardApi ( '/dashboard/get-config' , { slug } )
256251 } ,
257252
258253 async addDashboardGroup ( slug : string ) : Promise < DashboardMutationResponse > {
259- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/add_dashboard_group' , { slug } )
254+ return callDashboardMutationApi ( '/dashboard/add_dashboard_group' , { slug } )
260255 } ,
261256
262257 async moveDashboardGroup (
263258 slug : string ,
264259 groupId : string ,
265260 direction : DashboardGroupMoveDirection ,
266261 ) : Promise < DashboardMutationResponse > {
267- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/move_dashboard_group' , {
262+ return callDashboardMutationApi ( '/dashboard/move_dashboard_group' , {
268263 slug,
269264 groupId,
270265 direction,
271266 } )
272267 } ,
273268
274269 async removeDashboardGroup ( slug : string , groupId : string ) : Promise < DashboardMutationResponse > {
275- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/remove_dashboard_group' , {
270+ return callDashboardMutationApi ( '/dashboard/remove_dashboard_group' , {
276271 slug,
277272 groupId,
278273 } )
279274 } ,
280275
281276 async setDashboardGroupConfig ( slug : string , groupId : string , config : EditableDashboardGroupConfig ) : Promise < DashboardMutationResponse > {
282- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/set_dashboard_group_config' , {
277+ return callDashboardMutationApi ( '/dashboard/set_dashboard_group_config' , {
283278 slug,
284279 groupId,
285280 config,
286281 } )
287282 } ,
288283
289284 async addDashboardWidget ( slug : string , groupId : string ) : Promise < DashboardMutationResponse > {
290- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/add_dashboard_widget' , {
285+ return callDashboardMutationApi ( '/dashboard/add_dashboard_widget' , {
291286 slug,
292287 groupId,
293288 } )
@@ -298,22 +293,22 @@ export const dashboardApi = {
298293 widgetId : string ,
299294 direction : DashboardWidgetMoveDirection ,
300295 ) : Promise < DashboardMutationResponse > {
301- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/move_dashboard_widget' , {
296+ return callDashboardMutationApi ( '/dashboard/move_dashboard_widget' , {
302297 slug,
303298 widgetId,
304299 direction,
305300 } )
306301 } ,
307302
308303 async removeDashboardWidget ( slug : string , widgetId : string ) : Promise < DashboardMutationResponse > {
309- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/remove_dashboard_widget' , {
304+ return callDashboardMutationApi ( '/dashboard/remove_dashboard_widget' , {
310305 slug,
311306 widgetId,
312307 } )
313308 } ,
314309
315310 async setWidgetConfig ( slug : string , widgetId : string , config : unknown ) : Promise < DashboardMutationResponse > {
316- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/set_widget_config' , {
311+ return callDashboardMutationApi ( '/dashboard/set_widget_config' , {
317312 slug,
318313 widgetId,
319314 config,
@@ -325,7 +320,7 @@ export const dashboardApi = {
325320 widgetId : string ,
326321 config : ConfigurableTableWidgetConfig ,
327322 ) : Promise < DashboardMutationResponse > {
328- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/configure_table_widget' , {
323+ return callDashboardMutationApi ( '/dashboard/configure_table_widget' , {
329324 slug,
330325 widgetId,
331326 config,
@@ -337,7 +332,7 @@ export const dashboardApi = {
337332 widgetId : string ,
338333 config : ConfigurableKpiCardWidgetConfig ,
339334 ) : Promise < DashboardMutationResponse > {
340- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/configure_kpi_card_widget' , {
335+ return callDashboardMutationApi ( '/dashboard/configure_kpi_card_widget' , {
341336 slug,
342337 widgetId,
343338 config,
@@ -349,7 +344,7 @@ export const dashboardApi = {
349344 widgetId : string ,
350345 config : ConfigurableGaugeCardWidgetConfig ,
351346 ) : Promise < DashboardMutationResponse > {
352- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/configure_gauge_card_widget' , {
347+ return callDashboardMutationApi ( '/dashboard/configure_gauge_card_widget' , {
353348 slug,
354349 widgetId,
355350 config,
@@ -361,7 +356,7 @@ export const dashboardApi = {
361356 widgetId : string ,
362357 config : ConfigurableLineChartWidgetConfig ,
363358 ) : Promise < DashboardMutationResponse > {
364- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/configure_line_chart_widget' , {
359+ return callDashboardMutationApi ( '/dashboard/configure_line_chart_widget' , {
365360 slug,
366361 widgetId,
367362 config,
@@ -373,7 +368,7 @@ export const dashboardApi = {
373368 widgetId : string ,
374369 config : ConfigurableBarChartWidgetConfig ,
375370 ) : Promise < DashboardMutationResponse > {
376- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/configure_bar_chart_widget' , {
371+ return callDashboardMutationApi ( '/dashboard/configure_bar_chart_widget' , {
377372 slug,
378373 widgetId,
379374 config,
@@ -385,7 +380,7 @@ export const dashboardApi = {
385380 widgetId : string ,
386381 config : ConfigurableStackedBarChartWidgetConfig ,
387382 ) : Promise < DashboardMutationResponse > {
388- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/configure_stacked_bar_chart_widget' , {
383+ return callDashboardMutationApi ( '/dashboard/configure_stacked_bar_chart_widget' , {
389384 slug,
390385 widgetId,
391386 config,
@@ -397,7 +392,7 @@ export const dashboardApi = {
397392 widgetId : string ,
398393 config : ConfigurablePieChartWidgetConfig ,
399394 ) : Promise < DashboardMutationResponse > {
400- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/configure_pie_chart_widget' , {
395+ return callDashboardMutationApi ( '/dashboard/configure_pie_chart_widget' , {
401396 slug,
402397 widgetId,
403398 config,
@@ -409,7 +404,7 @@ export const dashboardApi = {
409404 widgetId : string ,
410405 config : ConfigurableHistogramChartWidgetConfig ,
411406 ) : Promise < DashboardMutationResponse > {
412- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/configure_histogram_chart_widget' , {
407+ return callDashboardMutationApi ( '/dashboard/configure_histogram_chart_widget' , {
413408 slug,
414409 widgetId,
415410 config,
@@ -421,7 +416,7 @@ export const dashboardApi = {
421416 widgetId : string ,
422417 config : ConfigurableFunnelChartWidgetConfig ,
423418 ) : Promise < DashboardMutationResponse > {
424- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/configure_funnel_chart_widget' , {
419+ return callDashboardMutationApi ( '/dashboard/configure_funnel_chart_widget' , {
425420 slug,
426421 widgetId,
427422 config,
@@ -433,7 +428,7 @@ export const dashboardApi = {
433428 widgetId : string ,
434429 config : ConfigurablePivotTableWidgetConfig ,
435430 ) : Promise < DashboardMutationResponse > {
436- return callDashboardMutationApi ( '/adminapi/v1/ dashboard/configure_pivot_table_widget' , {
431+ return callDashboardMutationApi ( '/dashboard/configure_pivot_table_widget' , {
437432 slug,
438433 widgetId,
439434 config,
@@ -445,7 +440,7 @@ export const dashboardApi = {
445440 widgetId : string ,
446441 request : DashboardWidgetDataRequest = { } ,
447442 ) : Promise < DashboardWidgetDataResponse > {
448- return callDashboardWidgetDataApi ( '/adminapi/v1/ dashboard/get_dashboard_widget_data' , {
443+ return callDashboardWidgetDataApi ( '/dashboard/get_dashboard_widget_data' , {
449444 slug,
450445 widgetId,
451446 ...request ,
0 commit comments