import product catalogue
This commit is contained in:
190
src/components/ImportProductModal.tsx
Normal file
190
src/components/ImportProductModal.tsx
Normal file
@@ -0,0 +1,190 @@
|
||||
import React, { useState } from 'react';
|
||||
import { X, Save, AlertCircle } from 'lucide-react';
|
||||
import { CatalogueProduct, ImportCatalogueProductRequest } from '../services/catalogueApi';
|
||||
import { useProductSubcategories } from '../hooks/useCatalogueImport';
|
||||
|
||||
interface ImportProductModalProps {
|
||||
product: CatalogueProduct;
|
||||
tenantid: number;
|
||||
locationid: number;
|
||||
onClose: () => void;
|
||||
onImport: (item: ImportCatalogueProductRequest) => void;
|
||||
}
|
||||
|
||||
export default function ImportProductModal({
|
||||
product,
|
||||
tenantid,
|
||||
locationid,
|
||||
onClose,
|
||||
onImport
|
||||
}: ImportProductModalProps) {
|
||||
const [categoryId, setCategoryId] = useState<string>('');
|
||||
const [subcategoryId, setSubcategoryId] = useState<string>('');
|
||||
const [retailPrice, setRetailPrice] = useState<string>('');
|
||||
const [productCost, setProductCost] = useState<string>('');
|
||||
const [taxPercent, setTaxPercent] = useState<string>('0');
|
||||
const [quantity, setQuantity] = useState<string>('1');
|
||||
|
||||
// Load subcategories for this tenant (optional: filter by categoryId if category picker is also dynamic)
|
||||
// The spec says "getproductsubcategories" with optional categoryid. We will fetch all for now and pick.
|
||||
const { data: subcategories = [], isLoading: isLoadingSubcats } = useProductSubcategories(tenantid);
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!categoryId || !subcategoryId || !retailPrice || !productCost) {
|
||||
alert("Please fill in all required fields.");
|
||||
return;
|
||||
}
|
||||
|
||||
onImport({
|
||||
tenantid,
|
||||
locationid,
|
||||
brand: product.brand,
|
||||
catalogueid: product.id,
|
||||
categoryid: Number(categoryId),
|
||||
subcategoryid: Number(subcategoryId),
|
||||
quantity: Number(quantity),
|
||||
stocktype: "in",
|
||||
status: "Active",
|
||||
retailprice: Number(retailPrice),
|
||||
productcost: Number(productCost),
|
||||
taxpercent: Number(taxPercent),
|
||||
});
|
||||
};
|
||||
|
||||
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]">
|
||||
|
||||
{/* 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>
|
||||
</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>
|
||||
</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 ID *</label>
|
||||
<input
|
||||
type="number"
|
||||
value={categoryId}
|
||||
onChange={e => setCategoryId(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"
|
||||
placeholder="e.g. 1"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-xs font-semibold text-slate-600 uppercase tracking-wider">Subcategory *</label>
|
||||
{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"
|
||||
required
|
||||
>
|
||||
<option value="">Select subcategory...</option>
|
||||
{subcategories.map((s: any) => (
|
||||
<option key={s.subcategoryid || s.id} value={s.subcategoryid || s.id}>
|
||||
{s.subcategoryname || s.name} (Cat {s.categoryid || '?'})
|
||||
</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>
|
||||
|
||||
{/* 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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user