feat(ui): indicate valid role name
parent
bedb63780f
commit
8a62384e16
|
@ -1,5 +1,6 @@
|
||||||
import React, {useCallback, useState} from 'react'
|
import React, {useCallback, useState} from 'react'
|
||||||
import {
|
import {
|
||||||
|
ComponentStatus,
|
||||||
Form,
|
Form,
|
||||||
Input,
|
Input,
|
||||||
OverlayBody,
|
OverlayBody,
|
||||||
|
@ -8,6 +9,11 @@ import {
|
||||||
OverlayTechnology,
|
OverlayTechnology,
|
||||||
} from 'src/reusable_ui'
|
} from 'src/reusable_ui'
|
||||||
|
|
||||||
|
const minLen = 3
|
||||||
|
export function validateRoleName(name: string): boolean {
|
||||||
|
return name?.length >= minLen
|
||||||
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
create: (role: {name: string}) => void
|
create: (role: {name: string}) => void
|
||||||
setVisible: (visible: boolean) => void
|
setVisible: (visible: boolean) => void
|
||||||
|
@ -30,6 +36,11 @@ const CreateRoleDialog = ({visible, setVisible, create}: Props) => {
|
||||||
value={name}
|
value={name}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
onChange={e => setName(e.target.value)}
|
onChange={e => setName(e.target.value)}
|
||||||
|
status={
|
||||||
|
validateRoleName(name)
|
||||||
|
? ComponentStatus.Valid
|
||||||
|
: ComponentStatus.Default
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Form.Element>
|
</Form.Element>
|
||||||
<Form.Footer>
|
<Form.Footer>
|
||||||
|
|
|
@ -26,14 +26,15 @@ import computeEffectiveDBPermissions from './util/computeEffectiveDBPermissions'
|
||||||
import useDebounce from 'src/utils/useDebounce'
|
import useDebounce from 'src/utils/useDebounce'
|
||||||
import useChangeEffect from 'src/utils/useChangeEffect'
|
import useChangeEffect from 'src/utils/useChangeEffect'
|
||||||
import {ComponentSize, MultiSelectDropdown, SlideToggle} from 'src/reusable_ui'
|
import {ComponentSize, MultiSelectDropdown, SlideToggle} from 'src/reusable_ui'
|
||||||
import CreateRoleDialog from 'src/admin/components/influxdb/CreateRoleDialog'
|
import CreateRoleDialog, {
|
||||||
|
validateRoleName,
|
||||||
|
} from 'src/admin/components/influxdb/CreateRoleDialog'
|
||||||
|
|
||||||
const minLen = 3
|
|
||||||
const validateRole = (
|
const validateRole = (
|
||||||
user: Pick<UserRole, 'name'>,
|
role: Pick<UserRole, 'name'>,
|
||||||
notify: NotificationAction
|
notify: NotificationAction
|
||||||
) => {
|
) => {
|
||||||
if (user.name.length < minLen) {
|
if (!validateRoleName(role.name)) {
|
||||||
notify(notifyRoleNameInvalid())
|
notify(notifyRoleNameInvalid())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue