2024-02-19 14:24:05 +07:00
|
|
|
import { type RecipeDashboard } from '@/models/recipe/schema'
|
|
|
|
|
import { create } from 'zustand'
|
2024-02-20 15:01:43 +07:00
|
|
|
import useAxios from './axios'
|
2024-02-19 14:24:05 +07:00
|
|
|
|
|
|
|
|
export interface RecipeDashboardFilterQuery {
|
|
|
|
|
countryID: string
|
|
|
|
|
filename: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface materialDashboard {
|
|
|
|
|
lebel: string
|
|
|
|
|
value: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface RecipeDashboardHook {
|
|
|
|
|
getRecipesDashboard: (filter?: RecipeDashboardFilterQuery) => Promise<RecipeDashboard[] | []>
|
|
|
|
|
getMaterials: (filter?: RecipeDashboardFilterQuery) => Promise<materialDashboard[] | []>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const useRecipeDashboard = create<RecipeDashboardHook>(() => ({
|
|
|
|
|
async getRecipesDashboard(filter) {
|
2024-02-20 15:01:43 +07:00
|
|
|
return useAxios
|
|
|
|
|
.getState()
|
|
|
|
|
.axios.get<RecipeDashboard[]>('/v2/recipes/dashboard', {
|
2024-02-19 14:24:05 +07:00
|
|
|
params: filter
|
|
|
|
|
? {
|
|
|
|
|
country_id: filter.countryID,
|
|
|
|
|
filename: filter.filename
|
|
|
|
|
}
|
|
|
|
|
: undefined
|
|
|
|
|
})
|
|
|
|
|
.then(res => {
|
|
|
|
|
return res.data
|
|
|
|
|
})
|
|
|
|
|
.catch(() => [])
|
|
|
|
|
},
|
|
|
|
|
async getMaterials(filter) {
|
2024-02-20 15:01:43 +07:00
|
|
|
return useAxios
|
|
|
|
|
.getState()
|
|
|
|
|
.axios.get<materialDashboard[]>('/v2/materials/dashboard', {
|
2024-02-19 14:24:05 +07:00
|
|
|
params: filter
|
|
|
|
|
? {
|
|
|
|
|
country_id: filter.countryID,
|
|
|
|
|
filename: filter.filename
|
|
|
|
|
}
|
|
|
|
|
: undefined
|
|
|
|
|
})
|
|
|
|
|
.then(res => {
|
|
|
|
|
return res.data
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
export default useRecipeDashboard
|