|
1
|
import { LoaderFunctionArgs } from "react-router-dom" |
|
2
|
|
|
3
|
import { stockLocationsQueryKeys } from "../../../hooks/api/stock-locations" |
|
4
|
import { sdk } from "../../../lib/client" |
|
5
|
import { queryClient } from "../../../lib/query-client" |
|
6
|
import { LOCATION_DETAILS_FIELD } from "./constants" |
|
7
|
|
|
8
|
const locationQuery = (id: string) => ({ |
|
9
|
queryKey: stockLocationsQueryKeys.detail(id, { |
|
10
|
fields: LOCATION_DETAILS_FIELD, |
|
11
|
}), |
|
12
|
queryFn: async () => |
|
13
|
sdk.admin.stockLocation.retrieve(id, { |
|
14
|
fields: LOCATION_DETAILS_FIELD, |
|
15
|
}), |
|
16
|
}) |
|
17
|
|
|
18
|
export const locationLoader = async ({ params }: LoaderFunctionArgs) => { |
|
19
|
const id = params.location_id |
|
20
|
const query = locationQuery(id!) |
|
21
|
|
|
22
|
return queryClient.ensureQueryData(query) |
|
23
|
} |