Обновлен компонент CreateSupplyPage: удалены неиспользуемые состояния и эффекты, добавлены новые функции для создания поставки и управления состоянием. Внедрен новый компонент DirectSupplyCreation для упрощения процесса создания поставки. Обновлен компонент TabsHeader для поддержки новой логики создания поставки с кнопкой для запуска процесса.

This commit is contained in:
Bivekich
2025-07-23 16:05:44 +03:00
parent 158411cc98
commit f478754bef
3 changed files with 953 additions and 38 deletions

View File

@ -1,24 +1,23 @@
"use client"
import React, { useState, useEffect } from 'react'
import { useQuery } from '@apollo/client'
import React, { useState } from 'react'
import { Sidebar } from '@/components/dashboard/sidebar'
import { useSidebar } from '@/hooks/useSidebar'
import { GET_MY_COUNTERPARTIES, GET_ALL_PRODUCTS } from '@/graphql/queries'
import { useRouter } from 'next/navigation'
import { WBProductCards } from './wb-product-cards'
import { SelectedCard as WBSelectedCard } from '@/types/supplies'
import { DirectSupplyCreation } from './direct-supply-creation'
import { WholesalerProductsPage } from './wholesaler-products-page'
import { TabsHeader } from './tabs-header'
import { WholesalerGrid } from './wholesaler-grid'
import { CartSummary } from './cart-summary'
import { FloatingCart } from './floating-cart'
import { WholesalerProductsPage } from './wholesaler-products-page'
import {
WholesalerForCreation,
WholesalerProduct,
SelectedProduct,
CounterpartyWholesaler
} from './types'
import { useQuery } from '@apollo/client'
import { GET_MY_COUNTERPARTIES, GET_ALL_PRODUCTS } from '@/graphql/queries'
export function CreateSupplyPage() {
const router = useRouter()
@ -26,9 +25,10 @@ export function CreateSupplyPage() {
const [activeTab, setActiveTab] = useState<'cards' | 'wholesaler'>('cards')
const [selectedWholesaler, setSelectedWholesaler] = useState<WholesalerForCreation | null>(null)
const [selectedProducts, setSelectedProducts] = useState<SelectedProduct[]>([])
const [selectedCards, setSelectedCards] = useState<WBSelectedCard[]>([])
const [showSummary, setShowSummary] = useState(false)
const [searchQuery, setSearchQuery] = useState('')
const [canCreateSupply, setCanCreateSupply] = useState(false)
const [isCreatingSupply, setIsCreatingSupply] = useState(false)
// Загружаем контрагентов-оптовиков
const { data: counterpartiesData, loading: counterpartiesLoading } = useQuery(GET_MY_COUNTERPARTIES)
@ -50,13 +50,6 @@ export function CreateSupplyPage() {
)
: []
// Автоматически показываем корзину если в ней есть товары и мы на этапе выбора оптовиков
useEffect(() => {
if (activeTab === 'wholesaler' && !selectedWholesaler && selectedProducts.length > 0) {
setShowSummary(true)
}
}, [activeTab, selectedWholesaler, selectedProducts.length])
const formatCurrency = (amount: number) => {
return new Intl.NumberFormat('ru-RU', {
style: 'currency',
@ -106,12 +99,6 @@ export function CreateSupplyPage() {
return selectedProducts.reduce((sum, product) => sum + product.selectedQuantity, 0)
}
const handleCardsComplete = (cards: WBSelectedCard[]) => {
setSelectedCards(cards)
console.log('Карточки товаров выбраны:', cards)
router.push('/supplies')
}
const handleCreateSupply = () => {
if (activeTab === 'cards') {
console.log('Создание поставки с карточками Wildberries')
@ -146,6 +133,23 @@ export function CreateSupplyPage() {
)
}
const handleSupplyComplete = () => {
router.push('/supplies')
}
const handleCreateSupplyClick = () => {
setIsCreatingSupply(true)
}
const handleCanCreateSupplyChange = (canCreate: boolean) => {
setCanCreateSupply(canCreate)
}
const handleSupplyCompleted = () => {
setIsCreatingSupply(false)
handleSupplyComplete()
}
// Рендер страницы товаров оптовика
if (selectedWholesaler && activeTab === 'wholesaler') {
return (
@ -175,13 +179,7 @@ export function CreateSupplyPage() {
onTabChange={setActiveTab}
onBack={() => router.push('/supplies')}
cartInfo={
activeTab === 'cards' && selectedCards.length > 0
? {
itemCount: selectedCards.reduce((sum, sc) => sum + sc.selectedQuantity, 0),
totalAmount: 0,
formatCurrency
}
: activeTab === 'wholesaler' && selectedProducts.length > 0
activeTab === 'wholesaler' && selectedProducts.length > 0
? {
itemCount: selectedProducts.length,
totalAmount: getTotalAmount(),
@ -190,17 +188,19 @@ export function CreateSupplyPage() {
: undefined
}
onCartClick={() => setShowSummary(true)}
onCreateSupply={handleCreateSupplyClick}
canCreateSupply={canCreateSupply}
isCreatingSupply={isCreatingSupply}
/>
{/* Контент карточек */}
{/* Контент карточек - новый компонент прямого создания поставки */}
{activeTab === 'cards' && (
<WBProductCards
onBack={() => router.push('/supplies')}
onComplete={handleCardsComplete}
showSummary={showSummary}
setShowSummary={setShowSummary}
selectedCards={selectedCards}
setSelectedCards={setSelectedCards}
<DirectSupplyCreation
onComplete={handleSupplyCompleted}
onCreateSupply={handleCreateSupplyClick}
canCreateSupply={canCreateSupply}
isCreatingSupply={isCreatingSupply}
onCanCreateSupplyChange={handleCanCreateSupplyChange}
/>
)}
@ -229,7 +229,7 @@ export function CreateSupplyPage() {
itemCount={selectedProducts.length}
totalAmount={getTotalAmount()}
formatCurrency={formatCurrency}
onClick={() => setShowSummary(true)}
onClick={() => setShowSummary(true)}
visible={selectedProducts.length > 0 && !showSummary}
/>
</div>