"use client" import { useState } from 'react' import { useQuery, useMutation } from '@apollo/client' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Search, Truck } from 'lucide-react' import { OrganizationCard } from './organization-card' import { SEARCH_ORGANIZATIONS, GET_INCOMING_REQUESTS, GET_OUTGOING_REQUESTS } from '@/graphql/queries' import { SEND_COUNTERPARTY_REQUEST } from '@/graphql/mutations' interface Organization { id: string inn: string name?: string fullName?: string type: 'FULFILLMENT' | 'SELLER' | 'LOGIST' | 'WHOLESALE' address?: string phones?: Array<{ value: string }> emails?: Array<{ value: string }> createdAt: string users?: Array<{ id: string, avatar?: string }> isCounterparty?: boolean isCurrentUser?: boolean hasOutgoingRequest?: boolean hasIncomingRequest?: boolean } export function MarketLogistics() { const [searchTerm, setSearchTerm] = useState('') const { data, loading, refetch } = useQuery(SEARCH_ORGANIZATIONS, { variables: { type: 'LOGIST', search: searchTerm || null } }) const [sendRequest, { loading: sendingRequest }] = useMutation(SEND_COUNTERPARTY_REQUEST, { refetchQueries: [ { query: SEARCH_ORGANIZATIONS, variables: { type: 'SELLER' } }, { query: SEARCH_ORGANIZATIONS, variables: { type: 'FULFILLMENT' } }, { query: SEARCH_ORGANIZATIONS, variables: { type: 'LOGIST' } }, { query: SEARCH_ORGANIZATIONS, variables: { type: 'WHOLESALE' } }, { query: GET_OUTGOING_REQUESTS }, { query: GET_INCOMING_REQUESTS } ], awaitRefetchQueries: true }) const handleSearch = () => { refetch({ type: 'LOGIST', search: searchTerm || null }) } const handleSendRequest = async (organizationId: string, message: string) => { try { await sendRequest({ variables: { organizationId: organizationId, message: message || 'Заявка на добавление в контрагенты' } }) } catch (error) { console.error('Ошибка отправки заявки:', error) } } const organizations = data?.searchOrganizations || [] return (
{/* Поиск */}
setSearchTerm(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleSearch()} className="pl-10 glass-input text-white placeholder:text-white/40 h-10" />
{/* Заголовок с иконкой */}

Логистика

Найдите и добавьте логистические компании в контрагенты

{/* Результаты поиска */}
{loading ? (
Поиск...
) : organizations.length === 0 ? (

{searchTerm ? 'Логистические компании не найдены' : 'Введите запрос для поиска'}

Попробуйте изменить условия поиска

) : (
{organizations.map((organization: Organization) => ( ))}
)}
) }