asdfsadfdsa
This commit is contained in:
@@ -7,13 +7,15 @@ import {
|
||||
CalculatorIcon,
|
||||
PencilIcon,
|
||||
TrashIcon,
|
||||
PlayIcon
|
||||
PlayIcon,
|
||||
EyeIcon
|
||||
} from '@heroicons/react/24/outline';
|
||||
import { propertiesAPI, productsAPI, equipmentAPI, applicationsAPI, nozzlesAPI } from '../../services/api';
|
||||
import LoadingSpinner from '../../components/UI/LoadingSpinner';
|
||||
import PropertyMap from '../../components/Maps/PropertyMap';
|
||||
import ApplicationExecutionModal from '../../components/Applications/ApplicationExecutionModal';
|
||||
import ApplicationPlanModal from '../../components/Applications/ApplicationPlanModal';
|
||||
import ApplicationViewModal from '../../components/Applications/ApplicationViewModal';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
const Applications = () => {
|
||||
@@ -31,6 +33,8 @@ const Applications = () => {
|
||||
const [loadingRecommendation, setLoadingRecommendation] = useState(false);
|
||||
const [executingApplication, setExecutingApplication] = useState(null);
|
||||
const [showExecutionModal, setShowExecutionModal] = useState(false);
|
||||
const [showViewModal, setShowViewModal] = useState(false);
|
||||
const [viewingApplication, setViewingApplication] = useState(null);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
@@ -167,6 +171,30 @@ const Applications = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleViewApplication = async (application) => {
|
||||
try {
|
||||
// Set the viewing application and show the modal
|
||||
setViewingApplication(application);
|
||||
|
||||
// Get the property ID from the application
|
||||
const propertyId = application.property?.id || application.section?.propertyId;
|
||||
|
||||
// Try to fetch property details if we have a valid property ID
|
||||
if (propertyId && (!selectedPropertyDetails || selectedPropertyDetails.id !== propertyId)) {
|
||||
await fetchPropertyDetails(propertyId);
|
||||
} else if (!propertyId) {
|
||||
console.warn('No property ID found for application:', application);
|
||||
// Clear any existing property details since this application doesn't have property info
|
||||
setSelectedPropertyDetails(null);
|
||||
}
|
||||
|
||||
setShowViewModal(true);
|
||||
} catch (error) {
|
||||
console.error('Failed to load application details:', error);
|
||||
toast.error('Failed to load application details');
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
@@ -403,28 +431,39 @@ const Applications = () => {
|
||||
</p>
|
||||
<div className="flex gap-2 mt-2">
|
||||
{application.status === 'planned' && (
|
||||
<>
|
||||
<button
|
||||
onClick={() => handleExecuteApplication(application)}
|
||||
className="p-1 text-green-600 hover:text-green-800 hover:bg-green-50 rounded"
|
||||
title="Execute application"
|
||||
>
|
||||
<PlayIcon className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleEditPlan(application.id)}
|
||||
className="p-1 text-blue-600 hover:text-blue-800 hover:bg-blue-50 rounded"
|
||||
title="Edit plan"
|
||||
>
|
||||
<PencilIcon className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleDeletePlan(application.id, `${application.propertyName} - ${application.sectionName}`)}
|
||||
className="p-1 text-red-600 hover:text-red-800 hover:bg-red-50 rounded"
|
||||
title="Delete plan"
|
||||
>
|
||||
<TrashIcon className="h-4 w-4" />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{application.status === 'completed' && (
|
||||
<button
|
||||
onClick={() => handleExecuteApplication(application)}
|
||||
className="p-1 text-green-600 hover:text-green-800 hover:bg-green-50 rounded"
|
||||
title="Execute application"
|
||||
onClick={() => handleViewApplication(application)}
|
||||
className="p-1 text-indigo-600 hover:text-indigo-800 hover:bg-indigo-50 rounded"
|
||||
title="View completed application"
|
||||
>
|
||||
<PlayIcon className="h-4 w-4" />
|
||||
<EyeIcon className="h-4 w-4" />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={() => handleEditPlan(application.id)}
|
||||
className="p-1 text-blue-600 hover:text-blue-800 hover:bg-blue-50 rounded"
|
||||
title="Edit plan"
|
||||
>
|
||||
<PencilIcon className="h-4 w-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleDeletePlan(application.id, `${application.propertyName} - ${application.sectionName}`)}
|
||||
className="p-1 text-red-600 hover:text-red-800 hover:bg-red-50 rounded"
|
||||
title="Delete plan"
|
||||
>
|
||||
<TrashIcon className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -593,6 +632,18 @@ const Applications = () => {
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Application View Modal */}
|
||||
{showViewModal && viewingApplication && (
|
||||
<ApplicationViewModal
|
||||
application={viewingApplication}
|
||||
propertyDetails={selectedPropertyDetails}
|
||||
onClose={() => {
|
||||
setShowViewModal(false);
|
||||
setViewingApplication(null);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user