4d764689e2
- Excel uyumlu CSV indirme - İçe aktarma: önce deneme raporu (geçerli / zaten var / satır satır hata), onayla geçerli satırlar - Sütunlar adla, esnek tutar/tarih yazımı, ; ve , ayırıcı, Windows-1254 desteği - Varlıkta tarih sırasına göre eldekinden fazla satış denetimi - Ayarlar sayfasında Veri bölümü Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
/**
|
||
* CSV dışa / içe aktarma. İçe aktarma iki adım: deneme (`commit: false`) → onay (`true`).
|
||
* Aktarımdan sonra dönem, rapor ve birikim verileri yenilenir.
|
||
*/
|
||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||
import type { ImportReport } from '@/types/ImportReport'
|
||
import { api } from './api'
|
||
import { queryKeys } from './query'
|
||
|
||
export const TRANSFER_KINDS = ['entries', 'plan-items', 'asset-transactions'] as const
|
||
export type TransferKind = (typeof TRANSFER_KINDS)[number]
|
||
|
||
/** İndirme adresi (çerezle; tarayıcı dosya olarak kaydeder) */
|
||
export const exportUrl = (kind: TransferKind) => `/api/export/${kind}.csv`
|
||
|
||
export function useImport() {
|
||
const qc = useQueryClient()
|
||
return useMutation({
|
||
mutationFn: ({ kind, csv, commit }: { kind: TransferKind; csv: string; commit: boolean }) =>
|
||
api.postCsv<ImportReport>(`/import/${kind}?commit=${commit}`, csv),
|
||
onSuccess: (_, v) => {
|
||
if (!v.commit) return
|
||
void Promise.all([
|
||
qc.invalidateQueries({ queryKey: queryKeys.periods }),
|
||
qc.invalidateQueries({ queryKey: ['period'] }),
|
||
qc.invalidateQueries({ queryKey: queryKeys.portfolio }),
|
||
qc.invalidateQueries({ queryKey: queryKeys.reports }),
|
||
])
|
||
},
|
||
})
|
||
}
|