added some pages
This commit is contained in:
1 parent
c2548280a2
commit
c7797c3e31
61 files changed
+8309
-35
No files matched your search
@@ -0,0 +1,78 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
intlPaymentApi,
|
||||
type IntlPaymentListParams,
|
||||
type IntlPaymentCreatePayload,
|
||||
type IntlPaymentUpdatePayload,
|
||||
} from '../api/visaMasterPaymentsApi'
|
||||
|
||||
export const INTL_PAYMENT_KEYS = {
|
||||
all: ['intl-payments-visa'] as const,
|
||||
lists: () => [...INTL_PAYMENT_KEYS.all, 'list'] as const,
|
||||
list: (p: IntlPaymentListParams) => [...INTL_PAYMENT_KEYS.lists(), p] as const,
|
||||
detail: (id: string) => [...INTL_PAYMENT_KEYS.all, 'detail', id] as const,
|
||||
}
|
||||
|
||||
export function useIntlPayments(params: IntlPaymentListParams) {
|
||||
return useQuery({
|
||||
queryKey: INTL_PAYMENT_KEYS.list(params),
|
||||
queryFn: () => intlPaymentApi.list(params),
|
||||
placeholderData: (prev) => prev,
|
||||
})
|
||||
}
|
||||
|
||||
export function useIntlPayment(id: string) {
|
||||
return useQuery({
|
||||
queryKey: INTL_PAYMENT_KEYS.detail(id),
|
||||
queryFn: () => intlPaymentApi.getById(id),
|
||||
enabled: !!id,
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateIntlPayment() {
|
||||
const qc = useQueryClient()
|
||||
const { t } = useTranslation()
|
||||
return useMutation({
|
||||
mutationFn: (payload: IntlPaymentCreatePayload) => intlPaymentApi.create(payload),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: INTL_PAYMENT_KEYS.lists() })
|
||||
toast.success(t('intlPayment.createSuccess', 'Töleg döredildi'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('intlPayment.createError', 'Döretmek başartmady'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateIntlPayment(id: string) {
|
||||
const qc = useQueryClient()
|
||||
const { t } = useTranslation()
|
||||
return useMutation({
|
||||
mutationFn: (payload: IntlPaymentUpdatePayload) => intlPaymentApi.update(id, payload),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: INTL_PAYMENT_KEYS.lists() })
|
||||
qc.invalidateQueries({ queryKey: INTL_PAYMENT_KEYS.detail(id) })
|
||||
toast.success(t('intlPayment.updateSuccess', 'Töleg üýtgedildi'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('intlPayment.updateError', 'Üýtgetmek başartmady'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteIntlPayment() {
|
||||
const qc = useQueryClient()
|
||||
const { t } = useTranslation()
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => intlPaymentApi.delete(id),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: INTL_PAYMENT_KEYS.lists() })
|
||||
toast.success(t('intlPayment.deleteSuccess', 'Töleg pozuldy'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('intlPayment.deleteError', 'Pozmak başartmady'))
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user