dispatch testing

This commit is contained in:
2026-07-20 18:54:09 +05:30
parent 6b154997fb
commit 407574d62a
11 changed files with 663 additions and 518 deletions

View File

@@ -1,7 +1,9 @@
import React, { useState } from 'react';
import { X, Save, AlertCircle } from 'lucide-react';
import { X, Save, AlertCircle, CheckCircle, DownloadCloud, Plus, Box } from 'lucide-react';
import { CatalogueProduct, ImportCatalogueProductRequest } from '../services/catalogueApi';
import { useProductSubcategories, useTenantCategories } from '../hooks/useCatalogueImport';
import { SlideDrawer } from './consoleUi';
import FMCGHoverOverlay from './FMCGHoverOverlay';
interface ImportProductModalProps {
product: CatalogueProduct;
@@ -9,6 +11,7 @@ interface ImportProductModalProps {
locationid: number;
onClose: () => void;
onImport: (item: ImportCatalogueProductRequest) => void;
isImported?: boolean;
}
export default function ImportProductModal({
@@ -16,7 +19,8 @@ export default function ImportProductModal({
tenantid,
locationid,
onClose,
onImport
onImport,
isImported = false
}: ImportProductModalProps) {
const [categoryId, setCategoryId] = useState<string>('');
const [subcategoryId, setSubcategoryId] = useState<string>('');
@@ -25,14 +29,10 @@ export default function ImportProductModal({
const [taxPercent, setTaxPercent] = useState<string>('0');
const [quantity, setQuantity] = useState<string>('1');
// Categories this tenant's own products actually use — the global
// categories list is missing categoryids that are nonetheless in real use.
// Categories this tenant's own products actually use
const { data: categories = [], isLoading: isLoadingCategories } = useTenantCategories(tenantid);
// Subcategories are scoped to the selected category, so a product can't be
// tagged with a subcategory that doesn't actually belong to its category.
// Optional: many subcategories are unowned/shared and a product can be
// imported without one (falls back to "Uncategorized" in subcategory views).
// Subcategories scoped to selected category
const { data: subcategories = [], isLoading: isLoadingSubcats } = useProductSubcategories(
tenantid,
categoryId ? Number(categoryId) : undefined,
@@ -62,151 +62,114 @@ export default function ImportProductModal({
};
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/50 backdrop-blur-sm p-4">
<div className="bg-white rounded-xl shadow-2xl w-full max-w-lg overflow-hidden flex flex-col max-h-[90vh]">
<SlideDrawer
isOpen={!!product}
onClose={onClose}
title="Global Product Details"
>
<div className="flex flex-col gap-6 pb-8 text-xs font-sans">
{/* Header */}
<div className="flex items-center justify-between px-6 py-4 border-b border-slate-100">
<div>
<h2 className="text-lg font-bold text-slate-800">Import Product</h2>
<p className="text-sm text-slate-500">{product.product_name} ({product.brand})</p>
{/* Clean Image Container */}
<div className="w-full h-64 bg-white rounded-2xl border border-slate-200 overflow-hidden relative flex items-center justify-center p-4 shadow-xs">
{product.images && product.images.length > 0 ? (
<img src={product.images[0]} alt={product.product_name} className="w-auto h-full max-w-full object-contain mix-blend-multiply" />
) : (
<Box size={48} className="text-slate-300" />
)}
{isImported && (
<div className="absolute top-3 right-3 flex items-center gap-1 bg-emerald-500 text-white text-[10px] font-extrabold uppercase px-2 py-1 shadow-sm rounded-md">
<CheckCircle size={12} />
In Store Catalogue
</div>
)}
</div>
{/* Title & Basics */}
<div>
<p className="text-xs font-bold text-slate-400 font-mono tracking-tight mb-1">ID: {product.id}</p>
<h3 className="text-xl font-extrabold text-slate-900 leading-tight mb-3">{product.product_name}</h3>
<div className="flex flex-wrap items-center gap-2">
<span className="px-2.5 py-1 rounded bg-purple-50 text-[#662582] text-[10px] font-extrabold uppercase tracking-wider border border-purple-100">
{product.brand.replace('brand_', '')}
</span>
</div>
<button onClick={onClose} className="p-2 text-slate-400 hover:bg-slate-50 hover:text-slate-600 rounded-full transition-colors">
<X size={20} />
</button>
</div>
{/* Body */}
<div className="p-6 overflow-y-auto custom-scrollbar flex-1">
<form id="import-form" onSubmit={handleSubmit} className="space-y-5">
<div className="bg-blue-50/50 rounded-lg p-3 border border-blue-100 flex gap-3 text-sm text-blue-700">
<AlertCircle size={18} className="shrink-0 mt-0.5" />
<p>You need to map this catalogue product to your store's categories and set your own pricing.</p>
{/* Price Range Container */}
<div className="bg-slate-50/90 p-4 rounded-xl border border-slate-200 flex items-center justify-between shadow-xs">
<div>
<span className="text-[10px] font-extrabold text-slate-400 uppercase tracking-widest block mb-0.5">Price Range</span>
<div className="text-2xl font-black text-slate-900 font-mono tracking-tight">
{product.price_range || 'N/A'}
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-1.5">
<label className="text-xs font-semibold text-slate-600 uppercase tracking-wider">Category *</label>
{isLoadingCategories ? (
<div className="w-full px-3 py-2 border border-slate-200 rounded-lg text-slate-400">Loading...</div>
) : (
<select
value={categoryId}
onChange={e => {
setCategoryId(e.target.value);
setSubcategoryId(''); // subcategory list is about to change
}}
className="w-full px-3 py-2 border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500/20 focus:border-purple-500 transition-colors bg-white"
required
>
<option value="">Select category...</option>
{categories.map((c) => (
<option key={c.categoryid} value={c.categoryid}>
{c.categoryname}
</option>
))}
</select>
)}
</div>
<div className="space-y-1.5">
<label className="text-xs font-semibold text-slate-600 uppercase tracking-wider">Subcategory (optional)</label>
{!categoryId ? (
<div className="w-full px-3 py-2 border border-slate-200 rounded-lg text-slate-400">Select a category first</div>
) : isLoadingSubcats ? (
<div className="w-full px-3 py-2 border border-slate-200 rounded-lg text-slate-400">Loading...</div>
) : (
<select
value={subcategoryId}
onChange={e => setSubcategoryId(e.target.value)}
className="w-full px-3 py-2 border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500/20 focus:border-purple-500 transition-colors bg-white"
>
<option value="">None</option>
{subcategories.map((s: any) => (
<option key={s.subcategoryid || s.id} value={s.subcategoryid || s.id}>
{s.subcategoryname || s.name}
</option>
))}
</select>
)}
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-1.5">
<label className="text-xs font-semibold text-slate-600 uppercase tracking-wider">Retail Price *</label>
<div className="relative">
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"></span>
<input
type="number" step="0.01"
value={retailPrice} onChange={e => setRetailPrice(e.target.value)}
className="w-full pl-7 pr-3 py-2 border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 transition-colors"
placeholder="0.00"
required
/>
</div>
</div>
<div className="space-y-1.5">
<label className="text-xs font-semibold text-slate-600 uppercase tracking-wider">Cost Price *</label>
<div className="relative">
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"></span>
<input
type="number" step="0.01"
value={productCost} onChange={e => setProductCost(e.target.value)}
className="w-full pl-7 pr-3 py-2 border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 transition-colors"
placeholder="0.00"
required
/>
</div>
</div>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-1.5">
<label className="text-xs font-semibold text-slate-600 uppercase tracking-wider">Tax Percent</label>
<div className="relative">
<input
type="number" step="0.1"
value={taxPercent} onChange={e => setTaxPercent(e.target.value)}
className="w-full pr-8 pl-3 py-2 border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500/20 focus:border-purple-500 transition-colors"
placeholder="0"
/>
<span className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400">%</span>
</div>
</div>
<div className="space-y-1.5">
<label className="text-xs font-semibold text-slate-600 uppercase tracking-wider">Initial Quantity</label>
<input
type="number" min="1"
value={quantity} onChange={e => setQuantity(e.target.value)}
className="w-full px-3 py-2 border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500/20 focus:border-purple-500 transition-colors"
required
/>
</div>
</div>
</form>
</div>
{product.size && (
<span className="px-3 py-1.5 rounded-lg bg-white text-slate-700 text-xs font-extrabold uppercase tracking-wider border border-slate-200 shadow-2xs">
Size: {product.size}
</span>
)}
</div>
{/* Footer */}
<div className="px-6 py-4 border-t border-slate-100 bg-slate-50 flex items-center justify-end gap-3">
<button
type="button"
onClick={onClose}
className="px-4 py-2 text-sm font-medium text-slate-600 hover:text-slate-800 transition-colors"
>
Cancel
</button>
<button
type="submit"
form="import-form"
className="flex items-center gap-2 px-5 py-2 bg-purple-650 hover:bg-purple-750 text-white text-sm font-medium rounded-lg shadow-sm shadow-purple-650/20 transition-all hover:-translate-y-0.5 active:translate-y-0"
>
<Save size={16} />
Import Product
</button>
{/* Import Action Container */}
<div className="bg-slate-50/80 rounded-2xl border border-slate-200 p-5 space-y-4 shadow-xs">
{isImported ? (
<div className="p-4 bg-emerald-50/80 border border-emerald-200 rounded-xl flex items-center gap-3 text-xs text-emerald-800 font-semibold shadow-xs">
<CheckCircle size={22} className="text-emerald-600 shrink-0" />
<div>
<div className="font-extrabold text-sm text-emerald-900">Imported</div>
<p className="text-[11px] text-emerald-700 font-medium mt-0.5">This product is available in your Admin Catalogue. Set pricing and store parameters in the Admin Catalogue.</p>
</div>
</div>
) : (
<div className="space-y-4">
<div className="flex items-center justify-between border-b border-slate-200 pb-3">
<h4 className="font-extrabold text-slate-800 text-sm flex items-center gap-2">
<DownloadCloud size={16} className="text-[#662582]" /> Import Product
</h4>
<span className="text-[10px] font-semibold text-slate-500">Global FMCG</span>
</div>
<p className="text-[11px] text-slate-600 font-medium leading-relaxed">
Import this product to your Admin Catalogue. Selling price and outlet parameters will be managed directly in your Admin Catalogue.
</p>
<button
onClick={() => {
const validCategory = categories.find(c => c.categoryid > 0)?.categoryid || (categories[0]?.categoryid ?? 2);
onImport({
tenantid,
locationid,
brand: product.brand,
catalogueid: product.id,
categoryid: validCategory,
subcategoryid: 0,
quantity: 1,
stocktype: "in",
status: "Active",
retailprice: 0,
productcost: 0,
taxpercent: 0,
});
}}
className="w-full flex items-center justify-center gap-2 py-3.5 rounded-xl text-sm font-extrabold transition-all bg-[#662582] hover:bg-[#531e6a] text-white shadow-md cursor-pointer"
>
<Plus size={18} strokeWidth={2.5} />
Import Product
</button>
</div>
)}
</div>
{/* Retail Packaging Details */}
<div>
<h4 className="text-[10px] font-black uppercase tracking-widest text-slate-400 mb-2">Retail Packaging Info</h4>
<FMCGHoverOverlay
productId={String(product.id)}
category={product.brand}
productName={product.product_name}
product={product}
/>
</div>
</div>
</div>
</SlideDrawer>
);
}