added loan remaing pages

This commit is contained in:
@jcarymuhammedow committed 2026-05-05 19:07:59 +05:00
1 parent c612d5bae3
commit c2548280a2
24 files changed
+3182 -307

No files matched your search

@@ -5,7 +5,11 @@ import { useTranslation } from 'react-i18next'
import {
fetchLoanRemaining,
deleteLoanRemaining,
fetchLoanRemainingById,
createLoanRemaining,
updateLoanRemaining,
type LoanRemainingListParams,
type LoanRemainingPayload,
} from '../api/loanRemainingApi'
// ─── Query keys ────────────────────────────────────────────────────────────────
@@ -14,6 +18,8 @@ export const loanRemainingKeys = {
all: ['loanRemaining'] as const,
lists: () => [...loanRemainingKeys.all, 'list'] as const,
list: (params: LoanRemainingListParams) => [...loanRemainingKeys.lists(), params] as const,
details: () => [...loanRemainingKeys.all, 'detail'] as const,
detail: (id: number) => [...loanRemainingKeys.details(), id] as const,
}
// ─── Hooks ─────────────────────────────────────────────────────────────────────
@@ -39,4 +45,45 @@ export function useDeleteLoanRemaining() {
toast.error(t('loanRemaining.deleteError', 'Pozmak başartmady, gaýtadan synanyşyň'))
},
})
}
export function useLoanRemainingById(id?: string) {
return useQuery({
queryKey: loanRemainingKeys.detail(Number(id)),
queryFn: () => fetchLoanRemainingById(Number(id)),
enabled: !!id,
})
}
export function useCreateLoanRemaining() {
const queryClient = useQueryClient()
const { t } = useTranslation()
return useMutation({
mutationFn: (payload: LoanRemainingPayload) => createLoanRemaining(payload),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: loanRemainingKeys.lists() })
toast.success(t('loanRemaining.createSuccess', 'Üstünlikli döredildi'))
},
onError: () => {
toast.error(t('loanRemaining.createError', 'Döretmek başartmady'))
},
})
}
export function useUpdateLoanRemaining(id: number) {
const queryClient = useQueryClient()
const { t } = useTranslation()
return useMutation({
mutationFn: (payload: LoanRemainingPayload) => updateLoanRemaining(id, payload),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: loanRemainingKeys.lists() })
queryClient.invalidateQueries({ queryKey: loanRemainingKeys.detail(id) })
toast.success(t('loanRemaining.updateSuccess', 'Üstünlikli üýtgedildi'))
},
onError: () => {
toast.error(t('loanRemaining.updateError', 'Üýtgetmek başartmady'))
},
})
}