Sort jobs such and such
This commit is contained in:
@@ -29,9 +29,9 @@ const JobCard: React.FC<JobCardProps> = ({ job, onEdit, onDelete }) => {
|
||||
case 'Planned': return 'bg-gray-600';
|
||||
case 'Acquisition': return 'bg-yellow-600';
|
||||
case 'Running': return 'bg-blue-600';
|
||||
case 'Done': return 'bg-green-600';
|
||||
case 'Selling': return 'bg-purple-600';
|
||||
case 'Closed': return 'bg-gray-800';
|
||||
case 'Done': return 'bg-purple-600';
|
||||
case 'Selling': return 'bg-orange-600';
|
||||
case 'Closed': return 'bg-green-600';
|
||||
default: return 'bg-gray-600';
|
||||
}
|
||||
};
|
||||
|
@@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Plus, Factory, TrendingUp, Briefcase } from 'lucide-react';
|
||||
import { IndTransactionRecordNoId, IndJobRecordNoId, IndTransactionRecord } from '@/lib/pbtypes';
|
||||
import { IndTransactionRecordNoId, IndJobRecordNoId, IndTransactionRecord, IndJobStatusOptions } from '@/lib/pbtypes';
|
||||
import * as jobService from '@/services/jobService';
|
||||
import * as transactionService from '@/services/transactionService';
|
||||
import { formatISK } from '@/utils/priceUtils';
|
||||
@@ -36,6 +36,29 @@ const Index = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Sort jobs by status priority
|
||||
const getStatusPriority = (status: IndJobStatusOptions): number => {
|
||||
switch (status) {
|
||||
case 'Planned': return 6;
|
||||
case 'Acquisition': return 1;
|
||||
case 'Running': return 2;
|
||||
case 'Done': return 3;
|
||||
case 'Selling': return 4;
|
||||
case 'Closed': return 5;
|
||||
default: return 0;
|
||||
}
|
||||
};
|
||||
|
||||
const sortedJobs = [...jobs].sort((a, b) => {
|
||||
const priorityA = getStatusPriority(a.status);
|
||||
const priorityB = getStatusPriority(b.status);
|
||||
if (priorityA === priorityB) {
|
||||
// If same status, sort by creation date (newest first)
|
||||
return new Date(b.created || '').getTime() - new Date(a.created || '').getTime();
|
||||
}
|
||||
return priorityA - priorityB;
|
||||
});
|
||||
|
||||
const handleCreateJob = async (jobData: IndJobRecordNoId) => {
|
||||
try {
|
||||
const newJob = await createJob(jobData);
|
||||
@@ -296,7 +319,7 @@ const Index = () => {
|
||||
</Card>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 gap-6">
|
||||
{jobs.map((job) => (
|
||||
{sortedJobs.map((job) => (
|
||||
<div key={job.id} onClick={() => setSelectedJob(job)} className="cursor-pointer">
|
||||
<JobCard
|
||||
job={job}
|
||||
|
@@ -39,9 +39,15 @@ export const parseTransactionLine = (line: string): {
|
||||
} | null => {
|
||||
try {
|
||||
const parts = line.split('\t');
|
||||
if (parts.length < 8) return null;
|
||||
if (parts.length < 6) return null;
|
||||
|
||||
let dateStr, quantityStr, itemName, unitPriceStr, totalAmountStr, buyer, location, corporation, wallet;
|
||||
if (parts.length === 8) {
|
||||
[dateStr, quantityStr, itemName, unitPriceStr, totalAmountStr, buyer, location, corporation, wallet] = parts;
|
||||
} else {
|
||||
[dateStr, quantityStr, itemName, unitPriceStr, totalAmountStr, buyer, location] = parts;
|
||||
}
|
||||
|
||||
const [dateStr, quantityStr, itemName, unitPriceStr, totalAmountStr, buyer, location, corporation, wallet] = parts;
|
||||
|
||||
// Parse date (YYYY.MM.DD HH:mm format)
|
||||
const [datePart, timePart] = dateStr.split(' ');
|
||||
|
Reference in New Issue
Block a user