import { useEffect, useMemo, useState } from "react"; import { Input, List, Spin, Empty, Typography, Tag } from "antd"; import { FolderOpenOutlined, SearchOutlined } from "@ant-design/icons"; import { useAppDispatch, useAppSelector } from "../../store/store"; import { getCompanyGroupsThunk } from "../../store/slices/companyGroupsSlice/thunks"; import { setActiveCompanyGroup } from "../../store/slices/companyGroupsSlice/companyGroupsSlice"; const { Text } = Typography; export const CompanyGroupsList = () => { const dispatch = useAppDispatch(); const rawRows = useAppSelector((state) => state.company_groups.raw_rows); const loading = useAppSelector((state) => state.company_groups.loading); const activeCompanyGroup = useAppSelector( (state) => state.company_groups.activeCompanyGroup, ); const [query, setQuery] = useState(""); const filtered = useMemo(() => { const q = query.trim().toLowerCase(); if (!q) return rawRows; return rawRows.filter( (g) => g.name.toLowerCase().includes(q) || g.crm_id?.toLowerCase().includes(q), ); }, [rawRows, query]); useEffect(() => { dispatch(getCompanyGroupsThunk()); }, [dispatch]); useEffect(() => { if (!activeCompanyGroup && rawRows?.length) { dispatch(setActiveCompanyGroup(rawRows?.[0])); } }, [rawRows, activeCompanyGroup]); return (
} placeholder={"Поиск по ЮЛ или ГСК"} value={query} onChange={(e) => setQuery(e.target.value)} />
{loading ? (
) : filtered.length === 0 ? ( ) : ( { const active = item.id === activeCompanyGroup?.id; return ( dispatch(setActiveCompanyGroup(item))} style={{ cursor: "pointer", borderRadius: 8, padding: "10px 12px", marginBottom: 4, background: active ? "#e6f4ea" : "transparent", boxShadow: active ? "inset 0 0 0 1px #2ea64b3d, inset 3px 0 0 #258141" : "inset 0 0 0 1px #0f172a14", transition: "background 0.15s", }} onMouseEnter={(e) => { if (!active) { (e.currentTarget as HTMLElement).style.background = "#fafafa"; } }} onMouseLeave={(e) => { if (!active) { (e.currentTarget as HTMLElement).style.background = "transparent"; } }} >
{item.name} CRM ID: {item.crm_id ?? "-"}
{item.legal_entities_count}
); }} /> )}
); };