Merge remote-tracking branch 'origin/main' into efril

This commit is contained in:
efrilm
2025-08-13 15:05:14 +07:00
42 changed files with 2666 additions and 524 deletions
+36
View File
@@ -0,0 +1,36 @@
import { useQuery } from '@tanstack/react-query'
import { Organizations } from '../../types/services/organization'
import { api } from '../api'
interface OrganizationsQueryParams {
page?: number
limit?: number
search?: string
}
export function useOrganizations(params: OrganizationsQueryParams = {}) {
const { page = 1, limit = 10, search = '', ...filters } = params
return useQuery<Organizations>({
queryKey: ['organizations', { 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(`/organizations?${queryParams.toString()}`)
return res.data.data
}
})
}
+13
View File
@@ -0,0 +1,13 @@
import { useQuery } from '@tanstack/react-query'
import { ProductRecipe } from '../../types/services/productRecipe'
import { api } from '../api'
export function useProductRecipesByProduct(productId: string) {
return useQuery<ProductRecipe[]>({
queryKey: ['product-recipes', productId],
queryFn: async () => {
const res = await api.get(`/product-recipes/product/${productId}`)
return res.data.data
}
})
}
+3 -2
View File
@@ -1,6 +1,7 @@
import { useQuery } from '@tanstack/react-query'
import { Products } from '../../types/services/product'
import { Product, Products } from '../../types/services/product'
import { api } from '../api'
import { ProductRecipe } from '../../types/services/productRecipe'
interface ProductsQueryParams {
page?: number
@@ -39,7 +40,7 @@ export function useProducts(params: ProductsQueryParams = {}) {
}
export function useProductById(id: string) {
return useQuery({
return useQuery<Product>({
queryKey: ['product', id],
queryFn: async () => {
const res = await api.get(`/products/${id}`)