uha
This commit is contained in:
@@ -265,6 +265,9 @@ const Applications = () => {
|
|||||||
selectedPropertyDetails={selectedPropertyDetails}
|
selectedPropertyDetails={selectedPropertyDetails}
|
||||||
onPropertySelect={fetchPropertyDetails}
|
onPropertySelect={fetchPropertyDetails}
|
||||||
editingPlan={editingPlan}
|
editingPlan={editingPlan}
|
||||||
|
spreaderRecommendation={spreaderRecommendation}
|
||||||
|
loadingRecommendation={loadingRecommendation}
|
||||||
|
loadSpreaderRecommendation={loadSpreaderRecommendation}
|
||||||
onSubmit={async (planData) => {
|
onSubmit={async (planData) => {
|
||||||
try {
|
try {
|
||||||
if (editingPlan) {
|
if (editingPlan) {
|
||||||
@@ -371,68 +374,6 @@ const Applications = () => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</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
|
// Load spreader recommendations when granular product and spreader are selected
|
||||||
const loadSpreaderRecommendation = async (product, equipmentId, selectedAreas) => {
|
const loadSpreaderRecommendation = async (product, equipmentId, selectedAreas) => {
|
||||||
@@ -531,11 +472,76 @@ const ApplicationPlanModal = ({
|
|||||||
setLoadingRecommendation(false);
|
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
|
// Load spreader recommendation when relevant fields change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadSpreaderRecommendation(planData.selectedProduct, planData.equipmentId, planData.selectedAreas);
|
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) => {
|
const handlePropertyChange = async (propertyId) => {
|
||||||
setPlanData({ ...planData, propertyId, selectedAreas: [] });
|
setPlanData({ ...planData, propertyId, selectedAreas: [] });
|
||||||
@@ -545,6 +551,7 @@ const ApplicationPlanModal = ({
|
|||||||
setLoadingProperty(false);
|
setLoadingProperty(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Filter equipment based on application type
|
// Filter equipment based on application type
|
||||||
const availableEquipment = equipment.filter(eq => {
|
const availableEquipment = equipment.filter(eq => {
|
||||||
|
|||||||
Reference in New Issue
Block a user