import React, { useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import useSWR from "swr"; // services import workspaceService from "services/workspace.service"; // layouts import { WorkspaceAuthorizationLayout } from "layouts/auth-layout"; // components import { SingleWorkspaceViewItem } from "components/workspace/views/single-workspace-view-item"; import { WorkspaceIssuesViewOptions } from "components/issues/workspace-views/workspace-issue-view-option"; import { CreateUpdateWorkspaceViewModal } from "components/workspace/views/modal"; import { DeleteWorkspaceViewModal } from "components/workspace/views/delete-workspace-view-modal"; // ui import { EmptyState, Input, Loader, PrimaryButton } from "components/ui"; // icons import { MagnifyingGlassIcon } from "@heroicons/react/24/outline"; import { PlusIcon } from "lucide-react"; import { PhotoFilterOutlined } from "@mui/icons-material"; // image import emptyView from "public/empty-state/view.svg"; // types import type { NextPage } from "next"; import { IWorkspaceView } from "types/workspace-views"; // constants import { WORKSPACE_VIEWS_LIST } from "constants/fetch-keys"; // helper import { truncateText } from "helpers/string.helper"; const WorkspaceViews: NextPage = () => { const [query, setQuery] = useState(""); const [createUpdateViewModal, setCreateUpdateViewModal] = useState(false); const [selectedViewToUpdate, setSelectedViewToUpdate] = useState(null); const [deleteViewModal, setDeleteViewModal] = useState(false); const [selectedViewToDelete, setSelectedViewToDelete] = useState(null); const router = useRouter(); const { workspaceSlug } = router.query; const { data: workspaceViews } = useSWR( workspaceSlug ? WORKSPACE_VIEWS_LIST(workspaceSlug as string) : null, workspaceSlug ? () => workspaceService.getAllViews(workspaceSlug as string) : null ); const defaultWorkspaceViewsList = [ { key: "all", label: "All Issues", href: `/${workspaceSlug}/workspace-views/all-issues`, }, { key: "assigned", label: "Assigned", href: `/${workspaceSlug}/workspace-views/assigned`, }, { key: "created", label: "Created", href: `/${workspaceSlug}/workspace-views/created`, }, { key: "subscribed", label: "Subscribed", href: `/${workspaceSlug}/workspace-views/subscribed`, }, ]; const filteredDefaultOptions = query === "" ? defaultWorkspaceViewsList : defaultWorkspaceViewsList?.filter((option) => option.label.toLowerCase().includes(query.toLowerCase()) ); const filteredOptions = query === "" ? workspaceViews : workspaceViews?.filter((option) => option.name.toLowerCase().includes(query.toLowerCase())); const handleEditView = (view: IWorkspaceView) => { setSelectedViewToUpdate(view); setCreateUpdateViewModal(true); }; const handleDeleteView = (view: IWorkspaceView) => { setSelectedViewToDelete(view); setDeleteViewModal(true); }; return ( Workspace Views } right={
setCreateUpdateViewModal(true)} > New View
} > { setCreateUpdateViewModal(false); setSelectedViewToUpdate(null); }} data={selectedViewToUpdate} />
setQuery(e.target.value)} placeholder="Search" mode="trueTransparent" />
{filteredDefaultOptions && filteredDefaultOptions.length > 0 && filteredDefaultOptions.map((option) => ( ))} {filteredOptions ? ( filteredOptions.length > 0 ? (
{filteredOptions.map((view) => ( handleEditView(view)} handleDeleteView={() => handleDeleteView(view)} /> ))}
) : ( , text: "New View", onClick: () => setCreateUpdateViewModal(true), }} /> ) ) : ( )}
); }; export default WorkspaceViews;