history page
This commit is contained in:
@@ -22,6 +22,10 @@ const History = () => {
|
|||||||
const [selectedPropertyDetails, setSelectedPropertyDetails] = useState(null);
|
const [selectedPropertyDetails, setSelectedPropertyDetails] = useState(null);
|
||||||
const [dateFilter, setDateFilter] = useState('all'); // all, today, week, month
|
const [dateFilter, setDateFilter] = useState('all'); // all, today, week, month
|
||||||
const [sortBy, setSortBy] = useState('date'); // date, area, duration
|
const [sortBy, setSortBy] = useState('date'); // date, area, duration
|
||||||
|
const [statusFilter, setStatusFilter] = useState('all'); // all, completed, archived
|
||||||
|
const [propertyFilter, setPropertyFilter] = useState('all');
|
||||||
|
const [productFilter, setProductFilter] = useState('all');
|
||||||
|
const [showFilters, setShowFilters] = useState(false);
|
||||||
|
|
||||||
// Calculate coverage percentage based on GPS tracking and equipment specifications
|
// Calculate coverage percentage based on GPS tracking and equipment specifications
|
||||||
const calculateCoverage = (application, log) => {
|
const calculateCoverage = (application, log) => {
|
||||||
@@ -66,15 +70,21 @@ const History = () => {
|
|||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// Fetch completed applications (plans with completed status)
|
// Fetch completed and archived applications
|
||||||
const plansResponse = await applicationsAPI.getPlans({ status: 'completed' });
|
const [completedResponse, archivedResponse] = await Promise.all([
|
||||||
const completedPlans = plansResponse.data.data.plans || [];
|
applicationsAPI.getPlans({ status: 'completed' }),
|
||||||
|
applicationsAPI.getPlans({ status: 'archived' })
|
||||||
|
]);
|
||||||
|
|
||||||
|
const completedPlans = completedResponse.data.data.plans || [];
|
||||||
|
const archivedPlans = archivedResponse.data.data.plans || [];
|
||||||
|
const allHistoryApplications = [...completedPlans, ...archivedPlans];
|
||||||
|
|
||||||
// Fetch application logs for additional details
|
// Fetch application logs for additional details
|
||||||
const logsResponse = await applicationsAPI.getLogs();
|
const logsResponse = await applicationsAPI.getLogs();
|
||||||
const logs = logsResponse.data.data.logs || [];
|
const logs = logsResponse.data.data.logs || [];
|
||||||
|
|
||||||
setCompletedApplications(completedPlans);
|
setCompletedApplications(allHistoryApplications);
|
||||||
setApplicationLogs(logs);
|
setApplicationLogs(logs);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -95,25 +105,48 @@ const History = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Filter applications based on date filter
|
// Get unique values for filter options
|
||||||
|
const uniqueProperties = [...new Set(completedApplications.map(app => app.propertyName))].filter(Boolean);
|
||||||
|
const uniqueProducts = [...new Set(
|
||||||
|
completedApplications.flatMap(app =>
|
||||||
|
app.products ? app.products.map(p => p.productName) : []
|
||||||
|
)
|
||||||
|
)].filter(Boolean);
|
||||||
|
|
||||||
|
// Filter applications based on all filters
|
||||||
const filteredApplications = completedApplications.filter(app => {
|
const filteredApplications = completedApplications.filter(app => {
|
||||||
if (dateFilter === 'all') return true;
|
// Date filter
|
||||||
|
if (dateFilter !== 'all') {
|
||||||
const appDate = new Date(app.plannedDate);
|
const appDate = new Date(app.plannedDate);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
switch (dateFilter) {
|
switch (dateFilter) {
|
||||||
case 'today':
|
case 'today':
|
||||||
return appDate.toDateString() === now.toDateString();
|
if (appDate.toDateString() !== now.toDateString()) return false;
|
||||||
case 'week':
|
break;
|
||||||
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
|
case 'week':
|
||||||
return appDate >= weekAgo;
|
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
|
||||||
case 'month':
|
if (appDate < weekAgo) return false;
|
||||||
const monthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
|
break;
|
||||||
return appDate >= monthAgo;
|
case 'month':
|
||||||
default:
|
const monthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
|
||||||
return true;
|
if (appDate < monthAgo) return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Status filter
|
||||||
|
if (statusFilter !== 'all' && app.status !== statusFilter) return false;
|
||||||
|
|
||||||
|
// Property filter
|
||||||
|
if (propertyFilter !== 'all' && app.propertyName !== propertyFilter) return false;
|
||||||
|
|
||||||
|
// Product filter
|
||||||
|
if (productFilter !== 'all') {
|
||||||
|
if (!app.products || !app.products.some(p => p.productName === productFilter)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sort applications
|
// Sort applications
|
||||||
@@ -195,47 +228,138 @@ const History = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Filters and Sort */}
|
{/* Filters and Sort */}
|
||||||
<div className="bg-white p-4 rounded-lg shadow mb-6">
|
<div className="bg-white rounded-lg shadow mb-6">
|
||||||
<div className="flex flex-wrap gap-4">
|
<div className="p-4 border-b border-gray-200">
|
||||||
<div>
|
<button
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">
|
onClick={() => setShowFilters(!showFilters)}
|
||||||
Time Period
|
className="flex items-center justify-between w-full text-left"
|
||||||
</label>
|
>
|
||||||
<select
|
<h3 className="text-lg font-medium text-gray-900">Filters & Sorting</h3>
|
||||||
value={dateFilter}
|
<svg
|
||||||
onChange={(e) => setDateFilter(e.target.value)}
|
className={`h-5 w-5 transform transition-transform ${showFilters ? 'rotate-180' : ''}`}
|
||||||
className="border border-gray-300 rounded px-3 py-2 text-sm"
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
>
|
>
|
||||||
<option value="all">All Time</option>
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
|
||||||
<option value="today">Today</option>
|
</svg>
|
||||||
<option value="week">Last Week</option>
|
</button>
|
||||||
<option value="month">Last Month</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">
|
|
||||||
Sort By
|
|
||||||
</label>
|
|
||||||
<select
|
|
||||||
value={sortBy}
|
|
||||||
onChange={(e) => setSortBy(e.target.value)}
|
|
||||||
className="border border-gray-300 rounded px-3 py-2 text-sm"
|
|
||||||
>
|
|
||||||
<option value="date">Date</option>
|
|
||||||
<option value="area">Area Size</option>
|
|
||||||
<option value="duration">Duration</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{showFilters && (
|
||||||
|
<div className="p-4">
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5 gap-4">
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
|
Time Period
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={dateFilter}
|
||||||
|
onChange={(e) => setDateFilter(e.target.value)}
|
||||||
|
className="w-full border border-gray-300 rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
|
>
|
||||||
|
<option value="all">All Time</option>
|
||||||
|
<option value="today">Today</option>
|
||||||
|
<option value="week">Last Week</option>
|
||||||
|
<option value="month">Last Month</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
|
Status
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={statusFilter}
|
||||||
|
onChange={(e) => setStatusFilter(e.target.value)}
|
||||||
|
className="w-full border border-gray-300 rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
|
>
|
||||||
|
<option value="all">All Status</option>
|
||||||
|
<option value="completed">Completed</option>
|
||||||
|
<option value="archived">Archived</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
|
Property
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={propertyFilter}
|
||||||
|
onChange={(e) => setPropertyFilter(e.target.value)}
|
||||||
|
className="w-full border border-gray-300 rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
|
>
|
||||||
|
<option value="all">All Properties</option>
|
||||||
|
{uniqueProperties.map(property => (
|
||||||
|
<option key={property} value={property}>{property}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
|
Product
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={productFilter}
|
||||||
|
onChange={(e) => setProductFilter(e.target.value)}
|
||||||
|
className="w-full border border-gray-300 rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
|
>
|
||||||
|
<option value="all">All Products</option>
|
||||||
|
{uniqueProducts.map(product => (
|
||||||
|
<option key={product} value={product}>{product}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
|
Sort By
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={sortBy}
|
||||||
|
onChange={(e) => setSortBy(e.target.value)}
|
||||||
|
className="w-full border border-gray-300 rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
|
>
|
||||||
|
<option value="date">Date</option>
|
||||||
|
<option value="area">Area Size</option>
|
||||||
|
<option value="duration">Duration</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-4 pt-4 border-t border-gray-200">
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setDateFilter('all');
|
||||||
|
setStatusFilter('all');
|
||||||
|
setPropertyFilter('all');
|
||||||
|
setProductFilter('all');
|
||||||
|
setSortBy('date');
|
||||||
|
}}
|
||||||
|
className="px-4 py-2 text-sm text-gray-600 hover:text-gray-800 border border-gray-300 rounded hover:bg-gray-50"
|
||||||
|
>
|
||||||
|
Clear All Filters
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Applications List */}
|
{/* Applications List */}
|
||||||
{sortedApplications.length === 0 ? (
|
{sortedApplications.length === 0 ? (
|
||||||
<div className="text-center py-12">
|
<div className="text-center py-12">
|
||||||
<CalendarIcon className="h-12 w-12 text-gray-400 mx-auto mb-4" />
|
<CalendarIcon className="h-12 w-12 text-gray-400 mx-auto mb-4" />
|
||||||
<h3 className="text-lg font-medium text-gray-900 mb-2">No completed applications</h3>
|
<h3 className="text-lg font-medium text-gray-900 mb-2">
|
||||||
<p className="text-gray-500">Complete some applications to see them here.</p>
|
{statusFilter === 'completed' ? 'No completed applications' :
|
||||||
|
statusFilter === 'archived' ? 'No archived applications' :
|
||||||
|
'No completed or archived applications'}
|
||||||
|
</h3>
|
||||||
|
<p className="text-gray-500">
|
||||||
|
{statusFilter === 'completed' ? 'Complete some applications to see them here.' :
|
||||||
|
statusFilter === 'archived' ? 'Archive some completed applications to see them here.' :
|
||||||
|
'Complete and archive applications to see them here.'}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="grid gap-4">
|
<div className="grid gap-4">
|
||||||
@@ -250,8 +374,12 @@ const History = () => {
|
|||||||
<h3 className="text-lg font-semibold text-gray-900">
|
<h3 className="text-lg font-semibold text-gray-900">
|
||||||
{application.propertyName} - {application.sectionNames}
|
{application.propertyName} - {application.sectionNames}
|
||||||
</h3>
|
</h3>
|
||||||
<span className="px-3 py-1 text-sm font-medium rounded-full bg-green-100 text-green-800">
|
<span className={`px-3 py-1 text-sm font-medium rounded-full ${
|
||||||
Completed
|
application.status === 'archived'
|
||||||
|
? 'bg-gray-100 text-gray-800'
|
||||||
|
: 'bg-green-100 text-green-800'
|
||||||
|
}`}>
|
||||||
|
{application.status === 'archived' ? 'Archived' : 'Completed'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user