feat(defter): hafta seçici ve hızlı harcama giriş formu
- /defter: önceki/sonraki/bu hafta, haftanın harcanan/bütçe toplamı - Form: tutar, 4 grup düğmesi, kategori ve ödeme türü seçimi, tarih, açıklama - Son seçimler bu cihazda hatırlanır; sunucu hataları ilgili alana düşer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Günlük defter: harcama kayıtları (sunucu verisi kancaları).
|
||||
*
|
||||
* Kayıt değişince dönemin tüm sorguları yenilenir (`queryKeys.period(id)` öneki):
|
||||
* liste, özet (`spent_total`, `remaining`) ve bütçe (`spent`) birlikte güncellenir.
|
||||
*/
|
||||
import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import type { Entry } from '@/types/Entry'
|
||||
import type { EntryCreateRequest } from '@/types/EntryCreateRequest'
|
||||
import { api } from './api'
|
||||
import { queryKeys } from './query'
|
||||
|
||||
/** Bir tarih aralığının kayıtları (ikisi de dahil); en yeni başta */
|
||||
export function useEntries(periodId: string, range: { from: string; to: string }) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.entries(periodId, range),
|
||||
queryFn: () =>
|
||||
api.get<Entry[]>(`/periods/${periodId}/entries?from=${range.from}&to=${range.to}`),
|
||||
// hafta değiştirirken liste boşalıp titremesin
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateEntry(periodId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (body: EntryCreateRequest) => api.post<Entry>(`/periods/${periodId}/entries`, body),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.period(periodId) }),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user