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