WInners Voucher
This commit is contained in:
parent
5de78cb78f
commit
fb6e2571a5
File diff suppressed because it is too large
Load Diff
31
src/services/queries/vouchers.ts
Normal file
31
src/services/queries/vouchers.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query'
|
||||||
|
import { VoucherRowsResponse } from '../../types/services/voucher'
|
||||||
|
import { api } from '../api'
|
||||||
|
|
||||||
|
export interface VouchersQueryParams {
|
||||||
|
rows?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useVoucherRows(params: VouchersQueryParams = {}) {
|
||||||
|
const { rows = 4 } = params
|
||||||
|
|
||||||
|
return useQuery<VoucherRowsResponse>({
|
||||||
|
queryKey: ['voucher-rows', { rows }],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await api.get(`/vouchers/rows`, {
|
||||||
|
params: { rows }
|
||||||
|
})
|
||||||
|
return res.data.data
|
||||||
|
},
|
||||||
|
staleTime: 5 * 60 * 1000,
|
||||||
|
refetchOnWindowFocus: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Manual fetch function for cases where you need to fetch without using the hook
|
||||||
|
export async function fetchVoucherRows(rows: number = 4): Promise<VoucherRowsResponse> {
|
||||||
|
const res = await api.get(`/vouchers/rows`, {
|
||||||
|
params: { rows }
|
||||||
|
})
|
||||||
|
return res.data.data
|
||||||
|
}
|
||||||
23
src/types/services/voucher.ts
Normal file
23
src/types/services/voucher.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
export interface Voucher {
|
||||||
|
voucher_code: string
|
||||||
|
name: string
|
||||||
|
phone_number: string
|
||||||
|
is_winner: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VoucherRow {
|
||||||
|
row_number: number
|
||||||
|
vouchers: Voucher[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VoucherRowsResponse {
|
||||||
|
rows: VoucherRow[]
|
||||||
|
total_rows: number
|
||||||
|
total_vouchers: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VoucherApiResponse {
|
||||||
|
success: boolean
|
||||||
|
data: VoucherRowsResponse
|
||||||
|
errors: any
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user