Add validation to editing roles
This commit is contained in:
parent
bc03f1e473
commit
0a627e6cf5
|
@ -28,6 +28,27 @@
|
||||||
let tempDescription
|
let tempDescription
|
||||||
let tempColor
|
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 () => {
|
const deleteNode = async () => {
|
||||||
flow.deleteElements({
|
flow.deleteElements({
|
||||||
nodes: [{ id }],
|
nodes: [{ id }],
|
||||||
|
@ -100,15 +121,18 @@
|
||||||
title={`Edit ${data.displayName}`}
|
title={`Edit ${data.displayName}`}
|
||||||
confirmText="Save"
|
confirmText="Save"
|
||||||
onConfirm={saveChanges}
|
onConfirm={saveChanges}
|
||||||
|
disabled={invalid}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
label="Name"
|
label="Name"
|
||||||
value={tempDisplayName}
|
value={tempDisplayName}
|
||||||
|
error={nameError}
|
||||||
on:change={e => (tempDisplayName = e.detail)}
|
on:change={e => (tempDisplayName = e.detail)}
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="Description"
|
label="Description"
|
||||||
value={tempDescription}
|
value={tempDescription}
|
||||||
|
error={descriptionError}
|
||||||
on:change={e => (tempDescription = e.detail)}
|
on:change={e => (tempDescription = e.detail)}
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
|
|
Loading…
Reference in New Issue