Navigate when the modal is closed and the datasource was created

This commit is contained in:
Adria Navarro 2023-06-09 11:57:17 +01:00
parent 9021a095b1
commit 0bd35be861
1 changed files with 10 additions and 7 deletions

View File

@ -10,7 +10,7 @@
import { IntegrationNames, IntegrationTypes } from "constants/backend" import { IntegrationNames, IntegrationTypes } from "constants/backend"
import GoogleButton from "../_components/GoogleButton.svelte" import GoogleButton from "../_components/GoogleButton.svelte"
import { organisation } from "stores/portal" import { organisation } from "stores/portal"
import { onMount } from "svelte" import { onMount, onDestroy } from "svelte"
import { import {
validateDatasourceConfig, validateDatasourceConfig,
getDatasourceInfo, getDatasourceInfo,
@ -34,6 +34,7 @@
onMount(async () => { onMount(async () => {
await organisation.init() await organisation.init()
}) })
const integrationName = IntegrationNames[IntegrationTypes.GOOGLE_SHEETS] const integrationName = IntegrationNames[IntegrationTypes.GOOGLE_SHEETS]
export const GoogleDatasouceConfigStep = { export const GoogleDatasouceConfigStep = {
@ -82,7 +83,6 @@
} }
if (!integration.features[DatasourceFeature.FETCH_TABLE_NAMES]) { if (!integration.features[DatasourceFeature.FETCH_TABLE_NAMES]) {
$goto(`./datasource/${datasource._id}`)
notifications.success(`Datasource created successfully.`) notifications.success(`Datasource created successfully.`)
return return
} }
@ -115,18 +115,22 @@
}) })
} }
$goto(`./datasource/${datasource._id}`) return
} catch (err) { } catch (err) {
notifications.error(err?.message ?? "Error fetching the sheets") notifications.error(err?.message ?? "Error fetching the sheets")
// prevent the modal from closing // prevent the modal from closing
return false return false
} }
}, },
onCancel: async () => {
$goto(`./datasource/${datasource._id}`)
},
}, },
} }
// This will handle the user closing the modal pressing outside the modal
onDestroy(async () => {
if (step === GoogleDatasouceConfigStep.SET_SHEETS) {
await $goto(`./datasource/${datasource._id}`)
}
})
</script> </script>
<ModalContent <ModalContent
@ -136,7 +140,6 @@
confirmText={modalConfig[step].confirmButtonText} confirmText={modalConfig[step].confirmButtonText}
showConfirmButton={!!modalConfig[step].onConfirm} showConfirmButton={!!modalConfig[step].onConfirm}
onConfirm={modalConfig[step].onConfirm} onConfirm={modalConfig[step].onConfirm}
onCancel={modalConfig[step].onCancel}
disabled={!isValid} disabled={!isValid}
> >
{#if step === GoogleDatasouceConfigStep.AUTH} {#if step === GoogleDatasouceConfigStep.AUTH}