import { useEffect, useState } from "react"; import Link from "next/link"; import { observer } from "mobx-react-lite"; import { Tab } from "@headlessui/react"; // hooks import { useDashboard } from "hooks/store"; // components import { DurationFilterDropdown, TabsList, WidgetIssuesList, WidgetLoader, WidgetProps, } from "components/dashboard/widgets"; // helpers import { getCustomDates, getRedirectionFilters } from "helpers/dashboard.helper"; // types import { TAssignedIssuesWidgetFilters, TAssignedIssuesWidgetResponse } from "@plane/types"; // constants import { ISSUES_TABS_LIST } from "constants/dashboard"; const WIDGET_KEY = "assigned_issues"; export const AssignedIssuesWidget: React.FC = observer((props) => { const { dashboardId, workspaceSlug } = props; // states const [fetching, setFetching] = useState(false); // store hooks const { fetchWidgetStats, widgetDetails: allWidgetDetails, widgetStats: allWidgetStats, updateDashboardWidgetFilters, } = useDashboard(); // derived values const widgetDetails = allWidgetDetails?.[workspaceSlug]?.[dashboardId]?.find((w) => w.key === WIDGET_KEY); const widgetStats = allWidgetStats?.[workspaceSlug]?.[dashboardId]?.[WIDGET_KEY] as TAssignedIssuesWidgetResponse; const handleUpdateFilters = async (filters: Partial) => { if (!widgetDetails) return; setFetching(true); await updateDashboardWidgetFilters(workspaceSlug, dashboardId, widgetDetails.id, { widgetKey: WIDGET_KEY, filters, }); fetchWidgetStats(workspaceSlug, dashboardId, { widget_key: WIDGET_KEY, issue_type: widgetDetails.widget_filters.tab ?? "upcoming", target_date: getCustomDates(widgetDetails.widget_filters.target_date ?? "this_week"), expand: "issue_relation", }).finally(() => setFetching(false)); }; useEffect(() => { if (!widgetDetails) return; const filterDates = getCustomDates(widgetDetails.widget_filters.target_date ?? "this_week"); if (!widgetStats) fetchWidgetStats(workspaceSlug, dashboardId, { widget_key: WIDGET_KEY, issue_type: widgetDetails.widget_filters.tab ?? "upcoming", target_date: filterDates, expand: "issue_relation", }); }, [dashboardId, fetchWidgetStats, widgetDetails, widgetStats, workspaceSlug]); const filterParams = getRedirectionFilters(widgetDetails?.widget_filters.tab ?? "upcoming"); const redirectionLink = `/${workspaceSlug}/workspace-views/assigned/${filterParams}`; if (!widgetDetails || !widgetStats) return ; return (

All issues assigned

handleUpdateFilters({ target_date: val, }) } /> t.key === widgetDetails.widget_filters.tab ?? "upcoming")} onChange={(i) => { const selectedTab = ISSUES_TABS_LIST[i]; handleUpdateFilters({ tab: selectedTab.key ?? "upcoming" }); }} className="h-full flex flex-col" >
{ISSUES_TABS_LIST.map((tab) => ( ))}
); });