mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
## Issue - First batch of @iansltx 's work of cleaning up lint warnings #43387 ## Description - Quick PR review and grabbed as many confirmed low-risk quick wins as I could `git checkout lint-cleanup <file/path/1> <file/path/2>` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes This release contains internal code improvements with one minor UI tweak: * **Style** * Dropdown menu background color adjusted for clearer contrast in action lists * **Refactor** * Improved type safety across the codebase with stricter TypeScript annotations * Removed unused imports and constants to reduce code clutter * Enhanced React hook dependency arrays for more consistent component behavior <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Rachel Perkins <rachel@Rachels-MacBook-Pro.local> Co-authored-by: Ian Littman <iansltx@gmail.com>
90 lines
2.1 KiB
TypeScript
90 lines
2.1 KiB
TypeScript
import React, { useState, useCallback, useEffect } from "react";
|
|
|
|
import { ITeamFormData } from "services/entities/teams";
|
|
|
|
import Modal from "components/Modal";
|
|
import Button from "components/buttons/Button";
|
|
|
|
import InputField from "components/forms/fields/InputField";
|
|
|
|
const baseClass = "create-team-modal";
|
|
|
|
interface ICreateTeamModalProps {
|
|
onCancel: () => void;
|
|
onSubmit: (formData: ITeamFormData) => void;
|
|
backendValidators: { [key: string]: string };
|
|
isUpdatingTeams: boolean;
|
|
}
|
|
|
|
const CreateTeamModal = ({
|
|
onCancel,
|
|
onSubmit,
|
|
backendValidators,
|
|
isUpdatingTeams,
|
|
}: ICreateTeamModalProps): JSX.Element => {
|
|
const [name, setName] = useState("");
|
|
const [errors, setErrors] = useState<{ [key: string]: string }>(
|
|
backendValidators
|
|
);
|
|
|
|
useEffect(() => {
|
|
setErrors(backendValidators);
|
|
}, [backendValidators]);
|
|
|
|
const onInputChange = useCallback(
|
|
(value: string) => {
|
|
setName(value);
|
|
setErrors({});
|
|
},
|
|
[setName]
|
|
);
|
|
|
|
const onFormSubmit = useCallback(
|
|
(evt: React.FormEvent<HTMLFormElement>) => {
|
|
evt.preventDefault();
|
|
onSubmit({
|
|
name: name.trim(),
|
|
});
|
|
},
|
|
[onSubmit, name]
|
|
);
|
|
|
|
return (
|
|
<Modal title="Create fleet" onExit={onCancel} className={baseClass}>
|
|
<form
|
|
className={`${baseClass}__form`}
|
|
onSubmit={onFormSubmit}
|
|
autoComplete="off"
|
|
>
|
|
<InputField
|
|
autofocus
|
|
name="name"
|
|
onChange={onInputChange}
|
|
onBlur={() => {
|
|
setName(name.trim());
|
|
}}
|
|
label="Fleet name"
|
|
placeholder="Workstations"
|
|
value={name}
|
|
error={errors.name}
|
|
ignore1password
|
|
/>
|
|
<div className="modal-cta-wrap">
|
|
<Button
|
|
type="submit"
|
|
disabled={name.trim() === ""}
|
|
className="create-loading"
|
|
isLoading={isUpdatingTeams}
|
|
>
|
|
Create
|
|
</Button>
|
|
<Button onClick={onCancel} variant="inverse">
|
|
Cancel
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default CreateTeamModal;
|