diff --git a/packages/builder/src/components/backend/RoleEditor/RoleNode.svelte b/packages/builder/src/components/backend/RoleEditor/RoleNode.svelte index eda225b604..e07ab70ff6 100644 --- a/packages/builder/src/components/backend/RoleEditor/RoleNode.svelte +++ b/packages/builder/src/components/backend/RoleEditor/RoleNode.svelte @@ -28,6 +28,27 @@ let tempDescription let tempColor + $: nameError = validateName(tempDisplayName, $roles) + $: descriptionError = validateDescription(tempDescription) + $: invalid = nameError || descriptionError + + const validateName = (name, roles) => { + if (!name?.length) { + return "Please enter a name" + } + if (roles.some(x => x.displayName === name && x._id !== id)) { + return "That name is already used by another role" + } + return null + } + + const validateDescription = description => { + if (!description?.length) { + return "Please enter a name" + } + return null + } + const deleteNode = async () => { flow.deleteElements({ nodes: [{ id }], @@ -100,15 +121,18 @@ title={`Edit ${data.displayName}`} confirmText="Save" onConfirm={saveChanges} + disabled={invalid} > (tempDisplayName = e.detail)} /> (tempDescription = e.detail)} />