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

53 lines
1.3 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"
2021-11-10 17:04:27 +01:00
export let modal
export let navigationSelectionModal
2021-11-11 13:09:36 +01:00
export let screenName
export let url
let routeError
let roleId = $selectedAccessRole || "BASIC"
const routeChanged = event => {
if (!event.detail.startsWith("/")) {
url = "/" + event.detail
}
url = sanitizeUrl(url)
if (routeExists(url, roleId)) {
routeError = "This URL is already taken for this access role"
} else {
routeError = ""
}
}
const routeExists = (url, roleId) => {
return $allScreens.some(
screen =>
screen.routing.route.toLowerCase() === url.toLowerCase() &&
screen.routing.roleId === roleId
)
}
2021-11-10 17:04:27 +01:00
</script>
<ModalContent
size="M"
title={"Enter Details"}
2021-11-10 17:04:27 +01:00
confirmText={"Continue"}
onCancel={() => modal.show()}
onConfirm={() => navigationSelectionModal.show()}
cancelText={"Back"}
disabled={!screenName || !url || routeError}
2021-11-10 17:04:27 +01:00
>
2021-11-11 13:09:36 +01:00
<Input label="Name" bind:value={screenName} />
<Input
label="URL"
error={routeError}
bind:value={url}
on:change={routeChanged}
/>
2021-11-10 17:04:27 +01:00
</ModalContent>