diff --git a/src/components/CreateTeam/RoadmapSelector.tsx b/src/components/CreateTeam/RoadmapSelector.tsx index bec08ff38..96860b062 100644 --- a/src/components/CreateTeam/RoadmapSelector.tsx +++ b/src/components/CreateTeam/RoadmapSelector.tsx @@ -1,11 +1,12 @@ import { useEffect, useState } from 'preact/hooks'; -import { SearchSelector } from '../SearchSelector'; import { httpGet, httpPut } from '../../lib/http'; import type { PageType } from '../CommandMenu/CommandMenu'; -import SearchIcon from '../../icons/search.svg'; +import PlusIcon from '../../icons/plus.svg'; +import PlusWhiteIcon from '../../icons/plus-white.svg'; import { pageProgressMessage } from '../../stores/page'; import type { TeamDocument } from './CreateTeamForm'; import { UpdateTeamResourceModal } from './UpdateTeamResourceModal'; +import { SelectRoadmapModal } from './SelectRoadmapModal'; export type TeamResourceConfig = { resourceId: string; @@ -22,6 +23,7 @@ type RoadmapSelectorProps = { export function RoadmapSelector(props: RoadmapSelectorProps) { const { team, teamResourceConfig = [], setTeamResourceConfig } = props; + const [showSelectRoadmapModal, setShowSelectRoadmapModal] = useState(false); const [allRoadmaps, setAllRoadmaps] = useState([]); const [changingRoadmapId, setChangingRoadmapId] = useState(''); const [error, setError] = useState(''); @@ -126,42 +128,42 @@ export function RoadmapSelector(props: RoadmapSelectorProps) { } /> )} - - { - const roadmapId = option.value; - addTeamResource(roadmapId).finally(() => { - pageProgressMessage.set(''); - }); - }} - options={allRoadmaps - .filter((roadmap) => { - return !teamResourceConfig - .map((c) => c.resourceId) - .includes(roadmap.id); - }) - .map((roadmap) => ({ - value: roadmap.id, - label: roadmap.title, - }))} - searchInputId={'roadmap-input'} - inputClassName="mt-2 block w-full rounded-md border px-3 py-2 shadow-sm outline-none placeholder:text-gray-400 focus:ring-2 focus:ring-black focus:ring-offset-1" - /> + {showSelectRoadmapModal && ( + setShowSelectRoadmapModal(false)} + teamResourceConfig={teamResourceConfig} + allRoadmaps={allRoadmaps} + teamId={team?._id!} + onRoadmapAdd={(roadmapId) => { + addTeamResource(roadmapId).finally(() => { + pageProgressMessage.set(''); + }); + }} + onRoadmapRemove={(roadmapId) => { + onRemove(roadmapId).finally(() => {}); + }} + /> + )} {!teamResourceConfig.length && (
- {'search'} No roadmaps selected.

- Please search and add roadmaps from above + Please search and add roadmaps from below

+
+ +
)} @@ -214,6 +216,19 @@ export function RoadmapSelector(props: RoadmapSelectorProps) { ); })} + )} diff --git a/src/components/CreateTeam/SelectRoadmapModal.tsx b/src/components/CreateTeam/SelectRoadmapModal.tsx new file mode 100644 index 000000000..27fd56d71 --- /dev/null +++ b/src/components/CreateTeam/SelectRoadmapModal.tsx @@ -0,0 +1,114 @@ +import { useEffect, useRef, useState } from 'preact/hooks'; +import { useKeydown } from '../../hooks/use-keydown'; +import { useOutsideClick } from '../../hooks/use-outside-click'; +import type { PageType } from '../CommandMenu/CommandMenu'; +import { useToast } from '../../hooks/use-toast'; +import type { TeamResourceConfig } from './RoadmapSelector'; +import CloseIcon from '../../icons/close.svg'; + +export type SelectRoadmapModalProps = { + teamId: string; + allRoadmaps: PageType[]; + onClose: () => void; + teamResourceConfig: TeamResourceConfig; + onRoadmapAdd: (roadmapId: string) => void; + onRoadmapRemove: (roadmapId: string) => void; +}; + +export function SelectRoadmapModal(props: SelectRoadmapModalProps) { + const { + onClose, + allRoadmaps, + onRoadmapAdd, + onRoadmapRemove, + teamResourceConfig, + } = props; + const toast = useToast(); + const popupBodyEl = useRef(null); + + const [searchResults, setSearchResults] = useState(allRoadmaps); + const [searchText, setSearchText] = useState(''); + + useKeydown('Escape', () => { + onClose(); + }); + + useOutsideClick(popupBodyEl, () => { + onClose(); + }); + + useEffect(() => { + if (searchText.length === 0) { + setSearchResults(allRoadmaps); + return; + } + + const searchResults = allRoadmaps.filter((roadmap) => { + return ( + roadmap.title.toLowerCase().includes(searchText.toLowerCase()) || + roadmap.id.toLowerCase().includes(searchText.toLowerCase()) + ); + }); + setSearchResults(searchResults); + }, [searchText, allRoadmaps]); + + return ( +
+
+ +
+
+ ); +} diff --git a/src/icons/plus-white.svg b/src/icons/plus-white.svg new file mode 100644 index 000000000..4986ebc4b --- /dev/null +++ b/src/icons/plus-white.svg @@ -0,0 +1 @@ +