fix: user management & profit chart
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Orders } from '../../types/services/order'
|
||||
import { Order, Orders } from '../../types/services/order'
|
||||
import { api } from '../api'
|
||||
|
||||
interface OrdersQueryParams {
|
||||
@@ -34,3 +34,13 @@ export function useOrders(params: OrdersQueryParams = {}) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function useOrder(id: string) {
|
||||
return useQuery<Order>({
|
||||
queryKey: ['orders', id],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/orders/${id}`)
|
||||
return res.data.data
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,14 +1,36 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Users } from '../../types/services/user'
|
||||
import { api } from '../api'
|
||||
import { User } from '../../types/services/user'
|
||||
|
||||
interface UsersQueryParams {
|
||||
page?: number
|
||||
limit?: number
|
||||
search?: string
|
||||
}
|
||||
|
||||
export function useUsers() {
|
||||
return useQuery<User[]>({
|
||||
queryKey: ['users'],
|
||||
export function useUsers(params: UsersQueryParams = {}) {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
|
||||
return useQuery<Users>({
|
||||
queryKey: ['users', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const res = await api.get('/users')
|
||||
return res.data
|
||||
},
|
||||
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(`/users?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user