Vendor Api

This commit is contained in:
efrilm
2025-09-12 03:11:01 +07:00
parent a019a4bdbc
commit 0e8216b0c9
4 changed files with 179 additions and 122 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ const getToken = () => {
}
export const api = axios.create({
baseURL: 'https://api-pos.apskel.id/api/v1',
baseURL: 'http://127.0.0.1:4000/api/v1',
headers: {
'Content-Type': 'application/json'
},
+36
View File
@@ -0,0 +1,36 @@
import { useQuery } from '@tanstack/react-query'
import { api } from '../api'
import { Vendors } from '@/types/services/vendor'
interface VendorQueryParams {
page?: number
limit?: number
search?: string
}
export function useVendors(params: VendorQueryParams = {}) {
const { page = 1, limit = 10, search = '', ...filters } = params
return useQuery<Vendors>({
queryKey: ['vendors', { page, limit, search, ...filters }],
queryFn: async () => {
const queryParams = new URLSearchParams()
queryParams.append('page', page.toString())
queryParams.append('limit', limit.toString())
if (search) {
queryParams.append('search', search)
}
Object.entries(filters).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
queryParams.append(key, value.toString())
}
})
const res = await api.get(`/vendors?${queryParams.toString()}`)
return res.data.data
}
})
}