fix: eslint error
This commit is contained in:
@@ -1,37 +1,34 @@
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { api } from '../api'
|
||||
import { redirect } from 'next/navigation'
|
||||
|
||||
type LoginPayload = {
|
||||
email: string
|
||||
password: string
|
||||
}
|
||||
|
||||
export const useAuthMutation = {
|
||||
login: () => {
|
||||
return useMutation({
|
||||
mutationFn: async (payload: LoginPayload) => {
|
||||
const response = await api.post('/auth/login', payload)
|
||||
return response.data.data
|
||||
},
|
||||
onSuccess: data => {
|
||||
// Optional: refetch 'users' list after success
|
||||
localStorage.setItem('authToken', data.token)
|
||||
localStorage.setItem('user', JSON.stringify(data.user))
|
||||
}
|
||||
})
|
||||
},
|
||||
export const useAuthMutation = () => {
|
||||
const login = useMutation({
|
||||
mutationFn: async (payload: LoginPayload) => {
|
||||
const response = await api.post('/auth/login', payload)
|
||||
return response.data.data
|
||||
},
|
||||
onSuccess: data => {
|
||||
// Optional: refetch 'users' list after success
|
||||
localStorage.setItem('authToken', data.token)
|
||||
localStorage.setItem('user', JSON.stringify(data.user))
|
||||
}
|
||||
})
|
||||
|
||||
logout: () => {
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
await api.post('/auth/logout')
|
||||
},
|
||||
onSuccess: () => {
|
||||
// Optional: refetch 'users' list after success
|
||||
localStorage.removeItem('authToken')
|
||||
localStorage.removeItem('user')
|
||||
}
|
||||
})
|
||||
}
|
||||
const logout = useMutation({
|
||||
mutationFn: async () => {
|
||||
await api.post('/auth/logout')
|
||||
},
|
||||
onSuccess: () => {
|
||||
// Optional: refetch 'users' list after success
|
||||
localStorage.removeItem('authToken')
|
||||
localStorage.removeItem('user')
|
||||
}
|
||||
})
|
||||
|
||||
return { login, logout }
|
||||
}
|
||||
|
||||
@@ -3,58 +3,50 @@ import { api } from '../api'
|
||||
import { toast } from 'react-toastify'
|
||||
import { CategoryRequest } from '../../types/services/category'
|
||||
|
||||
export const useCategoriesMutation = {
|
||||
createCategory: () => {
|
||||
const queryClient = useQueryClient()
|
||||
export const useCategoriesMutation = () => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (newCategory: CategoryRequest) => {
|
||||
const response = await api.post('/categories', newCategory)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Category created successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['categories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
},
|
||||
const createCategory = useMutation({
|
||||
mutationFn: async (newCategory: CategoryRequest) => {
|
||||
const response = await api.post('/categories', newCategory)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Category created successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['categories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
|
||||
updateCategory: () => {
|
||||
const queryClient = useQueryClient()
|
||||
const updateCategory = useMutation({
|
||||
mutationFn: async ({ id, payload }: { id: string; payload: CategoryRequest }) => {
|
||||
const response = await api.put(`/categories/${id}`, payload)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Category updated successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['categories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Update failed')
|
||||
}
|
||||
})
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ id, payload }: { id: string; payload: CategoryRequest }) => {
|
||||
const response = await api.put(`/categories/${id}`, payload)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Category updated successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['categories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Update failed')
|
||||
}
|
||||
})
|
||||
},
|
||||
const deleteCategory = useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
const response = await api.delete(`/categories/${id}`)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Category deleted successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['categories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Delete failed')
|
||||
}
|
||||
})
|
||||
|
||||
deleteCategory: () => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
const response = await api.delete(`/categories/${id}`)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Category deleted successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['categories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Delete failed')
|
||||
}
|
||||
})
|
||||
}
|
||||
return { createCategory, updateCategory, deleteCategory }
|
||||
}
|
||||
|
||||
@@ -2,24 +2,24 @@ import { useMutation } from '@tanstack/react-query'
|
||||
import { api } from '../api'
|
||||
import { toast } from 'react-toastify'
|
||||
|
||||
export const useFilesMutation = {
|
||||
uploadFile: () => {
|
||||
return useMutation({
|
||||
mutationFn: async (newFile: FormData) => {
|
||||
const response = await api.post('/files/upload', newFile, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
})
|
||||
export const useFilesMutation = () => {
|
||||
const uploadFile = useMutation({
|
||||
mutationFn: async (newFile: FormData) => {
|
||||
const response = await api.post('/files/upload', newFile, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
})
|
||||
|
||||
return response.data.data
|
||||
},
|
||||
onSuccess: data => {
|
||||
toast.success('File uploaded successfully!')
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response.data.errors[0].cause)
|
||||
}
|
||||
})
|
||||
}
|
||||
return response.data.data
|
||||
},
|
||||
onSuccess: data => {
|
||||
toast.success('File uploaded successfully!')
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response.data.errors[0].cause)
|
||||
}
|
||||
})
|
||||
|
||||
return { uploadFile }
|
||||
}
|
||||
|
||||
@@ -3,58 +3,50 @@ import { api } from '../api'
|
||||
import { toast } from 'react-toastify'
|
||||
import { InventoryAdjustRequest, InventoryRequest } from '../../types/services/inventory'
|
||||
|
||||
export const useInventoriesMutation = {
|
||||
createInventory: () => {
|
||||
const queryClient = useQueryClient()
|
||||
export const useInventoriesMutation = () => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (newInventory: InventoryRequest) => {
|
||||
const response = await api.post('/inventory', newInventory)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Inventory created successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['inventories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
},
|
||||
const createInventory = useMutation({
|
||||
mutationFn: async (newInventory: InventoryRequest) => {
|
||||
const response = await api.post('/inventory', newInventory)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Inventory created successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['inventories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
|
||||
adjustInventory: () => {
|
||||
const queryClient = useQueryClient()
|
||||
const adjustInventory = useMutation({
|
||||
mutationFn: async (newInventory: InventoryAdjustRequest) => {
|
||||
const response = await api.post('/inventory/adjust', newInventory)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Inventory adjusted successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['inventories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (newInventory: InventoryAdjustRequest) => {
|
||||
const response = await api.post('/inventory/adjust', newInventory)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Inventory adjusted successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['inventories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
},
|
||||
const deleteInventory = useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
const response = await api.delete(`/inventory/${id}`)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Inventory deleted successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['inventories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Delete failed')
|
||||
}
|
||||
})
|
||||
|
||||
deleteInventory: () => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
const response = await api.delete(`/inventory/${id}`)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Inventory deleted successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['inventories'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Delete failed')
|
||||
}
|
||||
})
|
||||
}
|
||||
return { createInventory, adjustInventory, deleteInventory }
|
||||
}
|
||||
|
||||
@@ -3,52 +3,48 @@ import { api } from '../api'
|
||||
import { toast } from 'react-toastify'
|
||||
import { ProductRequest } from '../../types/services/product'
|
||||
|
||||
export const useProductsMutation = {
|
||||
createProduct: () => {
|
||||
return useMutation({
|
||||
mutationFn: async (newProduct: ProductRequest) => {
|
||||
const response = await api.post('/products', newProduct)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Product created successfully!')
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
},
|
||||
export const useProductsMutation = () => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
updateProduct: () => {
|
||||
return useMutation({
|
||||
mutationFn: async ({ id, payload }: { id: string; payload: ProductRequest }) => {
|
||||
const response = await api.put(`/products/${id}`, payload)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Product updated successfully!')
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Update failed')
|
||||
}
|
||||
})
|
||||
},
|
||||
const createProduct = useMutation({
|
||||
mutationFn: async (newProduct: ProductRequest) => {
|
||||
const response = await api.post('/products', newProduct)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Product created successfully!')
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
|
||||
deleteProduct: () => {
|
||||
const queryClient = useQueryClient()
|
||||
const updateProduct = useMutation({
|
||||
mutationFn: async ({ id, payload }: { id: string; payload: ProductRequest }) => {
|
||||
const response = await api.put(`/products/${id}`, payload)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Product updated successfully!')
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Update failed')
|
||||
}
|
||||
})
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
const response = await api.delete(`/products/${id}`)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Product deleted successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['products'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Delete failed')
|
||||
}
|
||||
})
|
||||
}
|
||||
const deleteProduct = useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
const response = await api.delete(`/products/${id}`)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Product deleted successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['products'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Delete failed')
|
||||
}
|
||||
})
|
||||
|
||||
return { createProduct, updateProduct, deleteProduct }
|
||||
}
|
||||
|
||||
@@ -3,58 +3,50 @@ import { toast } from 'react-toastify'
|
||||
import { UnitRequest } from '../../types/services/unit'
|
||||
import { api } from '../api'
|
||||
|
||||
export const useUnitsMutation = {
|
||||
createUnit: () => {
|
||||
const queryClient = useQueryClient()
|
||||
export const useUnitsMutation = () => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (newUnit: UnitRequest) => {
|
||||
const response = await api.post('/units', newUnit)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Unit created successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['units'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
},
|
||||
const createUnit = useMutation({
|
||||
mutationFn: async (newUnit: UnitRequest) => {
|
||||
const response = await api.post('/units', newUnit)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Unit created successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['units'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Create failed')
|
||||
}
|
||||
})
|
||||
|
||||
updateUnit: () => {
|
||||
const queryClient = useQueryClient()
|
||||
const updateUnit = useMutation({
|
||||
mutationFn: async ({ id, payload }: { id: string; payload: UnitRequest }) => {
|
||||
const response = await api.put(`/units/${id}`, payload)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Unit updated successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['units'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Update failed')
|
||||
}
|
||||
})
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ id, payload }: { id: string; payload: UnitRequest }) => {
|
||||
const response = await api.put(`/units/${id}`, payload)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Unit updated successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['units'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Update failed')
|
||||
}
|
||||
})
|
||||
},
|
||||
const deleteUnit = useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
const response = await api.delete(`/units/${id}`)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Unit deleted successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['units'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Delete failed')
|
||||
}
|
||||
})
|
||||
|
||||
deleteUnit: () => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
const response = await api.delete(`/units/${id}`)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Unit deleted successfully!')
|
||||
queryClient.invalidateQueries({ queryKey: ['units'] })
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error.response?.data?.errors?.[0]?.cause || 'Delete failed')
|
||||
}
|
||||
})
|
||||
}
|
||||
return { createUnit, updateUnit, deleteUnit }
|
||||
}
|
||||
|
||||
@@ -7,21 +7,21 @@ type CreateUserPayload = {
|
||||
email: string
|
||||
}
|
||||
|
||||
const useUsersMutation = {
|
||||
createUser: () => {
|
||||
const queryClient = useQueryClient()
|
||||
const useUsersMutation = () => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const createUser = useMutation<User, Error, CreateUserPayload>({
|
||||
mutationFn: async newUser => {
|
||||
const response = await api.post('/users', newUser)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
// Optional: refetch 'users' list after success
|
||||
queryClient.invalidateQueries({ queryKey: ['users'] })
|
||||
}
|
||||
})
|
||||
|
||||
return useMutation<User, Error, CreateUserPayload>({
|
||||
mutationFn: async newUser => {
|
||||
const response = await api.post('/users', newUser)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
// Optional: refetch 'users' list after success
|
||||
queryClient.invalidateQueries({ queryKey: ['users'] })
|
||||
}
|
||||
})
|
||||
}
|
||||
return { createUser }
|
||||
}
|
||||
|
||||
export default useUsersMutation
|
||||
|
||||
@@ -8,32 +8,29 @@ interface CategoriesQueryParams {
|
||||
search?: string
|
||||
}
|
||||
|
||||
export const useCategoriesQuery = {
|
||||
getCategories: (params: CategoriesQueryParams = {}) => {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
export function useCategories(params: CategoriesQueryParams = {}) {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
|
||||
return useQuery<Categories>({
|
||||
queryKey: ['categories', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
return useQuery<Categories>({
|
||||
queryKey: ['categories', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
}
|
||||
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
|
||||
// Add other filters
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
|
||||
const res = await api.get(`/categories?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
},
|
||||
})
|
||||
}
|
||||
const res = await api.get(`/categories?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,32 +8,29 @@ interface InventoriesQueryParams {
|
||||
search?: string
|
||||
}
|
||||
|
||||
export const useInventoriesQuery = {
|
||||
getInventories: (params: InventoriesQueryParams = {}) => {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
export function useInventories(params: InventoriesQueryParams = {}) {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
|
||||
return useQuery<Inventories>({
|
||||
queryKey: ['inventories', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
return useQuery<Inventories>({
|
||||
queryKey: ['inventories', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
}
|
||||
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
|
||||
// Add other filters
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
|
||||
const res = await api.get(`/inventory?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
},
|
||||
})
|
||||
}
|
||||
const res = await api.get(`/inventory?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
import { Orders } from "../../types/services/order"
|
||||
import { api } from "../api"
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Orders } from '../../types/services/order'
|
||||
import { api } from '../api'
|
||||
|
||||
interface OrdersQueryParams {
|
||||
page?: number
|
||||
@@ -8,32 +8,29 @@ interface OrdersQueryParams {
|
||||
search?: string
|
||||
}
|
||||
|
||||
export const useOrdersQuery = {
|
||||
getOrders: (params: OrdersQueryParams = {}) => {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
export function useOrders(params: OrdersQueryParams = {}) {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
|
||||
return useQuery<Orders>({
|
||||
queryKey: ['orders', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
return useQuery<Orders>({
|
||||
queryKey: ['orders', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
}
|
||||
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
|
||||
// Add other filters
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
|
||||
const res = await api.get(`/orders?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
},
|
||||
})
|
||||
}
|
||||
const res = await api.get(`/orders?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,32 +8,29 @@ interface OutletsQueryParams {
|
||||
search?: string
|
||||
}
|
||||
|
||||
export const useOutletsQuery = {
|
||||
getOutlets: (params: OutletsQueryParams = {}) => {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
export function useOutlets(params: OutletsQueryParams = {}) {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
|
||||
return useQuery<Outlets>({
|
||||
queryKey: ['outlets', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
return useQuery<Outlets>({
|
||||
queryKey: ['outlets', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
}
|
||||
|
||||
// Add other filters
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
|
||||
const res = await api.get(`/outlets/list?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
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(`/outlets/list?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,45 +11,40 @@ interface ProductsQueryParams {
|
||||
is_active?: boolean
|
||||
}
|
||||
|
||||
export const useProductsQuery = {
|
||||
getProducts: (params: ProductsQueryParams = {}) => {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
export function useProducts(params: ProductsQueryParams = {}) {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
|
||||
return useQuery<Products>({
|
||||
queryKey: ['products', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
return useQuery<Products>({
|
||||
queryKey: ['products', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
}
|
||||
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
|
||||
// Add other filters
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
const res = await api.get(`/products?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const res = await api.get(`/products?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
getProductById: (id: string) => {
|
||||
return useQuery({
|
||||
queryKey: ['product', id],
|
||||
queryFn: async ({ queryKey: [, id] }) => {
|
||||
const res = await api.get(`/products/${id}`)
|
||||
return res.data.data
|
||||
},
|
||||
|
||||
// Cache for 5 minutes
|
||||
staleTime: 5 * 60 * 1000
|
||||
})
|
||||
}
|
||||
export function useProductById(id: string) {
|
||||
return useQuery({
|
||||
queryKey: ['product', id],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/products/${id}`)
|
||||
return res.data.data
|
||||
},
|
||||
staleTime: 5 * 60 * 1000
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,32 +8,29 @@ interface UnitsQueryParams {
|
||||
search?: string
|
||||
}
|
||||
|
||||
export const useUnitsQuery = {
|
||||
getUnits: (params: UnitsQueryParams = {}) => {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
export function useUnits(params: UnitsQueryParams = {}) {
|
||||
const { page = 1, limit = 10, search = '', ...filters } = params
|
||||
|
||||
return useQuery<Units>({
|
||||
queryKey: ['units', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
return useQuery<Units>({
|
||||
queryKey: ['units', { page, limit, search, ...filters }],
|
||||
queryFn: async () => {
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
queryParams.append('page', page.toString())
|
||||
queryParams.append('limit', limit.toString())
|
||||
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
if (search) {
|
||||
queryParams.append('search', search)
|
||||
}
|
||||
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
|
||||
// Add other filters
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.append(key, value.toString())
|
||||
}
|
||||
})
|
||||
|
||||
const res = await api.get(`/units?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
},
|
||||
})
|
||||
}
|
||||
const res = await api.get(`/units?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,16 +2,13 @@ import { useQuery } from '@tanstack/react-query'
|
||||
import { api } from '../api'
|
||||
import { User } from '../../types/services/user'
|
||||
|
||||
const useUsersQuery = {
|
||||
getUsers: () => {
|
||||
return useQuery<User[]>({
|
||||
queryKey: ['users'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get('/users')
|
||||
return res.data
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default useUsersQuery
|
||||
export function useUsers() {
|
||||
return useQuery<User[]>({
|
||||
queryKey: ['users'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get('/users')
|
||||
return res.data
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user