fix: SIE import duplicate check, performance, and UX improvements (#162)

* fix: catch duplicate SIE import early with clear error message

- Add duplicate check in execute route before doing any work (defense in depth)
- Handle duplicate error from execute route in frontend
- Show "Filen har redan importerats" heading instead of generic "Kunde inte läsa filen"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: catch duplicate SIE import early and batch account creation for performance

- Add duplicate check in execute route before doing any work (defense in depth)
- Handle duplicate error from execute route in frontend with clear Swedish message
- Replace sequential ensureAccountExists loop (50-100 DB round trips) with single
  batch SELECT + batch INSERT — reduces import time from 3+ min to seconds

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: update mappings optimistically after creating missing accounts

Previously re-parsed the SIE file after account creation, which could fail
with a 409 duplicate error (leaving the "create accounts" card stuck).
Now optimistically marks created accounts as self-mapped and updates the
preview stats immediately.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address Greptile P2 feedback — error handling and typed errorType prop

- Check batch insert error in executeSIEImport account creation safety net
- Replace brittle string-match error detection with typed errorType prop
- Remove stale file dependency from handleCreateAccounts useCallback

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-04-02 11:21:51 +02:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 9dceb6285c
commit d23cb4c859
4 changed files with 119 additions and 36 deletions
+7 -2
View File
@@ -16,9 +16,10 @@ interface SIEUploadStepProps {
onFileSelect: (file: File) => void
isLoading: boolean
error: string | null
errorType?: 'duplicate' | 'duplicate_period' | 'validation' | 'parse'
}
export default function SIEUploadStep({ onFileSelect, isLoading, error }: SIEUploadStepProps) {
export default function SIEUploadStep({ onFileSelect, isLoading, error, errorType }: SIEUploadStepProps) {
const [isDragging, setIsDragging] = useState(false)
const [selectedFile, setSelectedFile] = useState<File | null>(null)
const [loadingPhase, setLoadingPhase] = useState(0)
@@ -161,7 +162,11 @@ export default function SIEUploadStep({ onFileSelect, isLoading, error }: SIEUpl
<div className="mt-4 p-4 bg-destructive/10 border border-destructive/20 rounded-lg flex gap-3">
<AlertCircle className="h-5 w-5 text-destructive flex-shrink-0 mt-0.5" />
<div>
<p className="font-medium text-destructive">Kunde inte läsa filen</p>
<p className="font-medium text-destructive">
{errorType === 'duplicate' || errorType === 'duplicate_period'
? 'Filen har redan importerats'
: 'Kunde inte läsa filen'}
</p>
<p className="text-sm text-muted-foreground">{error}</p>
</div>
</div>