0

Add some simple validation to access token and webhook forms

This commit is contained in:
Gabe Kangas 2021-01-17 11:11:58 -08:00
parent 7b6fd6a93d
commit e0f6f73f05
2 changed files with 18 additions and 10 deletions

View File

@ -34,15 +34,14 @@ function convertScopeStringToTag(scopeString) {
} }
function NewTokenModal(props) { function NewTokenModal(props) {
var selectedScopes = []; const [selectedScopes, setSelectedScopes] = useState([]);
const scopes = Object.keys(availableScopes).map(function (key) { const scopes = Object.keys(availableScopes).map(function (key) {
return { value: key, label: availableScopes[key].description } return { value: key, label: availableScopes[key].description }
}); });
function onChange(checkedValues) { function onChange(checkedValues) {
selectedScopes = checkedValues setSelectedScopes(checkedValues);
} }
function saveToken() { function saveToken() {
@ -51,8 +50,12 @@ function NewTokenModal(props) {
const [name, setName] = useState(''); const [name, setName] = useState('');
const okButtonProps = {
disabled: selectedScopes.length === 0 || name === ''
};
return ( return (
<Modal title="Create New Access token" visible={props.visible} onOk={saveToken} onCancel={props.onCancel}> <Modal title="Create New Access token" visible={props.visible} onOk={saveToken} onCancel={props.onCancel} okButtonProps={okButtonProps}>
<p><Input value={name} placeholder="Access token name/description" onChange={(input) => setName(input.currentTarget.value)} /></p> <p><Input value={name} placeholder="Access token name/description" onChange={(input) => setName(input.currentTarget.value)} /></p>
<p> <p>

View File

@ -1,6 +1,7 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { Table, Tag, Space, Button, Modal, Checkbox, Input, Typography, Tooltip, Select } from 'antd'; import { Table, Tag, Space, Button, Modal, Checkbox, Input, Typography, Tooltip, Select } from 'antd';
import { DeleteOutlined, EyeTwoTone, EyeInvisibleOutlined } from '@ant-design/icons'; import { DeleteOutlined, EyeTwoTone, EyeInvisibleOutlined } from '@ant-design/icons';
import {isValidUrl} from '../utils/urls';
const { Title, Paragraph, Text } = Typography; const { Title, Paragraph, Text } = Typography;
const { Option } = Select; const { Option } = Select;
@ -41,8 +42,8 @@ function convertEventStringToTag(eventString) {
} }
function NewWebhookModal(props) { function NewWebhookModal(props) {
var selectedEvents = []; const [selectedEvents, setSelectedEvents] = useState([]);
const [name, setName] = useState(''); const [webhookUrl, setWebhookUrl] = useState('');
const events = Object.keys(availableEvents).map(function (key) { const events = Object.keys(availableEvents).map(function (key) {
return { value: key, label: availableEvents[key].description } return { value: key, label: availableEvents[key].description }
@ -50,16 +51,20 @@ function NewWebhookModal(props) {
function onChange(checkedValues) { function onChange(checkedValues) {
selectedEvents = checkedValues setSelectedEvents(checkedValues);
} }
function save() { function save() {
props.onOk(name, selectedEvents) props.onOk(webhookUrl, selectedEvents)
} }
const okButtonProps = {
disabled: selectedEvents.length === 0 || !isValidUrl(webhookUrl)
};
return ( return (
<Modal title="Create New Webhook" visible={props.visible} onOk={save} onCancel={props.onCancel}> <Modal title="Create New Webhook" visible={props.visible} onOk={save} onCancel={props.onCancel} okButtonProps={okButtonProps}>
<div><Input value={name} placeholder="https://myserver.com/webhook" onChange={(input) => setName(input.currentTarget.value)} /></div> <div><Input value={webhookUrl} placeholder="https://myserver.com/webhook" onChange={(input) => setWebhookUrl(input.currentTarget.value)} /></div>
<p> <p>
Select the events that will be sent to this webhook. Select the events that will be sent to this webhook.