diff --git a/apps/app/components/command-palette/addAsSubIssue.tsx b/apps/app/components/command-palette/addAsSubIssue.tsx index 41c3e3d28..e8c585e45 100644 --- a/apps/app/components/command-palette/addAsSubIssue.tsx +++ b/apps/app/components/command-palette/addAsSubIssue.tsx @@ -1,3 +1,4 @@ +// react import React, { useState } from "react"; // swr import { mutate } from "swr"; @@ -5,23 +6,23 @@ import { mutate } from "swr"; import { useForm } from "react-hook-form"; // headless ui import { Combobox, Dialog, Transition } from "@headlessui/react"; +// services +import issuesServices from "lib/services/issues.services"; // hooks import useUser from "lib/hooks/useUser"; // icons -import { MagnifyingGlassIcon } from "@heroicons/react/20/solid"; -import { FolderIcon } from "@heroicons/react/24/outline"; +import { RectangleStackIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; // commons import { classNames } from "constants/common"; // types import { IIssue, IssueResponse } from "types"; -import { Button } from "ui"; -import { PROJECT_ISSUES_DETAILS, PROJECT_ISSUES_LIST } from "constants/fetch-keys"; -import issuesServices from "lib/services/issues.services"; +// constants +import { PROJECT_ISSUES_LIST } from "constants/fetch-keys"; type Props = { isOpen: boolean; setIsOpen: React.Dispatch>; - parentId: string; + parent: IIssue | undefined; }; type FormInput = { @@ -29,7 +30,7 @@ type FormInput = { cycleId: string; }; -const AddAsSubIssue: React.FC = ({ isOpen, setIsOpen, parentId }) => { +const AddAsSubIssue: React.FC = ({ isOpen, setIsOpen, parent }) => { const [query, setQuery] = useState(""); const { activeWorkspace, activeProject, issues } = useUser(); @@ -41,24 +42,19 @@ const AddAsSubIssue: React.FC = ({ isOpen, setIsOpen, parentId }) => { []; const { - register, formState: { errors, isSubmitting }, - handleSubmit, - control, reset, - setError, } = useForm(); const handleCommandPaletteClose = () => { setIsOpen(false); setQuery(""); - reset(); }; const addAsSubIssue = (issueId: string) => { if (activeWorkspace && activeProject) { issuesServices - .patchIssue(activeWorkspace.slug, activeProject.id, issueId, { parent: parentId }) + .patchIssue(activeWorkspace.slug, activeProject.id, issueId, { parent: parent?.id }) .then((res) => { mutate( PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id), @@ -78,118 +74,113 @@ const AddAsSubIssue: React.FC = ({ isOpen, setIsOpen, parentId }) => { }; return ( - <> - setQuery("")} appear> - + setQuery("")} appear> + + +
+ + +
-
- + + +
+
-
- - - { - // const { url, onClick } = item; - // if (url) router.push(url); - // else if (onClick) onClick(); - // handleCommandPaletteClose(); - // }} + -
- 0 && ( + <> +
  • + {query === "" && ( +

    + Issues +

    + )} +
      + {filteredIssues.map((issue) => { + if ( + (issue.parent === "" || issue.parent === null) && // issue does not have any other parent + issue.id !== parent?.id && // issue is not itself + issue.id !== parent?.parent // issue is not it's parent + ) + return ( + + classNames( + "flex items-center gap-2 cursor-pointer select-none rounded-md px-3 py-2", + active ? "bg-gray-900 bg-opacity-5 text-gray-900" : "" + ) + } + onClick={() => { + addAsSubIssue(issue.id); + setIsOpen(false); + }} + > + + {issue.name} + + ); + })} +
    +
  • + + )} + + + {query !== "" && filteredIssues.length === 0 && ( +
    +
    - - - {filteredIssues.length > 0 && ( - <> -
  • - {query === "" && ( -

    - Issues -

    - )} -
      - {filteredIssues.map((issue) => { - if (issue.parent === "" || issue.parent === null) - return ( - - classNames( - "flex items-center gap-2 cursor-pointer select-none rounded-md px-3 py-2", - active ? "bg-gray-900 bg-opacity-5 text-gray-900" : "" - ) - } - onClick={() => { - addAsSubIssue(issue.id); - setIsOpen(false); - }} - > - - {issue.name} - - ); - })} -
    -
  • - - )} -
    - - {query !== "" && filteredIssues.length === 0 && ( -
    -
    - )} - - - -
    -
    -
    - + )} + + + + +
    +
    ); }; diff --git a/apps/app/components/command-palette/index.tsx b/apps/app/components/command-palette/index.tsx index 5c718b704..1b5694616 100644 --- a/apps/app/components/command-palette/index.tsx +++ b/apps/app/components/command-palette/index.tsx @@ -4,40 +4,35 @@ import { useRouter } from "next/router"; // swr import { mutate } from "swr"; // react hook form -import { Controller, SubmitHandler, useForm } from "react-hook-form"; +import { SubmitHandler, useForm } from "react-hook-form"; // headless ui import { Combobox, Dialog, Transition } from "@headlessui/react"; +// services +import issuesServices from "lib/services/issues.services"; // hooks import useUser from "lib/hooks/useUser"; import useTheme from "lib/hooks/useTheme"; import useToast from "lib/hooks/useToast"; // icons -import { MagnifyingGlassIcon } from "@heroicons/react/20/solid"; import { FolderIcon, RectangleStackIcon, ClipboardDocumentListIcon, - ArrowPathIcon, + MagnifyingGlassIcon, } from "@heroicons/react/24/outline"; -// commons -import { classNames, copyTextToClipboard } from "constants/common"; // components import ShortcutsModal from "components/command-palette/shortcuts"; import CreateProjectModal from "components/project/CreateProjectModal"; import CreateUpdateIssuesModal from "components/project/issues/CreateUpdateIssueModal"; import CreateUpdateCycleModal from "components/project/cycles/CreateUpdateCyclesModal"; +// ui +import { Button } from "ui"; // types -import { IIssue, IProject, IssueResponse } from "types"; -import { Button, SearchListbox } from "ui"; -import issuesServices from "lib/services/issues.services"; +import { IIssue, IssueResponse } from "types"; // fetch keys -import { PROJECTS_LIST, PROJECT_ISSUES_LIST } from "constants/fetch-keys"; - -type ItemType = { - name: string; - url?: string; - onClick?: () => void; -}; +import { PROJECT_ISSUES_LIST } from "constants/fetch-keys"; +// constants +import { classNames, copyTextToClipboard } from "constants/common"; type FormInput = { issue_ids: string[]; @@ -45,8 +40,6 @@ type FormInput = { }; const CommandPalette: React.FC = () => { - const router = useRouter(); - const [query, setQuery] = useState(""); const [isPaletteOpen, setIsPaletteOpen] = useState(false); @@ -55,7 +48,9 @@ const CommandPalette: React.FC = () => { const [isShortcutsModalOpen, setIsShortcutsModalOpen] = useState(false); const [isCreateCycleModalOpen, setIsCreateCycleModalOpen] = useState(false); - const { activeWorkspace, activeProject, issues, cycles } = useUser(); + const { activeWorkspace, activeProject, issues } = useUser(); + + const router = useRouter(); const { toggleCollapsed } = useTheme(); @@ -67,14 +62,7 @@ const CommandPalette: React.FC = () => { : issues?.results.filter((issue) => issue.name.toLowerCase().includes(query.toLowerCase())) ?? []; - const { - register, - formState: { errors, isSubmitting }, - handleSubmit, - control, - reset, - setError, - } = useForm(); + const { register, handleSubmit, reset } = useForm(); const quickActions = [ { @@ -186,37 +174,6 @@ const CommandPalette: React.FC = () => { } }; - const handleAddToCycle: SubmitHandler = (data) => { - if (!data.issue_ids || data.issue_ids.length === 0) { - setToastAlert({ - title: "Error", - type: "error", - message: "Please select atleast one issue", - }); - return; - } - - if (!data.cycleId) { - setToastAlert({ - title: "Error", - type: "error", - message: "Please select a cycle", - }); - return; - } - - if (activeWorkspace && activeProject) { - issuesServices - .bulkAddIssuesToCycle(activeWorkspace.slug, activeProject.id, data.cycleId, data) - .then((res) => { - console.log(res); - }) - .catch((e) => { - console.log(e); - }); - } - }; - useEffect(() => { document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); @@ -269,14 +226,7 @@ const CommandPalette: React.FC = () => { >
    - { - // const { url, onClick } = item; - // if (url) router.push(url); - // else if (onClick) onClick(); - // handleCommandPaletteClose(); - // }} - > +
    { {filteredIssues.map((issue) => ( classNames( - "flex cursor-pointer select-none items-center rounded-md px-3 py-2", + "flex items-center justify-between cursor-pointer select-none rounded-md px-3 py-2", active ? "bg-gray-900 bg-opacity-5 text-gray-900" : "" ) } > {({ active }) => ( <> - {/*