add recipe viewer

This commit is contained in:
Kenta420 2024-02-21 15:17:54 +07:00
parent 92b11f7b9d
commit f7f1535695
31 changed files with 1532 additions and 151 deletions

View file

@ -1,6 +1,6 @@
import { type RecipeDashboard } from '@/models/recipe/schema'
import { create } from 'zustand'
import useAxios from './axios'
import taoAxios from '@/lib/taoAxios'
export interface RecipeDashboardFilterQuery {
countryID: string
@ -13,15 +13,21 @@ interface materialDashboard {
}
interface RecipeDashboardHook {
selectedRecipe: string
setSelectedRecipe: (recipe: string) => void
getRecipesDashboard: (filter?: RecipeDashboardFilterQuery) => Promise<RecipeDashboard[] | []>
getMaterials: (filter?: RecipeDashboardFilterQuery) => Promise<materialDashboard[] | []>
getRecipe: (productCode: string) => Promise<RecipeDashboard | null>
}
const useRecipeDashboard = create<RecipeDashboardHook>(() => ({
selectedRecipe: '',
setSelectedRecipe: id => {
useRecipeDashboard.setState({ selectedRecipe: id })
},
async getRecipesDashboard(filter) {
return useAxios
.getState()
.axios.get<RecipeDashboard[]>('/v2/recipes/dashboard', {
return taoAxios
.get<RecipeDashboard[]>('/v2/recipes/dashboard', {
params: filter
? {
country_id: filter.countryID,
@ -35,9 +41,8 @@ const useRecipeDashboard = create<RecipeDashboardHook>(() => ({
.catch(() => [])
},
async getMaterials(filter) {
return useAxios
.getState()
.axios.get<materialDashboard[]>('/v2/materials/dashboard', {
return taoAxios
.get<materialDashboard[]>('/v2/materials/dashboard', {
params: filter
? {
country_id: filter.countryID,
@ -48,6 +53,14 @@ const useRecipeDashboard = create<RecipeDashboardHook>(() => ({
.then(res => {
return res.data
})
},
async getRecipe(productCode) {
return taoAxios
.get<RecipeDashboard>(`/v2/recipes/${productCode}`)
.then(res => {
return res.data
})
.catch(() => null)
}
}))