erp-platform/ui/src/views/warehouse/components/WarehouseList.tsx

420 lines
18 KiB
TypeScript
Raw Normal View History

2025-09-15 21:11:40 +00:00
import React, { useState } from 'react'
import { Link } from 'react-router-dom'
import { useQuery } from '@tanstack/react-query'
2025-09-15 09:31:47 +00:00
import {
FaBuilding,
FaPlus,
FaSearch,
FaFilter,
FaDownload,
FaEdit,
FaEye,
FaMapMarkerAlt,
FaBox,
FaArrowUp,
FaExclamationTriangle,
FaChartLine,
2025-09-15 21:11:40 +00:00
} from 'react-icons/fa'
import classNames from 'classnames'
import { WarehouseTypeEnum } from '../../../types/wm'
import { mockWarehouses } from '../../../mocks/mockWarehouses'
import { getWarehouseTypeColor, getWarehouseTypeText } from '../../../utils/erp'
import { Container } from '@/components/shared'
2025-09-16 12:33:57 +00:00
import { ROUTES_ENUM } from '@/routes/route.constant'
2025-09-15 09:31:47 +00:00
const WarehouseList: React.FC = () => {
2025-09-15 21:11:40 +00:00
const [searchTerm, setSearchTerm] = useState('')
const [filterType, setFilterType] = useState('all')
const [showFilters, setShowFilters] = useState(false)
2025-09-15 09:31:47 +00:00
const {
data: warehouses,
isLoading,
error,
} = useQuery({
2025-09-15 21:11:40 +00:00
queryKey: ['warehouses', searchTerm, filterType],
2025-09-15 09:31:47 +00:00
queryFn: async () => {
2025-09-15 21:11:40 +00:00
await new Promise((resolve) => setTimeout(resolve, 500))
2025-09-15 09:31:47 +00:00
return mockWarehouses.filter((warehouse) => {
const matchesSearch =
warehouse.code.toLowerCase().includes(searchTerm.toLowerCase()) ||
2025-09-15 21:11:40 +00:00
warehouse.name.toLowerCase().includes(searchTerm.toLowerCase())
const matchesType = filterType === 'all' || warehouse.warehouseType === filterType
return matchesSearch && matchesType
})
2025-09-15 09:31:47 +00:00
},
2025-09-15 21:11:40 +00:00
})
2025-09-15 09:31:47 +00:00
const getUtilizationColor = (utilization: number) => {
2025-09-15 21:11:40 +00:00
const percentage = utilization
if (percentage >= 90) return 'text-red-600'
if (percentage >= 75) return 'text-yellow-600'
return 'text-green-600'
}
2025-09-15 09:31:47 +00:00
if (isLoading) {
return (
<div className="flex items-center justify-center py-12">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"></div>
<span className="ml-3 text-gray-600">Depolar yükleniyor...</span>
</div>
2025-09-15 21:11:40 +00:00
)
2025-09-15 09:31:47 +00:00
}
if (error) {
return (
<div className="bg-red-50 border border-red-200 rounded-lg p-4">
<div className="flex items-center">
<FaExclamationTriangle className="h-5 w-5 text-red-600 mr-2" />
<span className="text-red-800">Depolar yüklenirken hata oluştu.</span>
</div>
</div>
2025-09-15 21:11:40 +00:00
)
2025-09-15 09:31:47 +00:00
}
return (
2025-09-15 21:11:40 +00:00
<Container>
<div className="space-y-2">
{/* Header Actions */}
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
<div className="flex items-center space-x-2">
<div className="relative">
<FaSearch
size={16}
className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4"
/>
<input
type="text"
placeholder="Depo kodu veya adı..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="pl-10 pr-4 py-1.5 text-sm w-64 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
/>
</div>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<button
onClick={() => setShowFilters(!showFilters)}
className={classNames(
'flex items-center px-3 py-1.5 text-sm border rounded-lg transition-colors',
showFilters
? 'border-blue-500 bg-blue-50 text-blue-700'
: 'border-gray-300 bg-white text-gray-700 hover:bg-gray-50',
)}
>
<FaFilter size={14} className="mr-2" />
Filtreler
</button>
</div>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<div className="flex items-center space-x-2">
<button
onClick={() => alert('Dışa aktarma özelliği yakında eklenecek')}
className="flex items-center px-3 py-1.5 text-sm border border-gray-300 bg-white text-gray-700 rounded-lg hover:bg-gray-50 transition-colors"
>
<FaDownload size={14} className="mr-2" />
Dışa Aktar
</button>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<Link
2025-09-16 12:33:57 +00:00
to={ROUTES_ENUM.protected.warehouse.warehouseNew}
2025-09-15 21:11:40 +00:00
className="flex items-center px-3 py-1.5 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
>
<FaPlus size={14} className="mr-2" />
Yeni Depo
</Link>
</div>
2025-09-15 09:31:47 +00:00
</div>
2025-09-15 21:11:40 +00:00
{/* Filters Panel */}
{showFilters && (
<div className="bg-white border border-gray-200 rounded-lg p-3">
<div className="grid grid-cols-1 md:grid-cols-3 gap-3">
<div>
<label className="block text-xs font-medium text-gray-700 mb-1">Depo Türü</label>
<select
value={filterType}
onChange={(e) => setFilterType(e.target.value)}
className="w-full border border-gray-300 rounded-lg px-3 py-1.5 text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent"
>
<option value="all">Tümü</option>
2025-09-17 09:46:58 +00:00
{Object.values(WarehouseTypeEnum).map((type) => (
<option key={type} value={type}>
{getWarehouseTypeText(type)}
</option>
))}
2025-09-15 21:11:40 +00:00
</select>
</div>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<div className="flex items-end">
<button
onClick={() => {
setFilterType('all')
setSearchTerm('')
}}
className="w-full px-4 py-1.5 text-sm border border-gray-300 bg-white text-gray-700 rounded-lg hover:bg-gray-50 transition-colors"
>
Filtreleri Temizle
</button>
</div>
2025-09-15 09:31:47 +00:00
</div>
</div>
2025-09-15 21:11:40 +00:00
)}
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
{/* Statistics Cards */}
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-3">
<div className="flex items-center justify-between">
<div>
<p className="text-sm font-medium text-gray-600">Toplam Depo</p>
<p className="text-xl font-bold text-gray-900">{warehouses?.length || 0}</p>
</div>
<FaBuilding className="h-6 w-6 text-blue-500" />
2025-09-15 09:31:47 +00:00
</div>
</div>
2025-09-15 21:11:40 +00:00
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-3">
<div className="flex items-center justify-between">
<div>
<p className="text-sm font-medium text-gray-600">Toplam Kapasite</p>
<p className="text-xl font-bold text-green-600">
{warehouses?.reduce((acc, w) => acc + w.capacity, 0).toLocaleString() || 0}
</p>
</div>
<FaBox className="h-6 w-6 text-green-500" />
2025-09-15 09:31:47 +00:00
</div>
</div>
2025-09-15 21:11:40 +00:00
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-3">
<div className="flex items-center justify-between">
<div>
<p className="text-sm font-medium text-gray-600">Kullanım Oranı</p>
<p className="text-xl font-bold text-yellow-600">
{warehouses?.length
? Math.round(
(warehouses.reduce((acc, w) => acc + w.currentUtilization, 0) /
(warehouses.reduce((acc, w) => acc + w.capacity, 0) || 1)) *
100,
)
: 0}
%
</p>
</div>
<FaArrowUp className="h-6 w-6 text-yellow-500" />
2025-09-15 09:31:47 +00:00
</div>
</div>
2025-09-15 21:11:40 +00:00
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-3">
<div className="flex items-center justify-between">
<div>
<p className="text-sm font-medium text-gray-600">Aktif Depo</p>
<p className="text-xl font-bold text-purple-600">
{warehouses?.filter((w) => w.isActive).length || 0}
</p>
</div>
<FaChartLine className="h-6 w-6 text-purple-500" />
2025-09-15 09:31:47 +00:00
</div>
</div>
</div>
2025-09-15 21:11:40 +00:00
{/* Warehouses Table */}
<div className="bg-white rounded-lg shadow-sm border border-gray-200">
<div className="px-4 py-3 border-b border-gray-200">
<h2 className="text-xl font-bold text-gray-900">Depo Listesi</h2>
</div>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<div className="overflow-x-auto">
<table className="w-full">
<thead className="bg-gray-50">
<tr>
<th className="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Depo Bilgileri
</th>
<th className="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Tür / Konum
</th>
<th className="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Kapasite
</th>
<th className="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Kullanım Oranı
</th>
<th className="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Performans
</th>
<th className="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Durum
</th>
<th className="px-4 py-2 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
İşlemler
</th>
</tr>
</thead>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<tbody className="bg-white divide-y divide-gray-200">
{warehouses?.map((warehouse) => {
const utilizationPercentage = Math.round(
(warehouse.currentUtilization / warehouse.capacity) * 100,
)
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
return (
<tr key={warehouse.id} className="hover:bg-gray-50 transition-colors">
<td className="px-4 py-3">
<div className="flex items-center">
<div className="flex-shrink-0 h-8 w-8">
<div className="h-8 w-8 rounded-lg bg-blue-100 flex items-center justify-center">
<FaBuilding className="h-5 w-5 text-blue-600" />
</div>
2025-09-15 09:31:47 +00:00
</div>
2025-09-15 21:11:40 +00:00
<div className="ml-4">
<div className="text-xs font-medium text-gray-900">
{warehouse.code}
</div>
<div className="text-sm text-gray-500 max-w-xs truncate">
{warehouse.name}
</div>
{warehouse.isMainWarehouse && (
<span className="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800 mt-1">
Ana Depo
</span>
)}
2025-09-15 09:31:47 +00:00
</div>
</div>
2025-09-15 21:11:40 +00:00
</td>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<td className="px-4 py-3">
<div className="space-y-1">
<span
className={classNames(
'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium',
getWarehouseTypeColor(warehouse.warehouseType),
)}
>
{getWarehouseTypeText(warehouse.warehouseType)}
</span>
<div className="flex items-center text-xs text-gray-500">
<FaMapMarkerAlt size={14} className="mr-1" />
{warehouse.address?.city}, {warehouse.address?.country}
</div>
2025-09-15 09:31:47 +00:00
</div>
2025-09-15 21:11:40 +00:00
</td>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<td className="px-4 py-3">
<div className="text-sm font-medium text-gray-900">
{warehouse.capacity.toLocaleString()} m³
2025-09-15 09:31:47 +00:00
</div>
2025-09-15 21:11:40 +00:00
<div className="text-sm text-gray-500">Toplam Kapasite</div>
</td>
<td className="px-4 py-3">
<div className="space-y-1">
<div className="flex items-center justify-between">
<span className="text-xs text-gray-600">Kullanılan:</span>
<span className="text-sm font-medium text-gray-900">
{warehouse.currentUtilization.toLocaleString()} m³
</span>
</div>
<div className="w-full bg-gray-200 rounded-full h-2">
<div
className={classNames(
'h-2 rounded-full',
utilizationPercentage >= 90
? 'bg-red-500'
: utilizationPercentage >= 75
? 'bg-yellow-500'
: 'bg-green-500',
)}
style={{
width: `${Math.min(utilizationPercentage, 100)}%`,
}}
/>
</div>
2025-09-15 09:31:47 +00:00
<div
className={classNames(
2025-09-15 21:11:40 +00:00
'text-sm font-medium',
getUtilizationColor(utilizationPercentage),
2025-09-15 09:31:47 +00:00
)}
2025-09-15 21:11:40 +00:00
>
%{utilizationPercentage}
</div>
2025-09-15 09:31:47 +00:00
</div>
2025-09-15 21:11:40 +00:00
</td>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<td className="px-4 py-3">
<div className="space-y-1">
<div className="flex items-center">
<FaChartLine size={14} className="text-green-500 mr-1" />
<span className="text-sm text-green-600">Verimli</span>
</div>
<div className="text-xs text-gray-500">Son 30 gün</div>
2025-09-15 09:31:47 +00:00
</div>
2025-09-15 21:11:40 +00:00
</td>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<td className="px-4 py-3">
<span
className={classNames(
'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium',
warehouse.isActive
? 'bg-green-100 text-green-800'
: 'bg-red-100 text-red-800',
)}
2025-09-15 09:31:47 +00:00
>
2025-09-15 21:11:40 +00:00
{warehouse.isActive ? 'Aktif' : 'Pasif'}
</span>
</td>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<td className="px-4 py-3 text-right">
<div className="flex items-center justify-end space-x-2">
<Link
2025-09-16 12:33:57 +00:00
to={ROUTES_ENUM.protected.warehouse.warehouseDetail.replace(
'::id',
warehouse.id,
)}
2025-09-15 21:11:40 +00:00
className="p-2 text-gray-600 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-colors"
title="Detayları Görüntüle"
>
<FaEye size={16} />
</Link>
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
<Link
2025-09-16 12:33:57 +00:00
to={ROUTES_ENUM.protected.warehouse.warehouseEdit.replace(
'::id',
warehouse.id,
)}
2025-09-15 21:11:40 +00:00
className="p-2 text-gray-600 hover:text-yellow-600 hover:bg-yellow-50 rounded-lg transition-colors"
title="Düzenle"
>
<FaEdit size={16} />
</Link>
</div>
</td>
</tr>
)
})}
</tbody>
</table>
2025-09-15 09:31:47 +00:00
</div>
2025-09-15 21:11:40 +00:00
{(!warehouses || warehouses.length === 0) && (
<div className="text-center py-12">
<FaBuilding className="mx-auto h-12 w-12 text-gray-400" />
<h3 className="mt-2 text-sm font-medium text-gray-900">Depo bulunamadı</h3>
<p className="mt-1 text-sm text-gray-500">Yeni depo ekleyerek başlayın.</p>
<div className="mt-6">
<Link
2025-09-16 12:33:57 +00:00
to={ROUTES_ENUM.protected.warehouse.warehouseNew}
2025-09-15 21:11:40 +00:00
className="inline-flex items-center px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
>
<FaPlus size={16} className="mr-2" />
Yeni Depo Ekle
</Link>
</div>
</div>
)}
</div>
2025-09-15 09:31:47 +00:00
</div>
2025-09-15 21:11:40 +00:00
</Container>
)
}
2025-09-15 09:31:47 +00:00
2025-09-15 21:11:40 +00:00
export default WarehouseList