diff --git a/frontend/src/components/requests/RequestStatisticsPanel.tsx b/frontend/src/components/requests/RequestStatisticsPanel.tsx index 736b2526..8f6e7565 100644 --- a/frontend/src/components/requests/RequestStatisticsPanel.tsx +++ b/frontend/src/components/requests/RequestStatisticsPanel.tsx @@ -1,10 +1,10 @@ "use client"; -import { SearchableSelectSingle } from "@/components/shared/SearchableSelect"; import { apiClient } from "@/lib/api"; import { displayUserName } from "@/lib/shared"; +import { resolveMediaUrl } from "@/lib/url"; import type { RequestEmployeeStatistics, User } from "@/types/api"; -import { ChevronDown } from "lucide-react"; +import { ChevronDown, Search } from "lucide-react"; import { useEffect, useState } from "react"; const statsPeriods = [ @@ -25,6 +25,7 @@ export function RequestStatisticsPanel({ employees, }: RequestStatisticsPanelProps) { const [open, setOpen] = useState(false); + const [searchQuery, setSearchQuery] = useState(""); const [employeeId, setEmployeeId] = useState(null); const [period, setPeriod] = useState("all"); const [stats, setStats] = useState(null); @@ -40,7 +41,9 @@ export function RequestStatisticsPanel({ setLoading(true); setError(null); - apiClient.getEmployeeRequestStatistics(employeeId, period) + apiClient.request( + `/api/v1/requests/statistics/?employee_id=${employeeId}&period=${period}` + ) .then((response) => { if (!cancelled) { setStats(response); @@ -64,10 +67,19 @@ export function RequestStatisticsPanel({ if (!canView) return null; - const employeeOptions = employees.map((employee) => ({ - id: employee.id, - name: displayUserName(employee), - })); + const filteredEmployees = employees.filter((employee) => { + const normalizedQuery = searchQuery.trim().toLowerCase(); + if (!normalizedQuery) return true; + + const haystack = [ + displayUserName(employee), + employee.email || "", + ] + .join(" ") + .toLowerCase(); + + return haystack.includes(normalizedQuery); + }); const statsItems = stats ? [ { label: "Всего заявлений", value: stats.total_submitted_requests }, @@ -101,20 +113,87 @@ export function RequestStatisticsPanel({ {open ? (
-
- { - setEmployeeId(id); - setStats(null); - setError(null); - }} - placeholder="Выберите сотрудника" - /> +
+
+ + setSearchQuery(e.target.value)} + placeholder="Выберите сотрудника для статистики" + className="app-input w-full rounded-xl py-2.5 pl-10 pr-3 text-sm" + /> +
-
+
+ Найдено: {filteredEmployees.length} + Выбрано: {employeeId ? 1 : 0} +
+ +
+ {filteredEmployees.length > 0 ? ( + filteredEmployees.map((employee) => { + const isSelected = employee.id === employeeId; + const employeeName = displayUserName(employee); + return ( + + ); + }) + ) : ( +

Сотрудники не найдены

+ )} +
+ +
{statsPeriods.map((periodOption) => { const isActive = period === periodOption.value; return (