feat(catalog): provide quick edit modal and comprehensive 4-step product edit functionality (PREPILOT-30)
All checks were successful
Beta CI/CD Pipeline / build-and-test (push) Successful in 2m2s
Beta CI/CD Pipeline / deploy-beta (push) Successful in 57s

This commit is contained in:
vickytechkey 2026-11-14 13:16:48 +05:30
parent 72a91b8233
commit d1806fba4e
3 changed files with 350 additions and 22 deletions

View file

@ -23,6 +23,7 @@ interface SellerContextType {
fetchData: () => Promise<void>;
updateStock: (id: string, newStock: number) => Promise<void>;
addProduct: (product: Omit<InventoryItem, 'id' | 'salesCount'>) => Promise<void>;
updateProduct: (id: string, updates: Partial<InventoryItem>) => Promise<void>;
deleteProduct: (id: string) => Promise<void>;
// Orders & Shipping
@ -772,6 +773,54 @@ export const SellerProvider: React.FC<{ children: React.ReactNode }> = ({ childr
}
};
const updateProduct = async (id: string, updates: Partial<InventoryItem>) => {
setInventory(prev => prev.map(item => {
if (item.id === id) {
const newStock = updates.stock !== undefined ? updates.stock : item.stock;
return {
...item,
...updates,
stock: newStock,
status: newStock === 0 ? 'out_of_stock' : newStock < 5 ? 'low_stock' : 'active'
};
}
return item;
}));
if (id && !String(id).startsWith('prod-')) {
try {
const payload: any = {};
if (updates.title !== undefined) payload.title = updates.title;
if (updates.price !== undefined) payload.price = updates.price;
if (updates.mrp !== undefined) payload.compare_at_price = updates.mrp;
if (updates.stock !== undefined) payload.stock = updates.stock;
if (updates.description !== undefined) payload.description = updates.description;
if (updates.category !== undefined) payload.category = updates.category;
if (updates.image !== undefined) payload.image = updates.image;
if (updates.additional_images !== undefined) payload.additional_images = updates.additional_images;
if (updates.video_url !== undefined) payload.video_url = updates.video_url;
if (updates.is_gi_tagged !== undefined) payload.is_gi_tagged = updates.is_gi_tagged;
if (updates.gi_tag_name !== undefined) payload.gi_tag_name = updates.gi_tag_name;
if (updates.is_odop !== undefined) payload.is_odop = updates.is_odop;
if (updates.odop_district !== undefined) payload.odop_district = updates.odop_district;
if (updates.is_sustainable !== undefined) payload.is_sustainable = updates.is_sustainable;
if (updates.sustainable_type !== undefined) payload.sustainable_type = updates.sustainable_type;
if (updates.geographical_origin !== undefined) payload.geographical_origin = updates.geographical_origin;
if (updates.statutory_certifications !== undefined) payload.statutory_certifications = updates.statutory_certifications;
if (updates.provenance_story !== undefined) payload.provenance_story = updates.provenance_story;
if (updates.coordinates !== undefined) payload.coordinates = updates.coordinates;
if (updates.package_weight !== undefined) payload.package_weight = updates.package_weight;
if (updates.shipping_profile !== undefined) payload.shipping_profile = updates.shipping_profile;
await api.patchProduct(id, payload);
} catch (err) {
console.warn('Failed to patch product on backend:', err);
}
}
fetchData().catch(() => {});
};
const deleteProduct = async (id: string) => {
try {
await api.deleteProduct(id);
@ -946,6 +995,7 @@ export const SellerProvider: React.FC<{ children: React.ReactNode }> = ({ childr
fetchData,
updateStock,
addProduct,
updateProduct,
deleteProduct,
orders,
updateOrderStatus,

View file

@ -112,7 +112,7 @@ export const AddProductPage: React.FC = () => {
}
}
};
const { addProduct, fetchData, user, onboarding, inventory } = useSeller();
const { addProduct, updateProduct, fetchData, user, onboarding, inventory } = useSeller();
const sellerMid = user?.profile?.merchant_id || user?.merchant_id || onboarding?.merchantId || (user?.id ? `TRDPX${String(user.id).padStart(6, '0')}` : 'TRDPX000001');
const nextProductSeq = (inventory?.length || 0) + 1;
const navigate = useNavigate();
@ -529,8 +529,7 @@ export const AddProductPage: React.FC = () => {
};
if (editingId && !String(editingId).startsWith('prod-')) {
await api.patchProduct(editingId, productPayload);
await fetchData();
await updateProduct(editingId, productPayload);
} else {
await addProduct(productPayload);
}
@ -595,11 +594,18 @@ export const AddProductPage: React.FC = () => {
<div className="is-flex is-justify-content-space-between is-align-items-center mb-2">
<div>
<div style={{ fontSize: '0.72rem', fontWeight: 700, color: '#701A29', letterSpacing: '0.04em', textTransform: 'uppercase', marginBottom: '4px' }}>
Catalog &amp; Inventory / Add Product
Catalog &amp; Inventory / {editingId ? 'Edit Product' : 'Add Product'}
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: '12px', flexWrap: 'wrap' }}>
<h1 style={{ fontSize: 'clamp(1.5rem, 2.5vw, 1.85rem)', fontWeight: 800, color: '#701A29', letterSpacing: '-0.02em', lineHeight: 1.2 }}>
{editingId ? 'Edit Handcrafted Product' : 'Add New Handcrafted Product'}
</h1>
{editingId && (
<span style={{ fontSize: '0.78rem', fontWeight: 700, backgroundColor: '#FEF3C7', color: '#92400E', padding: '4px 10px', borderRadius: '9999px', border: '1px solid #FDE68A' }}>
SKU: {sku}
</span>
)}
</div>
<h1 style={{ fontSize: 'clamp(1.5rem, 2.5vw, 1.85rem)', fontWeight: 800, color: '#701A29', letterSpacing: '-0.02em', lineHeight: 1.2 }}>
Add New Handcrafted Product
</h1>
<p style={{ fontSize: '0.86rem', color: '#6B7280', marginTop: '6px' }}>
{step === 1 && 'Step 1 of 4: Category'}
{step === 2 && 'Step 2 of 4: Photos & Video Showcase'}
@ -1718,7 +1724,9 @@ export const AddProductPage: React.FC = () => {
) : (
<button type="button" onClick={handleFinish} disabled={isSubmitting}
style={{ fontSize: '0.9rem', fontWeight: 700, color: '#FFFFFF', backgroundColor: isSubmitting ? '#9CA3AF' : '#701A29', border: 'none', borderRadius: '9999px', padding: '10px 28px', cursor: isSubmitting ? 'not-allowed' : 'pointer', display: 'flex', alignItems: 'center', gap: '8px', boxShadow: isSubmitting ? 'none' : '0 4px 12px rgba(112,26,41,0.2)' }}>
{isSubmitting ? 'Publishing Product...' : 'Publish Handcrafted Product 🚀'}
{isSubmitting
? (editingId ? 'Saving Changes...' : 'Publishing Product...')
: (editingId ? 'Save Changes & Update Catalog ✨' : 'Publish Handcrafted Product 🚀')}
</button>
)}
</div>

View file

@ -17,7 +17,8 @@ import {
Edit3,
ShieldCheck,
CheckCircle2,
FileSpreadsheet
FileSpreadsheet,
X
} from 'lucide-react';
const HEALTH_CONFIG: Record<string, { label: string; bg: string; color: string; dot: string }> = {
@ -38,7 +39,7 @@ const PAGE_SIZE = 10;
export const InventoryPage: React.FC = () => {
const navigate = useNavigate();
const { inventory, updateStock, deleteProduct, fetchData } = useSeller();
const { inventory, updateStock, updateProduct, deleteProduct, fetchData } = useSeller();
useEffect(() => {
fetchData();
@ -83,9 +84,20 @@ export const InventoryPage: React.FC = () => {
const [stockValues, setStockValues] = useState<Record<string, number>>({});
const [currentPage, setCurrentPage] = useState(1);
const [editingItem, setEditingItem] = useState<any>(null);
const [editTitle, setEditTitle] = useState('');
const [editPrice, setEditPrice] = useState<number | ''>('');
const [editMrp, setEditMrp] = useState<number | ''>('');
const [editStock, setEditStock] = useState<number | ''>('');
const [isSavingEdit, setIsSavingEdit] = useState(false);
const handleOpenQuickEdit = (item: any) => {
setEditingItem(item);
setEditTitle(item.title || '');
setEditPrice(item.price || '');
setEditMrp(item.mrp || item.compare_at_price || '');
setEditStock(stockValues[item.id] ?? item.stock ?? 0);
};
useEffect(() => {
setStockValues(prev => {
const next = { ...prev };
@ -154,19 +166,24 @@ export const InventoryPage: React.FC = () => {
const handleSaveEdit = async () => {
if (!editingItem) return;
setIsSavingEdit(true);
const currentStock = stockValues[editingItem.id] ?? editingItem.stock;
const patchPayload: any = { stock: currentStock };
if (editPrice !== '' && !isNaN(Number(editPrice))) {
patchPayload.price = Number(editPrice);
}
const updates: any = {};
if (editTitle.trim()) updates.title = editTitle.trim();
if (editPrice !== '' && !isNaN(Number(editPrice))) updates.price = Number(editPrice);
if (editMrp !== '' && !isNaN(Number(editMrp))) updates.mrp = Number(editMrp);
if (editStock !== '' && !isNaN(Number(editStock))) updates.stock = Math.max(0, Number(editStock));
try {
if (editingItem.id && !String(editingItem.id).startsWith('prod-')) {
await api.patchProduct(editingItem.id, patchPayload);
if (updateProduct) {
await updateProduct(editingItem.id, updates);
} else if (editingItem.id && !String(editingItem.id).startsWith('prod-')) {
await api.patchProduct(editingItem.id, updates);
}
if (updates.stock !== undefined) {
setStockValues(prev => ({ ...prev, [editingItem.id]: updates.stock }));
}
await updateStock(editingItem.id, currentStock);
await fetchData();
} catch (err) {
console.warn('Failed to update product via quick edit drawer:', err);
console.warn('Failed to update product via quick edit:', err);
} finally {
setIsSavingEdit(false);
setEditingItem(null);
@ -491,14 +508,21 @@ export const InventoryPage: React.FC = () => {
<td style={{ padding: '14px 16px', verticalAlign: 'middle', textAlign: 'right' }}>
<div className="is-flex is-align-items-center is-justify-content-end" style={{ gap: '6px' }}>
<button type="button" onClick={() => navigate('/dashboard/products/add', { state: { product: item, rejectionReason: item.rejectionReason } })}
className="button is-small" style={{ borderRadius: '6px', height: '28px', padding: '0 8px', border: item.approvalStatus === 'rejected' ? '1px solid #FCA5A5' : '1px solid #D1D5DB', backgroundColor: item.approvalStatus === 'rejected' ? '#FEF2F2' : '#FFFFFF', color: item.approvalStatus === 'rejected' ? '#DC2626' : '#374151' }}
title={item.approvalStatus === 'rejected' ? 'Rectify product & resubmit' : 'Edit Product'}
<button type="button" onClick={() => handleOpenQuickEdit(item)}
className="button is-small" style={{ borderRadius: '6px', height: '28px', padding: '0 8px', border: '1px solid #D1D5DB', backgroundColor: '#FFFFFF', color: '#374151' }}
title="Quick Edit Price & Stock"
>
<Edit3 size={12} />
</button>
<button type="button" onClick={() => navigate('/dashboard/products/add', { state: { product: item, rejectionReason: item.rejectionReason } })}
className="button is-small" style={{ borderRadius: '6px', height: '28px', padding: '0 8px', border: item.approvalStatus === 'rejected' ? '1px solid #FCA5A5' : '1px solid #E5E7EB', backgroundColor: item.approvalStatus === 'rejected' ? '#FEF2F2' : '#F9FAFB', color: item.approvalStatus === 'rejected' ? '#DC2626' : '#701A29', fontSize: '0.72rem', fontWeight: 700 }}
title={item.approvalStatus === 'rejected' ? 'Rectify product & resubmit' : 'Full 4-Step Editor & Story'}
>
Full
</button>
<button type="button" onClick={() => handleDeleteProduct(item.id, item.title)}
className="button is-small" style={{ borderRadius: '6px', height: '28px', padding: '0 8px', border: '1px solid #FCA5A5', backgroundColor: '#FFFFFF', color: '#DC2626' }}
title="Delete Product"
>
<Trash2 size={12} />
</button>
@ -570,6 +594,252 @@ export const InventoryPage: React.FC = () => {
</div>
{/* ── Quick Edit Modal ── */}
{editingItem && (
<div style={{
position: 'fixed',
inset: 0,
backgroundColor: 'rgba(17, 24, 39, 0.6)',
backdropFilter: 'blur(3px)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 9999,
padding: '1rem'
}}>
<div style={{
backgroundColor: '#FFFFFF',
borderRadius: '16px',
width: '100%',
maxWidth: '540px',
boxShadow: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
overflow: 'hidden',
border: '1px solid #E5E7EB'
}}>
{/* Modal Header */}
<div style={{
padding: '18px 24px',
borderBottom: '1px solid #F3F4F6',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
backgroundColor: '#FAFAFA'
}}>
<div>
<h3 style={{ fontSize: '1.05rem', fontWeight: 800, color: '#111827', margin: 0 }}>
Quick Edit Product
</h3>
<p style={{ fontSize: '0.78rem', color: '#6B7280', margin: '2px 0 0 0' }}>
Update pricing and stock or launch full editor
</p>
</div>
<button
type="button"
onClick={() => setEditingItem(null)}
style={{
background: 'none',
border: 'none',
cursor: 'pointer',
color: '#9CA3AF',
padding: '4px',
borderRadius: '6px'
}}
>
<X size={18} />
</button>
</div>
{/* Modal Body */}
<div style={{ padding: '20px 24px', display: 'flex', flexDirection: 'column', gap: '16px' }}>
{/* Product Info Strip */}
<div style={{
display: 'flex',
alignItems: 'center',
gap: '12px',
padding: '10px 12px',
backgroundColor: '#F9FAFB',
borderRadius: '10px',
border: '1px solid #E5E7EB'
}}>
<img
src={editingItem.image || '/images/placeholder.jpg'}
alt={editingItem.title}
style={{ width: '48px', height: '48px', objectFit: 'cover', borderRadius: '8px', border: '1px solid #E5E7EB' }}
/>
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ fontSize: '0.86rem', fontWeight: 700, color: '#111827', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{editingItem.title}
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: '8px', marginTop: '2px' }}>
<span style={{ fontSize: '0.72rem', color: '#6B7280', fontFamily: 'monospace' }}>
SKU: {editingItem.sku}
</span>
<span style={{ fontSize: '0.7rem', backgroundColor: '#EFF6FF', color: '#1D4ED8', padding: '2px 6px', borderRadius: '4px', fontWeight: 600 }}>
{editingItem.category}
</span>
</div>
</div>
</div>
{/* Title Field */}
<div>
<label style={{ display: 'block', fontSize: '0.78rem', fontWeight: 700, color: '#374151', marginBottom: '6px' }}>
Product Title
</label>
<input
type="text"
value={editTitle}
onChange={e => setEditTitle(e.target.value)}
style={{
width: '100%',
height: '38px',
padding: '0 12px',
border: '1px solid #D1D5DB',
borderRadius: '8px',
fontSize: '0.86rem',
color: '#111827'
}}
/>
</div>
{/* Pricing & Stock Grid */}
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: '12px' }}>
<div>
<label style={{ display: 'block', fontSize: '0.78rem', fontWeight: 700, color: '#374151', marginBottom: '6px' }}>
Selling Price (₹)
</label>
<input
type="number"
step="0.01"
min="1"
value={editPrice}
onChange={e => setEditPrice(e.target.value === '' ? '' : Number(e.target.value))}
style={{
width: '100%',
height: '38px',
padding: '0 12px',
border: '1px solid #D1D5DB',
borderRadius: '8px',
fontSize: '0.86rem',
color: '#111827',
fontWeight: 600
}}
/>
</div>
<div>
<label style={{ display: 'block', fontSize: '0.78rem', fontWeight: 700, color: '#374151', marginBottom: '6px' }}>
MRP (₹)
</label>
<input
type="number"
step="0.01"
min="1"
value={editMrp}
onChange={e => setEditMrp(e.target.value === '' ? '' : Number(e.target.value))}
style={{
width: '100%',
height: '38px',
padding: '0 12px',
border: '1px solid #D1D5DB',
borderRadius: '8px',
fontSize: '0.86rem',
color: '#6B7280'
}}
/>
</div>
<div>
<label style={{ display: 'block', fontSize: '0.78rem', fontWeight: 700, color: '#374151', marginBottom: '6px' }}>
Available Stock
</label>
<input
type="number"
min="0"
value={editStock}
onChange={e => setEditStock(e.target.value === '' ? '' : Number(e.target.value))}
style={{
width: '100%',
height: '38px',
padding: '0 12px',
border: '1px solid #D1D5DB',
borderRadius: '8px',
fontSize: '0.86rem',
color: '#111827',
fontWeight: 600
}}
/>
</div>
</div>
</div>
{/* Modal Footer */}
<div style={{
padding: '14px 24px',
borderTop: '1px solid #F3F4F6',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
backgroundColor: '#FAFAFA'
}}>
<button
type="button"
onClick={() => {
const itm = editingItem;
setEditingItem(null);
navigate('/dashboard/products/add', { state: { product: itm } });
}}
style={{
background: 'none',
border: 'none',
color: '#701A29',
fontSize: '0.82rem',
fontWeight: 700,
cursor: 'pointer',
textDecoration: 'underline'
}}
>
Open Full 4-Step Editor &amp; Story &rarr;
</button>
<div style={{ display: 'flex', gap: '8px' }}>
<button
type="button"
onClick={() => setEditingItem(null)}
style={{
backgroundColor: '#FFFFFF',
border: '1px solid #D1D5DB',
color: '#374151',
borderRadius: '8px',
padding: '8px 16px',
fontSize: '0.82rem',
fontWeight: 600,
cursor: 'pointer'
}}
>
Cancel
</button>
<button
type="button"
onClick={handleSaveEdit}
disabled={isSavingEdit}
style={{
backgroundColor: '#701A29',
border: 'none',
color: '#FFFFFF',
borderRadius: '8px',
padding: '8px 18px',
fontSize: '0.82rem',
fontWeight: 700,
cursor: isSavingEdit ? 'not-allowed' : 'pointer',
opacity: isSavingEdit ? 0.7 : 1
}}
>
{isSavingEdit ? 'Saving...' : 'Save Changes'}
</button>
</div>
</div>
</div>
</div>
)}
</div>
);
};