feat(admin-next, inventory-next, medusa, types): Add admin reservations flow (#7080)
* add reservation endpoints * add changeset * initial * add reservations table * add edit-item modal * udpate inventory item attributes * manage locations skeleton * add combi batch endpoint * cleanup * fix manage locations * add adjust inventory * prep for pr * minor fixes to region domain and api (#7042) * initial reservation * init * update reservation * create reservation * polishing * minor fix * prep for pr * prep for pr * polishing * inventory items reservations * Update packages/admin-next/dashboard/src/v2-routes/reservations/reservation-list/components/reservation-list-table/reservation-list-table.tsx Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com> * fix feedback * rename to ispending --------- Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import { AdminInventoryItemResponse, InventoryNext } from "@medusajs/types"
|
||||
import {
|
||||
InventoryItemDeleteRes,
|
||||
InventoryItemListRes,
|
||||
InventoryItemLocationLevelsRes,
|
||||
InventoryItemRes,
|
||||
ReservationItemDeleteRes,
|
||||
ReservationItemListRes,
|
||||
ReservationItemRes,
|
||||
} from "../../types/api-responses"
|
||||
import {
|
||||
InventoryItemLocationBatch,
|
||||
@@ -20,7 +18,6 @@ import {
|
||||
useQuery,
|
||||
} from "@tanstack/react-query"
|
||||
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { client } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/medusa"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
@@ -35,11 +32,6 @@ export const inventoryItemLevelsQueryKeys = queryKeysFactory(
|
||||
INVENTORY_ITEM_LEVELS_QUERY_KEY
|
||||
)
|
||||
|
||||
const RESERVATION_ITEMS_QUERY_KEY = "reservation_items" as const
|
||||
export const reservationItemsQueryKeys = queryKeysFactory(
|
||||
RESERVATION_ITEMS_QUERY_KEY
|
||||
)
|
||||
|
||||
export const useInventoryItems = (
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
@@ -171,7 +163,7 @@ export const useUpdateInventoryItemLevel = (
|
||||
inventoryItemId: string,
|
||||
locationId: string,
|
||||
options?: UseMutationOptions<
|
||||
AdminInventoryLevelResponse,
|
||||
AdminInventoryItemResponse,
|
||||
Error,
|
||||
UpdateInventoryLevelReq
|
||||
>
|
||||
@@ -225,67 +217,3 @@ export const useBatchInventoryItemLevels = (
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useReservationItems = (
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
ReservationItemListRes,
|
||||
Error,
|
||||
ReservationItemListRes,
|
||||
QueryKey
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.inventoryItems.listReservationItems(query),
|
||||
queryKey: reservationItemsQueryKeys.list(query),
|
||||
...options,
|
||||
})
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useUpdateReservationItem = (
|
||||
id: string,
|
||||
payload: InventoryNext.UpdateInventoryItemInput,
|
||||
options?: UseMutationOptions<
|
||||
ReservationItemRes,
|
||||
Error,
|
||||
UpdateInventoryItemReq
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.inventoryItems.updateReservationItem(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: inventoryItemsQueryKeys.lists(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: inventoryItemsQueryKeys.detail(id),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteReservationItem = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<ReservationItemDeleteRes, Error, void>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.inventoryItems.deleteReservationItem(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: inventoryItemsQueryKeys.lists(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: inventoryItemsQueryKeys.detail(id),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
119
packages/admin-next/dashboard/src/hooks/api/reservations.tsx
Normal file
119
packages/admin-next/dashboard/src/hooks/api/reservations.tsx
Normal file
@@ -0,0 +1,119 @@
|
||||
import {
|
||||
CreateReservationReq,
|
||||
UpdateReservationReq,
|
||||
} from "../../types/api-payloads"
|
||||
import {
|
||||
QueryKey,
|
||||
UseMutationOptions,
|
||||
UseQueryOptions,
|
||||
useMutation,
|
||||
useQuery,
|
||||
} from "@tanstack/react-query"
|
||||
import {
|
||||
ReservationItemDeleteRes,
|
||||
ReservationItemListRes,
|
||||
ReservationItemRes,
|
||||
} from "../../types/api-responses"
|
||||
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { client } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/medusa"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
|
||||
const RESERVATION_ITEMS_QUERY_KEY = "reservation_items" as const
|
||||
export const reservationItemsQueryKeys = queryKeysFactory(
|
||||
RESERVATION_ITEMS_QUERY_KEY
|
||||
)
|
||||
|
||||
export const useReservationItem = (
|
||||
id: string,
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<ReservationItemRes, Error, ReservationItemRes, QueryKey>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryKey: reservationItemsQueryKeys.detail(id),
|
||||
queryFn: async () => client.reservations.retrieve(id, query),
|
||||
...options,
|
||||
})
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useReservationItems = (
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
ReservationItemListRes,
|
||||
Error,
|
||||
ReservationItemListRes,
|
||||
QueryKey
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.reservations.list(query),
|
||||
queryKey: reservationItemsQueryKeys.list(query),
|
||||
...options,
|
||||
})
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useUpdateReservationItem = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<ReservationItemRes, Error, UpdateReservationReq>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: InventoryNext.UpdateReservationItemInput) =>
|
||||
client.reservations.update(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: reservationItemsQueryKeys.detail(id),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: reservationItemsQueryKeys.lists(),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useCreateReservationItem = (
|
||||
options?: UseMutationOptions<ReservationItemRes, Error, CreateReservationReq>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: CreateReservationReq) =>
|
||||
client.reservations.create(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: reservationItemsQueryKeys.lists(),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteReservationItem = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<ReservationItemDeleteRes, Error, void>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.reservations.delete(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: reservationItemsQueryKeys.lists(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: reservationItemsQueryKeys.detail(id),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user