From 89499d346c598727570fa1ce9080ff925bd88e98 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Mon, 2 Jan 2023 17:28:07 +0100 Subject: [PATCH] feat(ui) - cards - widget form updates --- .../components/WidgetForm/WidgetForm.tsx | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/frontend/app/components/Dashboard/components/WidgetForm/WidgetForm.tsx b/frontend/app/components/Dashboard/components/WidgetForm/WidgetForm.tsx index b4e2613e9..ac14b68db 100644 --- a/frontend/app/components/Dashboard/components/WidgetForm/WidgetForm.tsx +++ b/frontend/app/components/Dashboard/components/WidgetForm/WidgetForm.tsx @@ -109,19 +109,15 @@ function WidgetForm(props: Props) { console.error(e); } } - metricStore.save(metric).then((metric: any) => { - if (wasCreating) { - if (parseInt(dashboardId) > 0) { - history.replace(withSiteId(dashboardMetricDetails(dashboardId, metric.metricId), siteId)); - const dashboard = dashboardStore.getDashboard(parseInt(dashboardId)); - if (dashboard) { - dashboardStore.addWidgetToDashboard(dashboard, [metric.metricId]); - } - } else { - history.replace(withSiteId(metricDetails(metric.metricId), siteId)); - } + const savedMetric = await metricStore.save(metric); + if (wasCreating) { + if (parseInt(dashboardId, 10) > 0) { + history.replace(withSiteId(dashboardMetricDetails(dashboardId, savedMetric.metricId), siteId)); + dashboardStore.addWidgetToDashboard(dashboardStore.getDashboard(parseInt(dashboardId, 10))!, [savedMetric.metricId]); + } else { + history.replace(withSiteId(metricDetails(savedMetric.metricId), siteId)); } - }); + } }; const onDelete = async () => {