WInners Voucher

This commit is contained in:
Aditya Siregar 2025-09-13 16:06:49 +07:00
parent 5de78cb78f
commit fb6e2571a5
3 changed files with 677 additions and 458 deletions

File diff suppressed because it is too large Load Diff

View 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
}

View 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
}