This commit is contained in:
Jake Kasper
2025-08-25 14:10:28 -04:00
parent eef39c6a59
commit 1bd5a76cd8

View File

@@ -265,6 +265,9 @@ const Applications = () => {
selectedPropertyDetails={selectedPropertyDetails}
onPropertySelect={fetchPropertyDetails}
editingPlan={editingPlan}
spreaderRecommendation={spreaderRecommendation}
loadingRecommendation={loadingRecommendation}
loadSpreaderRecommendation={loadSpreaderRecommendation}
onSubmit={async (planData) => {
try {
if (editingPlan) {
@@ -371,68 +374,6 @@ const Applications = () => {
)}
</div>
);
};
// Application Planning Modal Component
const ApplicationPlanModal = ({
onClose,
onSubmit,
properties,
products,
equipment,
nozzles,
selectedPropertyDetails,
onPropertySelect,
editingPlan
}) => {
const [loadingProperty, setLoadingProperty] = useState(false);
const [planData, setPlanData] = useState({
propertyId: '',
selectedAreas: [],
productId: '',
selectedProduct: null,
applicationType: '', // 'liquid' or 'granular'
equipmentId: '',
nozzleId: '',
plannedDate: '',
notes: ''
});
// Initialize form with editing data
useEffect(() => {
if (editingPlan && products.length > 0) {
const propertyId = editingPlan.section?.propertyId || editingPlan.property?.id;
// Find the product from the plans products array
const planProduct = editingPlan.products?.[0];
let selectedProduct = null;
if (planProduct) {
if (planProduct.productId) {
selectedProduct = products.find(p => p.uniqueId === `shared_${planProduct.productId}`);
} else if (planProduct.userProductId) {
selectedProduct = products.find(p => p.uniqueId === `user_${planProduct.userProductId}`);
}
}
setPlanData({
propertyId: propertyId?.toString() || '',
selectedAreas: [editingPlan.section?.id],
productId: selectedProduct?.uniqueId || '',
selectedProduct: selectedProduct,
applicationType: planProduct?.applicationType || '',
equipmentId: editingPlan.equipment?.id?.toString() || '',
nozzleId: editingPlan.nozzle?.id?.toString() || '',
plannedDate: editingPlan.plannedDate ? new Date(editingPlan.plannedDate).toISOString().split('T')[0] : '',
notes: editingPlan.notes || ''
});
// Only fetch property details if we don't already have them
if (propertyId && (!selectedPropertyDetails || selectedPropertyDetails.id !== propertyId)) {
onPropertySelect(propertyId);
}
}
}, [editingPlan, products]);
// Load spreader recommendations when granular product and spreader are selected
const loadSpreaderRecommendation = async (product, equipmentId, selectedAreas) => {
@@ -531,11 +472,76 @@ const ApplicationPlanModal = ({
setLoadingRecommendation(false);
}
};
};
// Application Planning Modal Component
const ApplicationPlanModal = ({
onClose,
onSubmit,
properties,
products,
equipment,
nozzles,
selectedPropertyDetails,
onPropertySelect,
editingPlan,
spreaderRecommendation,
loadingRecommendation,
loadSpreaderRecommendation
}) => {
const [loadingProperty, setLoadingProperty] = useState(false);
const [planData, setPlanData] = useState({
propertyId: '',
selectedAreas: [],
productId: '',
selectedProduct: null,
applicationType: '', // 'liquid' or 'granular'
equipmentId: '',
nozzleId: '',
plannedDate: '',
notes: ''
});
// Initialize form with editing data
useEffect(() => {
if (editingPlan && products.length > 0) {
const propertyId = editingPlan.section?.propertyId || editingPlan.property?.id;
// Find the product from the plans products array
const planProduct = editingPlan.products?.[0];
let selectedProduct = null;
if (planProduct) {
if (planProduct.productId) {
selectedProduct = products.find(p => p.uniqueId === `shared_${planProduct.productId}`);
} else if (planProduct.userProductId) {
selectedProduct = products.find(p => p.uniqueId === `user_${planProduct.userProductId}`);
}
}
setPlanData({
propertyId: propertyId?.toString() || '',
selectedAreas: [editingPlan.section?.id],
productId: selectedProduct?.uniqueId || '',
selectedProduct: selectedProduct,
applicationType: planProduct?.applicationType || '',
equipmentId: editingPlan.equipment?.id?.toString() || '',
nozzleId: editingPlan.nozzle?.id?.toString() || '',
plannedDate: editingPlan.plannedDate ? new Date(editingPlan.plannedDate).toISOString().split('T')[0] : '',
notes: editingPlan.notes || ''
});
// Only fetch property details if we don't already have them
if (propertyId && (!selectedPropertyDetails || selectedPropertyDetails.id !== propertyId)) {
onPropertySelect(propertyId);
}
}
}, [editingPlan, products]);
// Load spreader recommendation when relevant fields change
useEffect(() => {
loadSpreaderRecommendation(planData.selectedProduct, planData.equipmentId, planData.selectedAreas);
}, [planData.selectedProduct, planData.equipmentId, planData.selectedAreas, selectedPropertyDetails, equipment]);
}, [planData.selectedProduct, planData.equipmentId, planData.selectedAreas, selectedPropertyDetails, equipment, loadSpreaderRecommendation]);
const handlePropertyChange = async (propertyId) => {
setPlanData({ ...planData, propertyId, selectedAreas: [] });
@@ -546,6 +552,7 @@ const ApplicationPlanModal = ({
}
};
// Filter equipment based on application type
const availableEquipment = equipment.filter(eq => {
if (planData.applicationType === 'liquid') {