import React, {useState} from 'react';
import { StrategySummary, EditStrategySpec } from 'wdk-client/Utils/WdkUser';
import './EditStrategyForm.css';
interface Props {
strategy: StrategySummary;
clearActiveModal: () => void;
editStrategy: (strategyId: number, properties: EditStrategySpec) => void;
}
export default function SaveStrategyForm(props: Props) {
const [ name, setName ] = useState(props.strategy.name);
const [ isPublic, setIsPublic ] = useState(props.strategy.isPublic);
const [ description, setDescription ] = useState(props.strategy.description || '');
const maxDescriptionSize = 4000;
const descriptionSize = description.length;
const descriptionTooLong = descriptionSize > maxDescriptionSize;
return (
);
function handleSubmit(event: React.FormEvent) {
event.preventDefault();
props.editStrategy(props.strategy.strategyId, { name, isPublic, description });
props.clearActiveModal();
}
function handleCancel(event: React.MouseEvent) {
event.preventDefault();
props.clearActiveModal();
}
function handleNameChange(event: React.ChangeEvent) {
const { target } = event;
const { value } = target;
setName(value);
target.setCustomValidity(value.length > 200 ? 'The value is too long.' : '');
}
function handleDescriptionChange(event: React.ChangeEvent) {
const { target } = event;
const { value } = target;
setDescription(value);
target.setCustomValidity(value.length > maxDescriptionSize ? 'The value is too long.' : '');
}
function handleIsPublicChange(event: React.ChangeEvent) {
setIsPublic(event.target.checked);
}
}