mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 09:18:59 +00:00
bcfac603f0
* added storybook * added avatar component * added button story * added dropdown button story * removed unused ellipsis component * cleaned up modal path * reorganized enroll secrets table file * added flash story; removed unused persistent flash * added fleet ace story * added checkbox story * added dropdown story * added input story * fixed storybook build * fixed avatar * added input with icon story * added radio button story * added select targets dropdown story * added slider story * added tooltip story * added info banner story * removed unused loaders; added spinner story * added modal story * removed unused NumberPill * added pagination story * lint fixes * added documentation to run * modified documentation * fixed corelayout test * fixed format for date-fns * fixed date format that breaks tests * wait for page
107 lines
2.8 KiB
TypeScript
107 lines
2.8 KiB
TypeScript
import React, { useCallback, useState } from "react";
|
|
import { Link } from "react-router";
|
|
import PATHS from "router/paths";
|
|
import Modal from "components/Modal";
|
|
import Button from "components/buttons/Button";
|
|
// ignore TS error for now until these are rewritten in ts.
|
|
// @ts-ignore
|
|
import Dropdown from "components/forms/fields/Dropdown";
|
|
import { ITeam } from "interfaces/team";
|
|
|
|
interface ITransferHostModal {
|
|
isGlobalAdmin: boolean;
|
|
teams: ITeam[];
|
|
onSubmit: (team: ITeam) => void;
|
|
onCancel: () => void;
|
|
}
|
|
|
|
interface INoTeamOption {
|
|
id: string;
|
|
}
|
|
|
|
const baseClass = "transfer-host-modal";
|
|
|
|
const NO_TEAM_OPTION = {
|
|
value: "no-team",
|
|
label: "No team",
|
|
};
|
|
|
|
const TransferHostModal = ({
|
|
onCancel,
|
|
onSubmit,
|
|
teams,
|
|
isGlobalAdmin,
|
|
}: ITransferHostModal): JSX.Element => {
|
|
const [selectedTeam, setSelectedTeam] = useState<ITeam | INoTeamOption>();
|
|
|
|
const onChangeSelectTeam = useCallback(
|
|
(teamId: number | string) => {
|
|
if (teamId === "no-team") {
|
|
setSelectedTeam({ id: NO_TEAM_OPTION.value });
|
|
} else {
|
|
const teamWithId = teams.find((team) => team.id === teamId);
|
|
setSelectedTeam(teamWithId as ITeam);
|
|
}
|
|
},
|
|
[teams, setSelectedTeam]
|
|
);
|
|
|
|
const onSubmitTransferHost = useCallback(() => {
|
|
onSubmit(selectedTeam as ITeam);
|
|
}, [onSubmit, selectedTeam]);
|
|
|
|
const createTeamDropdownOptions = () => {
|
|
const teamOptions = teams.map((team) => {
|
|
return {
|
|
value: team.id,
|
|
label: team.name,
|
|
};
|
|
});
|
|
return [NO_TEAM_OPTION, ...teamOptions];
|
|
};
|
|
|
|
return (
|
|
<Modal onExit={onCancel} title={"Transfer hosts"} className={baseClass}>
|
|
<form className={`${baseClass}__form`}>
|
|
<Dropdown
|
|
wrapperClassName={`${baseClass}__team-dropdown-wrapper`}
|
|
label={"Transfer host to:"}
|
|
value={selectedTeam && selectedTeam.id}
|
|
options={createTeamDropdownOptions()}
|
|
onChange={onChangeSelectTeam}
|
|
placeholder={"Select a team"}
|
|
searchable={false}
|
|
/>
|
|
{isGlobalAdmin && (
|
|
<p>
|
|
Team not here?
|
|
<Link to={PATHS.ADMIN_TEAMS} className={`${baseClass}__team-link`}>
|
|
Create a team
|
|
</Link>
|
|
</p>
|
|
)}
|
|
<div className={`${baseClass}__btn-wrap`}>
|
|
<Button
|
|
disabled={selectedTeam === undefined}
|
|
className={`${baseClass}__btn transfer-action-btn`}
|
|
type="button"
|
|
variant="brand"
|
|
onClick={onSubmitTransferHost}
|
|
>
|
|
Transfer
|
|
</Button>
|
|
<Button
|
|
className={`${baseClass}__btn`}
|
|
onClick={onCancel}
|
|
variant="inverse"
|
|
>
|
|
Cancel
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default TransferHostModal;
|