mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 16:08:47 +02:00
Bulk selection UI and import-review modal
Transactions gain a checkbox column with select-all; a bulk bar offers assign-category, defer/restore and delete (confirmed) via the new bulk endpoint, with toasts and invalidation. The paste-import modal now lists each skipped duplicate with the matched existing row and offers 'Importar duplicados de todos modos' — re-importing ONLY the skipped lines so first-pass rows can't double-import (UX-20). Two real fixes found en route: the mobile list ignored undo-pending deletes and used en-US dates; the desktop date column also lost its en-US stray. Note: UX-11 (no mobile layout) was a false positive — a card layout already existed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { useState } from 'react';
|
||||
import { ClipboardPaste, CheckCircle, AlertTriangle } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import api, { type ImportResult } from '@/lib/api';
|
||||
import { formatAmount } from '@/lib/format';
|
||||
import { formatShortDate } from '@/lib/dates';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
@@ -39,8 +43,40 @@ export default function PasteImportModal({ onClose, onImported }: Props) {
|
||||
const { data } = await api.post<ImportResult>('/import/paste', { text, bank, source });
|
||||
setResult(data);
|
||||
if (data.imported > 0) onImported();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} catch {
|
||||
toast.error('No se pudo importar - revisa el formato');
|
||||
} finally {
|
||||
setImporting(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Re-import ONLY the skipped lines with the dedup check disabled, so rows
|
||||
// that imported on the first pass are never duplicated.
|
||||
const handleImportDuplicates = async () => {
|
||||
if (!result || result.skipped.length === 0) return;
|
||||
const lines = text.trim().split('\n');
|
||||
const dupText = result.skipped
|
||||
.map((s) => lines[s.line - 1])
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
setImporting(true);
|
||||
try {
|
||||
const { data } = await api.post<ImportResult>('/import/paste', {
|
||||
text: dupText,
|
||||
bank,
|
||||
source,
|
||||
allow_duplicates: true,
|
||||
});
|
||||
toast.success(`${data.imported} duplicado(s) importados`);
|
||||
setResult({
|
||||
...result,
|
||||
imported: result.imported + data.imported,
|
||||
skipped: [],
|
||||
duplicates: 0,
|
||||
});
|
||||
onImported();
|
||||
} catch {
|
||||
toast.error('No se pudieron importar los duplicados');
|
||||
} finally {
|
||||
setImporting(false);
|
||||
}
|
||||
@@ -134,6 +170,39 @@ export default function PasteImportModal({ onClose, onImported }: Props) {
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{result.skipped.length > 0 && (
|
||||
<div className="rounded-lg border border-amber-500/40 bg-amber-500/5 p-3 space-y-2">
|
||||
<p className="text-sm font-medium">
|
||||
{result.skipped.length} duplicado(s) omitido(s)
|
||||
</p>
|
||||
<ul className="text-xs max-h-40 overflow-y-auto space-y-1.5">
|
||||
{result.skipped.map((s) => (
|
||||
<li key={`${s.line}-${s.existing_id}`} className="space-y-0.5">
|
||||
<span className="font-mono">
|
||||
{s.merchant} · {formatShortDate(s.date)} ·{' '}
|
||||
{formatAmount(s.amount, s.currency)}
|
||||
</span>
|
||||
<span className="block text-muted-foreground">
|
||||
coincide con #{s.existing_id}: {s.existing_merchant} del{' '}
|
||||
{formatShortDate(s.existing_date)} ({s.existing_source})
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full"
|
||||
onClick={handleImportDuplicates}
|
||||
disabled={importing}
|
||||
>
|
||||
{importing
|
||||
? 'Importando...'
|
||||
: 'Importar duplicados de todos modos'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Button onClick={onClose} className="w-full">
|
||||
Done
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user