Fix UI and functionality issues
Fixes tax config button size, recalculates min prices on tax change, saves tax on blur, and implements automatic pasting to batch assign.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Calendar, Factory, Clock, Copy } from 'lucide-react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { IndJob } from '@/lib/types';
|
||||
@@ -164,9 +164,16 @@ interface MinPriceDisplayProps {
|
||||
|
||||
const MinPriceDisplay: React.FC<MinPriceDisplayProps> = ({ job }) => {
|
||||
const { copying, copyToClipboard } = useClipboard();
|
||||
const [salesTax, setSalesTax] = useState(() => parseFloat(localStorage.getItem('salesTax') || '0') / 100);
|
||||
|
||||
// Get sales tax from localStorage (default 0%)
|
||||
const salesTax = parseFloat(localStorage.getItem('salesTax') || '0') / 100;
|
||||
// Listen for storage changes to update tax rate
|
||||
useEffect(() => {
|
||||
const handleStorageChange = () => {
|
||||
setSalesTax(parseFloat(localStorage.getItem('salesTax') || '0') / 100);
|
||||
};
|
||||
window.addEventListener('storage', handleStorageChange);
|
||||
return () => window.removeEventListener('storage', handleStorageChange);
|
||||
}, []);
|
||||
|
||||
const minPricePerUnit = job.projectedRevenue / job.produced;
|
||||
const minPriceWithTax = minPricePerUnit * (1 + salesTax);
|
||||
|
@@ -262,7 +262,27 @@ const Index = () => {
|
||||
<SalesTaxConfig />
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setShowBatchForm(true)}
|
||||
onClick={async () => {
|
||||
try {
|
||||
const text = await navigator.clipboard.readText();
|
||||
if (text.trim()) {
|
||||
setShowBatchForm(true);
|
||||
// Pass clipboard data to form
|
||||
setTimeout(() => {
|
||||
const textarea = document.querySelector('textarea[placeholder*="Paste your EVE transaction data"]') as HTMLTextAreaElement;
|
||||
if (textarea) {
|
||||
textarea.value = text;
|
||||
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
}
|
||||
}, 100);
|
||||
} else {
|
||||
setShowBatchForm(true);
|
||||
}
|
||||
} catch (err) {
|
||||
// Clipboard reading failed, just open the form
|
||||
setShowBatchForm(true);
|
||||
}
|
||||
}}
|
||||
className="border-gray-600 hover:bg-gray-800"
|
||||
>
|
||||
<FileText className="w-4 h-4 mr-2" />
|
||||
@@ -346,7 +366,6 @@ const SalesTaxConfig = () => {
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="border-gray-600 hover:bg-gray-800"
|
||||
>
|
||||
<Settings className="w-4 h-4 mr-2" />
|
||||
@@ -364,6 +383,12 @@ const SalesTaxConfig = () => {
|
||||
type="number"
|
||||
value={salesTax}
|
||||
onChange={(e) => setSalesTax(e.target.value)}
|
||||
onBlur={handleSave}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleSave();
|
||||
}
|
||||
}}
|
||||
placeholder="0"
|
||||
min="0"
|
||||
max="100"
|
||||
@@ -374,23 +399,6 @@ const SalesTaxConfig = () => {
|
||||
Applied to minimum price calculations
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setIsOpen(false)}
|
||||
className="border-gray-600 hover:bg-gray-800"
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={handleSave}
|
||||
className="bg-blue-600 hover:bg-blue-700"
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
Reference in New Issue
Block a user