Refactor: Use new services and types
Update frontend components to use the new services and types for job management, including facilities, jobs, and transactions. Remove old type definitions and integrate the new ones.
This commit is contained in:
@@ -7,31 +7,42 @@ import { Badge } from '@/components/ui/badge';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { parseTransactionLine, formatISK } from '@/utils/priceUtils';
|
||||
import { Transaction } from '@/services/jobService';
|
||||
import { Upload, Check, X } from 'lucide-react';
|
||||
import { IndTransactionRecord } from '@/lib/pbtypes';
|
||||
import { Check, X } from 'lucide-react';
|
||||
|
||||
interface TransactionFormProps {
|
||||
jobId: string;
|
||||
onTransactionsAdded: (transactions: Transaction[], type: 'expenditure' | 'income') => void;
|
||||
onTransactionsAdded: (transactions: IndTransactionRecord[], type: 'expenditure' | 'income') => void;
|
||||
}
|
||||
|
||||
const TransactionForm: React.FC<TransactionFormProps> = ({ jobId, onTransactionsAdded }) => {
|
||||
const [pastedData, setPastedData] = useState('');
|
||||
const [parsedTransactions, setParsedTransactions] = useState<Transaction[]>([]);
|
||||
const [parsedTransactions, setParsedTransactions] = useState<IndTransactionRecord[]>([]);
|
||||
const [transactionType, setTransactionType] = useState<'expenditure' | 'income'>('expenditure');
|
||||
|
||||
const handlePaste = (value: string) => {
|
||||
setPastedData(value);
|
||||
|
||||
const lines = value.trim().split('\n');
|
||||
const transactions: Transaction[] = [];
|
||||
const transactions: IndTransactionRecord[] = [];
|
||||
|
||||
lines.forEach((line, index) => {
|
||||
const parsed = parseTransactionLine(line);
|
||||
if (parsed) {
|
||||
transactions.push({
|
||||
id: `temp-${index}`,
|
||||
...parsed
|
||||
date: parsed.date.toISOString(),
|
||||
quantity: parsed.quantity,
|
||||
itemName: parsed.itemName,
|
||||
unitPrice: parsed.unitPrice,
|
||||
totalPrice: Math.abs(parsed.totalAmount),
|
||||
buyer: parsed.buyer,
|
||||
location: parsed.location,
|
||||
corporation: parsed.corporation,
|
||||
wallet: parsed.wallet,
|
||||
job: jobId,
|
||||
created: undefined,
|
||||
updated: undefined
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -47,7 +58,7 @@ const TransactionForm: React.FC<TransactionFormProps> = ({ jobId, onTransactions
|
||||
}
|
||||
};
|
||||
|
||||
const totalAmount = parsedTransactions.reduce((sum, tx) => sum + Math.abs(tx.totalAmount), 0);
|
||||
const totalAmount = parsedTransactions.reduce((sum, tx) => sum + tx.totalPrice, 0);
|
||||
|
||||
return (
|
||||
<Card className="bg-gray-900 border-gray-700 text-white">
|
||||
@@ -104,7 +115,7 @@ const TransactionForm: React.FC<TransactionFormProps> = ({ jobId, onTransactions
|
||||
{parsedTransactions.map((tx, index) => (
|
||||
<TableRow key={index} className="border-gray-700">
|
||||
<TableCell className="text-gray-300">
|
||||
{tx.date.toLocaleDateString()}
|
||||
{new Date(tx.date).toLocaleDateString()}
|
||||
</TableCell>
|
||||
<TableCell className="text-white">{tx.itemName}</TableCell>
|
||||
<TableCell className="text-gray-300">
|
||||
@@ -114,7 +125,7 @@ const TransactionForm: React.FC<TransactionFormProps> = ({ jobId, onTransactions
|
||||
{formatISK(tx.unitPrice)}
|
||||
</TableCell>
|
||||
<TableCell className={`font-semibold ${transactionType === 'expenditure' ? 'text-red-400' : 'text-green-400'}`}>
|
||||
{formatISK(Math.abs(tx.totalAmount))}
|
||||
{formatISK(tx.totalPrice)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
|
Reference in New Issue
Block a user