2022-03-01 18:28:51 +00:00
|
|
|
|
import React, { useState, useCallback, useEffect } from "react";
|
2021-04-14 09:20:56 +00:00
|
|
|
|
|
2021-11-07 06:41:09 +00:00
|
|
|
|
import Modal from "components/Modal";
|
2021-04-14 16:52:15 +00:00
|
|
|
|
import Button from "components/buttons/Button";
|
|
|
|
|
|
import InfoBanner from "components/InfoBanner/InfoBanner";
|
2021-04-29 13:47:33 +00:00
|
|
|
|
// @ts-ignore
|
2022-03-04 16:36:12 +00:00
|
|
|
|
import InputField from "components/forms/fields/InputField";
|
2021-04-14 09:20:56 +00:00
|
|
|
|
|
2021-04-14 16:52:15 +00:00
|
|
|
|
const baseClass = "create-team-modal";
|
2021-04-14 09:20:56 +00:00
|
|
|
|
|
|
|
|
|
|
export interface ICreateTeamFormData {
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface ICreateTeamModalProps {
|
|
|
|
|
|
onCancel: () => void;
|
|
|
|
|
|
onSubmit: (formData: ICreateTeamFormData) => void;
|
2022-03-01 18:28:51 +00:00
|
|
|
|
backendValidators: { [key: string]: string };
|
2021-04-14 09:20:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-22 15:34:45 +00:00
|
|
|
|
const CreateTeamModal = ({
|
|
|
|
|
|
onCancel,
|
|
|
|
|
|
onSubmit,
|
2022-03-01 18:28:51 +00:00
|
|
|
|
backendValidators,
|
2021-10-22 15:34:45 +00:00
|
|
|
|
}: ICreateTeamModalProps): JSX.Element => {
|
2021-04-14 16:52:15 +00:00
|
|
|
|
const [name, setName] = useState("");
|
2022-03-01 18:28:51 +00:00
|
|
|
|
const [errors, setErrors] = useState<{ [key: string]: string }>(
|
|
|
|
|
|
backendValidators
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
setErrors(backendValidators);
|
|
|
|
|
|
}, [backendValidators]);
|
2021-04-14 09:20:56 +00:00
|
|
|
|
|
2021-04-14 16:52:15 +00:00
|
|
|
|
const onInputChange = useCallback(
|
|
|
|
|
|
(value: string) => {
|
|
|
|
|
|
setName(value);
|
2022-03-01 18:28:51 +00:00
|
|
|
|
setErrors({});
|
2021-04-14 16:52:15 +00:00
|
|
|
|
},
|
|
|
|
|
|
[setName]
|
|
|
|
|
|
);
|
2021-04-14 09:20:56 +00:00
|
|
|
|
|
2021-04-30 19:13:04 +00:00
|
|
|
|
const onFormSubmit = useCallback(
|
|
|
|
|
|
(evt) => {
|
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
onSubmit({
|
|
|
|
|
|
name,
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
[onSubmit, name]
|
|
|
|
|
|
);
|
2021-04-14 09:20:56 +00:00
|
|
|
|
|
|
|
|
|
|
return (
|
2021-04-14 16:52:15 +00:00
|
|
|
|
<Modal title={"Create team"} onExit={onCancel} className={baseClass}>
|
2021-10-27 17:31:45 +00:00
|
|
|
|
<form
|
|
|
|
|
|
className={`${baseClass}__form`}
|
|
|
|
|
|
onSubmit={onFormSubmit}
|
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
|
>
|
2022-03-04 16:36:12 +00:00
|
|
|
|
<InputField
|
2021-04-14 09:20:56 +00:00
|
|
|
|
autofocus
|
|
|
|
|
|
name="name"
|
|
|
|
|
|
onChange={onInputChange}
|
2022-03-04 16:36:12 +00:00
|
|
|
|
label="Team name"
|
2021-04-14 09:20:56 +00:00
|
|
|
|
placeholder="Team name"
|
|
|
|
|
|
value={name}
|
2022-03-01 18:28:51 +00:00
|
|
|
|
error={errors.name}
|
2021-04-14 09:20:56 +00:00
|
|
|
|
/>
|
|
|
|
|
|
<InfoBanner className={`${baseClass}__sandbox-info`}>
|
2021-04-14 16:52:15 +00:00
|
|
|
|
<p className={`${baseClass}__info-header`}>
|
|
|
|
|
|
Need to test queries and configurations before deploying?
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
A popular pattern is to end a team’s name with “- Sandbox”, then you
|
|
|
|
|
|
can use this to test new queries and configuration with staging
|
|
|
|
|
|
hosts or volunteers acting as canaries.
|
|
|
|
|
|
</p>
|
2021-04-14 09:20:56 +00:00
|
|
|
|
</InfoBanner>
|
2022-04-27 20:40:28 +00:00
|
|
|
|
<div className="modal-cta-wrap">
|
|
|
|
|
|
<Button onClick={onCancel} variant="inverse">
|
2021-04-14 09:20:56 +00:00
|
|
|
|
Cancel
|
|
|
|
|
|
</Button>
|
2022-04-27 20:40:28 +00:00
|
|
|
|
<Button type="submit" variant="brand" disabled={name === ""}>
|
|
|
|
|
|
Create
|
|
|
|
|
|
</Button>
|
2021-04-14 09:20:56 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default CreateTeamModal;
|