// comment
import React, { useState, useEffect, useContext } from 'react';
import { Table, Space, Button, Modal, Checkbox, Input, Typography } from 'antd';
import { ServerStatusContext } from '../utils/server-status-context';
import { DeleteOutlined } from '@ant-design/icons';
import isValidUrl from '../utils/urls';
import FormStatusIndicator from '../components/config/form-status-indicator';
import {
createInputStatus,
StatusState,
STATUS_ERROR,
STATUS_PROCESSING,
STATUS_SUCCESS,
} from '../utils/input-statuses';
import {
postConfigUpdateToAPI,
API_EXTERNAL_ACTIONS,
RESET_TIMEOUT,
} from '../utils/config-constants';
const { Title, Paragraph } = Typography;
let resetTimer = null;
interface Props {
onCancel: () => void;
onOk: any; // todo: make better type
visible: boolean;
}
function NewActionModal(props: Props) {
const { onOk, onCancel, visible } = props;
const [actionUrl, setActionUrl] = useState('');
const [actionTitle, setActionTitle] = useState('');
const [actionDescription, setActionDescription] = useState('');
const [actionIcon, setActionIcon] = useState('');
const [actionColor, setActionColor] = useState('');
const [openExternally, setOpenExternally] = useState(false);
function save() {
onOk(actionUrl, actionTitle, actionDescription, actionIcon, actionColor, openExternally);
setActionUrl('')
setActionTitle('')
setActionDescription('')
setActionIcon('')
setActionColor('')
setOpenExternally(false)
}
function canSave(): Boolean {
try {
const validationObject = new URL(actionUrl);
if (validationObject.protocol !== 'https:') {
return false;
}
} catch {
return false;
}
return isValidUrl(actionUrl) && actionTitle !== '';
}
const okButtonProps = {
disabled: !canSave(),
};
const onOpenExternallyChanged = checkbox => {
setOpenExternally(checkbox.target.checked);
};
return (
Read more about external actions.
setActionUrl(input.currentTarget.value)}
/>
setActionTitle(input.currentTarget.value)}
/>
setActionDescription(input.currentTarget.value)}
/>
setActionIcon(input.currentTarget.value)}
/>
setActionColor(input.currentTarget.value)}
/>
Optional background color of the action button.