budibase/packages/builder/src/components/design/NavigationPanel/ScreenDetailsModal.svelte

61 lines
1.5 KiB
Svelte
Raw Normal View History

2021-11-10 17:04:27 +01:00
<script>
import { ModalContent, Input } from "@budibase/bbui"
import sanitizeUrl from "builderStore/store/screenTemplates/utils/sanitizeUrl"
import { selectedAccessRole, allScreens } from "builderStore"
import { get } from "svelte/store"
2021-11-10 17:04:27 +01:00
export let onConfirm
export let onCancel
2022-03-02 20:26:43 +01:00
export let screenUrl
export let confirmText = "Continue"
2021-11-23 21:14:28 +01:00
let routeError
2022-03-02 20:26:43 +01:00
let touched = false
let screenAccessRole = $selectedAccessRole + ""
const routeChanged = event => {
if (!event.detail.startsWith("/")) {
screenUrl = "/" + event.detail
}
2022-03-02 20:26:43 +01:00
touched = true
screenUrl = sanitizeUrl(screenUrl)
if (routeExists(screenUrl)) {
routeError = "This URL is already taken for this access role"
} else {
routeError = null
}
}
const routeExists = url => {
const roleId = get(selectedAccessRole) || "BASIC"
return get(allScreens).some(
screen =>
screen.routing.route.toLowerCase() === url.toLowerCase() &&
screen.routing.roleId === roleId
)
}
2021-11-29 12:53:46 +01:00
const confirmScreenDetails = async () => {
await onConfirm({
screenUrl,
})
}
2021-11-10 17:04:27 +01:00
</script>
<ModalContent
size="M"
2021-11-16 13:18:13 +01:00
title={"Enter details"}
{confirmText}
onConfirm={confirmScreenDetails}
{onCancel}
2021-11-10 17:04:27 +01:00
cancelText={"Back"}
disabled={!screenAccessRole || !screenUrl || routeError || !touched}
2021-11-10 17:04:27 +01:00
>
<Input
label="Enter a URL for the new screen"
error={routeError}
bind:value={screenUrl}
on:change={routeChanged}
/>
2021-11-10 17:04:27 +01:00
</ModalContent>