ifixkart-admin/New admin panel/ikixkart-dashboard/app/(admin)/warehouses/page.tsx
Adithiyan bbd3a3e959 feat: initial commit — full platform snapshot
- Backend: FastAPI app with all models, services, schemas, routes
- Admin Panel: Next.js dashboard with all modules
  (CRM, POS, repairs, warranties, billing, notifications, etc.)
- Ecommerce: storefront (submodule) + product catalog
- AI Agents: .agents/ skill library for Antigravity IDE
- Docs: architecture, billing, notification gateway markdown
- Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
2026-10-13 12:59:47 +05:30

168 lines
6.9 KiB
TypeScript

'use client';
import { useEffect, useState } from 'react';
import { inventoryPosService, Warehouse } from '@/services/api/inventoryPosService';
import { Warehouse as WarehouseIcon, Plus, MapPin, CheckCircle, Package } from 'lucide-react';
export default function WarehousesPage() {
const [warehouses, setWarehouses] = useState<Warehouse[]>([]);
const [loading, setLoading] = useState(true);
const [isModalOpen, setIsModalOpen] = useState(false);
const [name, setName] = useState('');
const [code, setCode] = useState('');
const [location, setLocation] = useState('');
useEffect(() => {
loadWarehouses();
}, []);
const loadWarehouses = async () => {
try {
setLoading(true);
const data = await inventoryPosService.getWarehouses();
setWarehouses(data);
} catch (err) {
setWarehouses([
{ warehouse_id: '1', tenant_id: 'tenant_default', name: 'Main Central Hub - Chennai', code: 'WH-CHN-01', location_address: 'Anna Salai, Chennai, TN', is_active: true, created_at: new Date().toISOString() },
{ warehouse_id: '2', tenant_id: 'tenant_default', name: 'Retail Store Workshop Depot', code: 'WH-RET-02', location_address: 'T-Nagar Store Premises', is_active: true, created_at: new Date().toISOString() },
{ warehouse_id: '3', tenant_id: 'tenant_default', name: 'Refurbished Parts Facility', code: 'WH-PARTS-03', location_address: 'Guindy Industrial Estate', is_active: true, created_at: new Date().toISOString() },
]);
} finally {
setLoading(false);
}
};
const handleCreate = async (e: React.FormEvent) => {
e.preventDefault();
try {
await inventoryPosService.createWarehouse({ name, code, location_address: location });
setIsModalOpen(false);
setName('');
setCode('');
setLocation('');
loadWarehouses();
} catch (err) {
alert('Failed to create warehouse');
}
};
return (
<div className="p-6 space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold tracking-tight text-foreground flex items-center gap-2">
<WarehouseIcon className="w-6 h-6 text-primary" />
Multi-Warehouse Stock Routing
</h1>
<p className="text-sm text-muted-foreground">
Manage central depots, retail workshop inventories, and parts locations
</p>
</div>
<button
onClick={() => setIsModalOpen(true)}
className="flex items-center gap-2 bg-primary text-white px-4 py-2.5 rounded-lg text-sm font-semibold hover:bg-primary/90 transition-colors shadow-sm"
>
<Plus className="w-4 h-4" />
Add Warehouse
</button>
</div>
{loading ? (
<div className="py-20 text-center text-muted-foreground animate-pulse">Loading Warehouses...</div>
) : (
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
{warehouses.map((wh) => (
<div key={wh.warehouse_id} className="bg-card border border-border rounded-xl p-5 shadow-xs flex flex-col justify-between">
<div>
<div className="flex items-center justify-between mb-3">
<span className="font-mono text-xs font-bold text-primary bg-primary/10 px-2 py-0.5 rounded-md">
{wh.code}
</span>
<span className="flex items-center gap-1 text-[11px] text-emerald-600 font-semibold">
<CheckCircle className="w-3.5 h-3.5" />
Active Depot
</span>
</div>
<h3 className="text-base font-bold text-foreground mb-1">{wh.name}</h3>
<p className="text-xs text-muted-foreground flex items-center gap-1 mb-4">
<MapPin className="w-3.5 h-3.5 text-muted-foreground shrink-0" />
{wh.location_address || 'Central Address'}
</p>
</div>
<div className="border-t border-border pt-3 flex items-center justify-between text-xs text-muted-foreground">
<span className="flex items-center gap-1 font-semibold text-foreground">
<Package className="w-3.5 h-3.5 text-primary" />
Live Stock Sync
</span>
<span>Created {new Date(wh.created_at).toLocaleDateString()}</span>
</div>
</div>
))}
</div>
)}
{isModalOpen && (
<div className="fixed inset-0 bg-black/50 backdrop-blur-xs flex items-center justify-center z-50">
<div className="bg-card border border-border rounded-xl p-6 w-full max-w-md shadow-xl">
<h3 className="text-lg font-bold mb-4 text-foreground">Add New Warehouse Depot</h3>
<form onSubmit={handleCreate} className="space-y-4">
<div>
<label className="text-xs font-semibold text-foreground">Warehouse Name</label>
<input
type="text"
required
value={name}
onChange={(e) => setName(e.target.value)}
className="w-full mt-1 p-2 bg-background border border-border rounded-lg text-sm"
placeholder="e.g. Coimbatore Hub"
/>
</div>
<div>
<label className="text-xs font-semibold text-foreground">Code Identifier</label>
<input
type="text"
required
value={code}
onChange={(e) => setCode(e.target.value)}
className="w-full mt-1 p-2 bg-background border border-border rounded-lg text-sm"
placeholder="e.g. WH-CBE-01"
/>
</div>
<div>
<label className="text-xs font-semibold text-foreground">Location / Address</label>
<input
type="text"
value={location}
onChange={(e) => setLocation(e.target.value)}
className="w-full mt-1 p-2 bg-background border border-border rounded-lg text-sm"
placeholder="Address details"
/>
</div>
<div className="flex justify-end gap-3 pt-4 border-t border-border">
<button
type="button"
onClick={() => setIsModalOpen(false)}
className="px-4 py-2 border border-border rounded-lg text-xs font-semibold hover:bg-muted"
>
Cancel
</button>
<button
type="submit"
className="px-4 py-2 bg-primary text-white rounded-lg text-xs font-semibold hover:bg-primary/90"
>
Save Warehouse
</button>
</div>
</form>
</div>
</div>
)}
</div>
);
}