import { useRef, useState } from 'preact/hooks'; import { useOutsideClick } from '../hooks/use-outside-click'; import { OptionType, SearchSelector } from './SearchSelector'; import type { PageType } from './CommandMenu/CommandMenu'; import { CheckIcon } from './ReactIcons/CheckIcon'; import { httpPut } from '../lib/http'; import type { TeamResourceConfig } from './CreateTeam/RoadmapSelector'; import { Spinner } from './ReactIcons/Spinner'; type AddTeamRoadmapProps = { teamId: string; allRoadmaps: PageType[]; availableRoadmaps: PageType[]; onClose: () => void; onMakeChanges: (roadmapId: string) => void; setResourceConfigs: (config: TeamResourceConfig) => void; }; export function AddTeamRoadmap(props: AddTeamRoadmapProps) { const { teamId, onMakeChanges, onClose, allRoadmaps, availableRoadmaps, setResourceConfigs, } = props; const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const [selectedRoadmap, setSelectedRoadmap] = useState(''); const popupBodyEl = useRef(null); async function addTeamResource(roadmapId: string) { if (!teamId) { return; } setIsLoading(true); const { error, response } = await httpPut( `${ import.meta.env.PUBLIC_API_URL }/v1-update-team-resource-config/${teamId}`, { teamId: teamId, resourceId: roadmapId, resourceType: 'roadmap', removed: [], } ); if (error || !response) { setError(error?.message || 'Error adding roadmap'); return; } setResourceConfigs(response); } useOutsideClick(popupBodyEl, () => { onClose(); }); const selectedRoadmapTitle = allRoadmaps.find( (roadmap) => roadmap.id === selectedRoadmap )?.title; return ( ); }