admin products
This commit is contained in:
@@ -219,18 +219,49 @@ const AdminProducts = () => {
|
||||
setSelectedProduct(null);
|
||||
};
|
||||
|
||||
const openEditModal = (product) => {
|
||||
const openEditModal = async (product) => {
|
||||
setSelectedProduct(product);
|
||||
const productType = product.productType || product.customProductType || 'granular';
|
||||
|
||||
// Seed blend defaults from row (shared products expose seedBlend directly)
|
||||
let nextSeedBlend = product.seedBlend || [];
|
||||
let nextRates = product.rates && product.rates.length > 0 ? product.rates : [];
|
||||
|
||||
// Fetch rates for shared products so preview/editor has full data
|
||||
if (product.isShared && product.id && adminAPI.getProductRates) {
|
||||
try {
|
||||
const r = await adminAPI.getProductRates(product.id);
|
||||
nextRates = r.data?.data?.rates || nextRates;
|
||||
} catch (e) {
|
||||
console.warn('Admin fetch rates failed', e?.response?.data || e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// For custom seed products, parse activeIngredients JSON for blend and seed rates
|
||||
if (!product.isShared && productType === 'seed' && product.customActiveIngredients) {
|
||||
try {
|
||||
const ai = typeof product.customActiveIngredients === 'string' ? JSON.parse(product.customActiveIngredients) : product.customActiveIngredients;
|
||||
if (Array.isArray(ai?.seedBlend)) nextSeedBlend = ai.seedBlend;
|
||||
if (ai?.seedRates) {
|
||||
const unit = ai.seedRates.unit || product.customRateUnit || 'lbs/1000 sq ft';
|
||||
const rates = [];
|
||||
if (ai.seedRates.new) rates.push({ applicationType: 'New Lawn', rateAmount: ai.seedRates.new, rateUnit: unit, notes: '' });
|
||||
if (ai.seedRates.overseed) rates.push({ applicationType: 'Overseeding', rateAmount: ai.seedRates.overseed, rateUnit: unit, notes: '' });
|
||||
if (rates.length) nextRates = rates;
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
setFormData({
|
||||
name: product.name || product.customName || '',
|
||||
brand: product.brand || product.customBrand || '',
|
||||
categoryId: product.categoryId || '',
|
||||
productType: product.productType || product.customProductType || 'granular',
|
||||
productType,
|
||||
activeIngredients: product.activeIngredients || product.customActiveIngredients || '',
|
||||
description: product.description || product.customDescription || '',
|
||||
seedBlend: product.seedBlend || [],
|
||||
rates: product.rates && product.rates.length > 0 ? product.rates : [{
|
||||
applicationType: product.productType || 'granular',
|
||||
seedBlend: nextSeedBlend,
|
||||
rates: nextRates.length > 0 ? nextRates : [{
|
||||
applicationType: productType,
|
||||
rateAmount: product.customRateAmount || '',
|
||||
rateUnit: product.customRateUnit || 'lbs/1000 sq ft',
|
||||
notes: ''
|
||||
|
||||
Reference in New Issue
Block a user