Taobin-Recipe-Manager/client-electron/src/hooks/recipe-dashboard.ts

55 lines
1.3 KiB
TypeScript
Raw Normal View History

import { type RecipeDashboard } from '@/models/recipe/schema'
import { create } from 'zustand'
2024-02-20 15:01:43 +07:00
import useAxios from './axios'
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', {
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', {
params: filter
? {
country_id: filter.countryID,
filename: filter.filename
}
: undefined
})
.then(res => {
return res.data
})
}
}))
export default useRecipeDashboard