This commit is contained in:
Jake Kasper
2025-08-27 10:39:04 -04:00
parent e433f5f5a1
commit 5c4917e6f7

View File

@@ -16,6 +16,7 @@ const ApplicationExecutionModal = ({ application, propertyDetails, onClose, onCo
const [averageSpeed, setAverageSpeed] = useState(0); const [averageSpeed, setAverageSpeed] = useState(0);
const [sections, setSections] = useState([]); const [sections, setSections] = useState([]);
const [mapCenter, setMapCenter] = useState(null); const [mapCenter, setMapCenter] = useState(null);
const [planDetails, setPlanDetails] = useState(null);
// Debug: Log the application data to understand structure // Debug: Log the application data to understand structure
useEffect(() => { useEffect(() => {
@@ -37,20 +38,23 @@ const ApplicationExecutionModal = ({ application, propertyDetails, onClose, onCo
try { try {
// First try to get detailed plan information from the API // First try to get detailed plan information from the API
const planResponse = await applicationsAPI.getPlan(application.id); const planResponse = await applicationsAPI.getPlan(application.id);
const planDetails = planResponse.data.data.plan; const fetchedPlanDetails = planResponse.data.data.plan;
console.log('Fetched plan details:', planDetails); console.log('Fetched plan details:', fetchedPlanDetails);
console.log('Plan details sections:', planDetails.sections); console.log('Plan details sections:', fetchedPlanDetails.sections);
if (planDetails.sections && planDetails.sections.length > 0) { // Store the plan details for use in completeApplication
setSections(planDetails.sections); setPlanDetails(fetchedPlanDetails);
if (fetchedPlanDetails.sections && fetchedPlanDetails.sections.length > 0) {
setSections(fetchedPlanDetails.sections);
// Calculate center from section coordinates // Calculate center from section coordinates
let totalLat = 0; let totalLat = 0;
let totalLng = 0; let totalLng = 0;
let pointCount = 0; let pointCount = 0;
planDetails.sections.forEach(section => { fetchedPlanDetails.sections.forEach(section => {
let polygonData = section.polygonData; let polygonData = section.polygonData;
if (typeof polygonData === 'string') { if (typeof polygonData === 'string') {
try { try {
@@ -78,7 +82,7 @@ const ApplicationExecutionModal = ({ application, propertyDetails, onClose, onCo
} }
// Fallback: If we have property details, use those sections // Fallback: If we have property details, use those sections
if ((!planDetails.sections || planDetails.sections.length === 0) && propertyDetails?.sections) { if ((!fetchedPlanDetails.sections || fetchedPlanDetails.sections.length === 0) && propertyDetails?.sections) {
const applicationSectionIds = application.sections?.map(s => s.id) || []; const applicationSectionIds = application.sections?.map(s => s.id) || [];
const relevantSections = propertyDetails.sections.filter(section => const relevantSections = propertyDetails.sections.filter(section =>
applicationSectionIds.includes(section.id) applicationSectionIds.includes(section.id)
@@ -206,11 +210,16 @@ const ApplicationExecutionModal = ({ application, propertyDetails, onClose, onCo
const endTime = new Date(); const endTime = new Date();
const duration = startTime ? (endTime - startTime) / 1000 : 0; // seconds const duration = startTime ? (endTime - startTime) / 1000 : 0; // seconds
// Ensure we have valid section data from fetched plan details // Debug logging for plan details
console.log('Complete Application - Plan Details:', planDetails);
console.log('Complete Application - Equipment:', planDetails?.equipment);
console.log('Complete Application - Products:', planDetails?.products);
// Ensure we have valid data from fetched plan details
const validSectionId = sections.length > 0 ? sections[0].id : null; const validSectionId = sections.length > 0 ? sections[0].id : null;
const validEquipmentId = application.equipment?.id; const validEquipmentId = planDetails?.equipment?.id;
const validProducts = application.products && application.products.length > 0 ? const validProducts = planDetails?.products && planDetails.products.length > 0 ?
application.products.map(product => ({ planDetails.products.map(product => ({
productId: product.productId, productId: product.productId,
userProductId: product.userProductId, userProductId: product.userProductId,
rateAmount: product.rateAmount, rateAmount: product.rateAmount,