2022-03-01 18:28:51 +00:00
|
|
|
import React, { useState, useCallback, useEffect } from "react";
|
2021-04-14 09:20:56 +00:00
|
|
|
|
2022-06-10 18:29:45 +00:00
|
|
|
import { ITeamFormData } from "services/entities/teams";
|
|
|
|
|
|
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";
|
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
|
|
|
|
|
|
|
|
interface ICreateTeamModalProps {
|
|
|
|
|
onCancel: () => void;
|
2022-06-10 18:29:45 +00:00
|
|
|
onSubmit: (formData: ITeamFormData) => void;
|
2022-03-01 18:28:51 +00:00
|
|
|
backendValidators: { [key: string]: string };
|
2022-08-29 15:21:37 +00:00
|
|
|
isUpdatingTeams: boolean;
|
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,
|
2022-08-29 15:21:37 +00:00
|
|
|
isUpdatingTeams,
|
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(
|
2024-03-13 19:09:16 +00:00
|
|
|
(evt: any) => {
|
2021-04-30 19:13:04 +00:00
|
|
|
evt.preventDefault();
|
|
|
|
|
onSubmit({
|
2024-10-03 22:59:10 +00:00
|
|
|
name: name.trim(),
|
2021-04-30 19:13:04 +00:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
[onSubmit, name]
|
|
|
|
|
);
|
2021-04-14 09:20:56 +00:00
|
|
|
|
|
|
|
|
return (
|
2026-02-17 21:19:33 +00:00
|
|
|
<Modal title="Create fleet" onExit={onCancel} className={baseClass}>
|
2022-08-29 15:21:37 +00:00
|
|
|
<form
|
|
|
|
|
className={`${baseClass}__form`}
|
|
|
|
|
onSubmit={onFormSubmit}
|
|
|
|
|
autoComplete="off"
|
|
|
|
|
>
|
|
|
|
|
<InputField
|
|
|
|
|
autofocus
|
|
|
|
|
name="name"
|
|
|
|
|
onChange={onInputChange}
|
2024-10-03 22:59:10 +00:00
|
|
|
onBlur={() => {
|
|
|
|
|
setName(name.trim());
|
|
|
|
|
}}
|
2026-02-17 21:19:33 +00:00
|
|
|
label="Fleet name"
|
2022-10-04 17:35:15 +00:00
|
|
|
placeholder="Workstations"
|
2022-08-29 15:21:37 +00:00
|
|
|
value={name}
|
|
|
|
|
error={errors.name}
|
2023-09-11 14:01:31 +00:00
|
|
|
ignore1password
|
2022-08-29 15:21:37 +00:00
|
|
|
/>
|
|
|
|
|
<div className="modal-cta-wrap">
|
|
|
|
|
<Button
|
|
|
|
|
type="submit"
|
2026-03-18 16:20:23 +00:00
|
|
|
disabled={name.trim() === ""}
|
2022-08-29 15:21:37 +00:00
|
|
|
className="create-loading"
|
|
|
|
|
isLoading={isUpdatingTeams}
|
|
|
|
|
>
|
|
|
|
|
Create
|
|
|
|
|
</Button>
|
|
|
|
|
<Button onClick={onCancel} variant="inverse">
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
2021-04-14 09:20:56 +00:00
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default CreateTeamModal;
|