asdfa
This commit is contained in:
@@ -245,7 +245,10 @@ const Applications = () => {
|
||||
<p className="text-gray-600">Plan, track, and log your lawn applications</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setShowPlanForm(true)}
|
||||
onClick={() => {
|
||||
setSelectedPropertyDetails(null); // Clear previous property data
|
||||
setShowPlanForm(true);
|
||||
}}
|
||||
className="btn-primary flex items-center gap-2"
|
||||
>
|
||||
<PlusIcon className="h-5 w-5" />
|
||||
@@ -262,7 +265,10 @@ const Applications = () => {
|
||||
Start by planning your first lawn application
|
||||
</p>
|
||||
<button
|
||||
onClick={() => setShowPlanForm(true)}
|
||||
onClick={() => {
|
||||
setSelectedPropertyDetails(null); // Clear previous property data
|
||||
setShowPlanForm(true);
|
||||
}}
|
||||
className="btn-primary"
|
||||
>
|
||||
Plan Your First Application
|
||||
@@ -569,7 +575,7 @@ const ApplicationPlanModal = ({
|
||||
|
||||
// Reset form when modal opens fresh (not editing)
|
||||
useEffect(() => {
|
||||
if (!editingPlan) {
|
||||
if (!editingPlan && showPlanForm) {
|
||||
setPlanData({
|
||||
propertyId: '',
|
||||
selectedAreas: [],
|
||||
@@ -582,8 +588,25 @@ const ApplicationPlanModal = ({
|
||||
plannedDate: '',
|
||||
notes: ''
|
||||
});
|
||||
// Also clear property details for new plans to prevent showing previous property's map
|
||||
setSelectedPropertyDetails(null);
|
||||
}
|
||||
}, [editingPlan]);
|
||||
}, [editingPlan, showPlanForm]);
|
||||
|
||||
// Check spreader settings when both product and equipment are selected for granular applications
|
||||
useEffect(() => {
|
||||
if (planData.applicationType === 'granular' &&
|
||||
planData.selectedProduct &&
|
||||
planData.equipmentId &&
|
||||
!editingPlan) { // Only for new plans, not when editing
|
||||
console.log('Triggering spreader setting check from useEffect:', {
|
||||
product: planData.selectedProduct?.customName || planData.selectedProduct?.name,
|
||||
equipmentId: planData.equipmentId,
|
||||
applicationType: planData.applicationType
|
||||
});
|
||||
checkSpreaderSetting(planData.selectedProduct, planData.equipmentId);
|
||||
}
|
||||
}, [planData.applicationType, planData.selectedProduct, planData.equipmentId, editingPlan]);
|
||||
|
||||
// Initialize form with editing data
|
||||
useEffect(() => {
|
||||
@@ -668,16 +691,36 @@ const ApplicationPlanModal = ({
|
||||
|
||||
// Check for spreader settings when granular product + equipment selected
|
||||
const checkSpreaderSetting = async (product, equipmentId) => {
|
||||
if (!product || !equipmentId ||
|
||||
(product.productType !== 'granular' && product.customProductType !== 'granular')) {
|
||||
if (!product || !equipmentId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if product is granular (more flexible matching like the product filter)
|
||||
const productType = product.productType || product.customProductType;
|
||||
const isGranular = productType && (
|
||||
productType.toLowerCase().includes('granular') ||
|
||||
productType.toLowerCase().includes('granule')
|
||||
);
|
||||
|
||||
if (!isGranular) {
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedEquipment = equipment.find(eq => eq.id === parseInt(equipmentId));
|
||||
if (!selectedEquipment || selectedEquipment.categoryName !== 'Spreader') {
|
||||
console.log('Spreader setting check skipped - equipment not a spreader:', {
|
||||
selectedEquipment: selectedEquipment?.customName,
|
||||
category: selectedEquipment?.categoryName
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Checking spreader setting for:', {
|
||||
product: product.customName || product.name,
|
||||
equipment: selectedEquipment.customName,
|
||||
productType: productType
|
||||
});
|
||||
|
||||
try {
|
||||
// Check if spreader setting exists
|
||||
const productApiId = product.isShared ? product.id : product.id;
|
||||
|
||||
Reference in New Issue
Block a user