Merge pull request 'efril' (#1) from efril into main
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
import { Outlets } from "../../types/services/outlet"
|
||||
import { api } from "../api"
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Outlet, Outlets } from '../../types/services/outlet'
|
||||
import { api } from '../api'
|
||||
|
||||
interface OutletsQueryParams {
|
||||
page?: number
|
||||
@@ -31,6 +31,28 @@ export function useOutlets(params: OutletsQueryParams = {}) {
|
||||
|
||||
const res = await api.get(`/outlets/list?${queryParams.toString()}`)
|
||||
return res.data.data
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function useOutletById() {
|
||||
const user = (() => {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem('user') || '{}')
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
})()
|
||||
|
||||
const outletId = user?.outlet_id // atau sesuai struktur data user
|
||||
|
||||
return useQuery<Outlet>({
|
||||
queryKey: ['outlet', outletId],
|
||||
queryFn: async () => {
|
||||
if (!outletId) throw new Error('Outlet ID not found in localStorage')
|
||||
const res = await api.get(`/outlets/detail/${outletId}`)
|
||||
return res.data.data
|
||||
},
|
||||
enabled: !!outletId // query hanya jalan kalau ada outletId
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user