@teamnovu/kit-shopware-composables 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/global.d.ts +8 -0
- package/dist/helpers/checkout/index.d.ts +1 -1
- package/dist/helpers/checkout/{useAddresses.d.ts → useCheckoutAddresses.d.ts} +9 -51
- package/dist/helpers/checkout/useOrderDetails.d.ts +3 -8
- package/dist/helpers/checkout/usePaymentMethods.d.ts +11 -49
- package/dist/helpers/checkout/useShippingMethods.d.ts +11 -55
- package/dist/helpers/general/usePagination.d.ts +3 -1
- package/dist/helpers/user/useIsLoggedIn.d.ts +3 -2
- package/dist/helpers/user/useUser.d.ts +4 -106
- package/dist/index.mjs +808 -640
- package/dist/keys.d.ts +42 -1
- package/dist/query/address/index.d.ts +1 -0
- package/dist/query/address/useCreateCustomerAddressMutation.d.ts +7 -6
- package/dist/query/address/useDeleteCustomerAddressMutation.d.ts +2 -1
- package/dist/query/address/useListAddressQuery.d.ts +5 -36
- package/dist/query/address/useUpdateCustomerAddressMutation.d.ts +167 -0
- package/dist/query/cart/useAddLineItemMutation.d.ts +7 -6
- package/dist/query/cart/useReadCartQuery.d.ts +5 -100
- package/dist/query/cart/useRemoveLineItemMutation.d.ts +7 -6
- package/dist/query/cart/useUpdateLineItemMutation.d.ts +7 -6
- package/dist/query/checkout/index.d.ts +0 -1
- package/dist/query/checkout/useCreateOrderMutation.d.ts +7 -6
- package/dist/query/context/useReadContextQuery.d.ts +8 -148
- package/dist/query/context/useUpdateContextMutation.d.ts +7 -6
- package/dist/query/country/index.d.ts +1 -0
- package/dist/query/country/useReadCountryQuery.d.ts +17 -0
- package/dist/query/customer/useChangeEmailMutation.d.ts +7 -6
- package/dist/query/customer/useChangeProfileMutation.d.ts +7 -6
- package/dist/query/customer/useLoginCustomerMutation.d.ts +7 -6
- package/dist/query/customer/useLogoutCustomerMutation.d.ts +7 -6
- package/dist/query/customer/useReadCustomerQuery.d.ts +10 -213
- package/dist/query/customer/useRegisterCustomerMutation.d.ts +7 -6
- package/dist/query/index.d.ts +4 -0
- package/dist/query/navigation/index.d.ts +1 -0
- package/dist/query/navigation/useReadNavigationQuery.d.ts +22 -0
- package/dist/query/order/useReadOrderQuery.d.ts +5 -32
- package/dist/query/payment/useHandlePaymentMutation.d.ts +7 -6
- package/dist/query/payment/useOrderSetPaymentMutation.d.ts +7 -6
- package/dist/query/payment/useReadPaymentMethodQuery.d.ts +5 -20
- package/dist/query/products/useReadCategoryListQuery.d.ts +5 -36
- package/dist/query/products/useReadCompactProductListingQuery.d.ts +5 -20
- package/dist/query/products/useReadCustomProductDetailQuery.d.ts +5 -52
- package/dist/query/salutation/index.d.ts +1 -0
- package/dist/query/salutation/useReadSalutationQuery.d.ts +17 -0
- package/dist/query/seoUrl/index.d.ts +1 -0
- package/dist/query/seoUrl/useReadSeoUrlQuery.d.ts +17 -0
- package/dist/query/shipping/useReadShippingMethodQuery.d.ts +5 -44
- package/dist/query/types/index.d.ts +1 -0
- package/dist/query/types/operations.d.ts +3 -3
- package/dist/query/types/query.d.ts +2 -3
- package/dist/query/types/util.d.ts +6 -0
- package/dist/util/unrefOptions.d.ts +2 -2
- package/docs/index.md +3 -3
- package/package.json +6 -4
- package/src/global.d.ts +8 -0
- package/src/helpers/checkout/index.ts +1 -1
- package/src/helpers/checkout/{useAddresses.ts → useCheckoutAddresses.ts} +2 -2
- package/src/helpers/checkout/useOrderDetails.ts +1 -1
- package/src/helpers/checkout/useOrderPayment.ts +1 -1
- package/src/helpers/checkout/usePaymentMethods.ts +5 -2
- package/src/helpers/checkout/useShippingMethods.ts +5 -2
- package/src/helpers/general/usePagination.ts +10 -5
- package/src/helpers/user/useIsLoggedIn.ts +6 -8
- package/src/helpers/user/useUser.ts +1 -1
- package/src/inject.ts +1 -1
- package/src/keys.ts +66 -1
- package/src/query/address/index.ts +1 -0
- package/src/query/address/useCreateCustomerAddressMutation.ts +7 -6
- package/src/query/address/useDeleteCustomerAddressMutation.ts +7 -6
- package/src/query/address/useUpdateCustomerAddressMutation.ts +42 -0
- package/src/query/cart/useAddLineItemMutation.ts +7 -6
- package/src/query/cart/useRemoveLineItemMutation.ts +6 -5
- package/src/query/cart/useUpdateLineItemMutation.ts +5 -4
- package/src/query/checkout/index.ts +0 -1
- package/src/query/checkout/useCreateOrderMutation.ts +11 -8
- package/src/query/context/useReadContextQuery.ts +14 -5
- package/src/query/context/useUpdateContextMutation.ts +6 -5
- package/src/query/country/index.ts +1 -0
- package/src/query/country/useReadCountryQuery.ts +31 -0
- package/src/query/customer/useChangeEmailMutation.ts +7 -7
- package/src/query/customer/useChangeProfileMutation.ts +7 -7
- package/src/query/customer/useLoginCustomerMutation.ts +12 -9
- package/src/query/customer/useLogoutCustomerMutation.ts +11 -7
- package/src/query/customer/useReadCustomerQuery.ts +2 -1
- package/src/query/customer/useRegisterCustomerMutation.ts +7 -7
- package/src/query/index.ts +4 -0
- package/src/query/navigation/index.ts +1 -0
- package/src/query/navigation/useReadNavigationQuery.ts +43 -0
- package/src/query/order/useReadOrderQuery.ts +0 -2
- package/src/query/payment/useHandlePaymentMutation.ts +5 -4
- package/src/query/payment/useOrderSetPaymentMutation.ts +6 -5
- package/src/query/salutation/index.ts +1 -0
- package/src/query/salutation/useReadSalutationQuery.ts +31 -0
- package/src/query/seoUrl/index.ts +1 -0
- package/src/query/seoUrl/useReadSeoUrlQuery.ts +31 -0
- package/src/query/types/index.ts +1 -0
- package/src/query/types/operations.ts +5 -5
- package/src/query/types/query.ts +4 -6
- package/src/query/types/util.ts +19 -0
- package/src/util/unrefOptions.ts +4 -4
- package/src/util/useOptimistic.ts +2 -1
- package/tsconfig.json +4 -2
- package/vite.config.js +6 -1
- package/dist/query/checkout/useCheckout.d.ts +0 -1
- package/src/query/checkout/useCheckout.ts +0 -2
package/src/global.d.ts
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schemas } from '#store-types'
|
|
1
|
+
import type { Schemas } from '#store-types'
|
|
2
2
|
import { until } from '@vueuse/core'
|
|
3
3
|
import { computed } from 'vue'
|
|
4
4
|
import { useListAddressQuery } from '../../query/address/useListAddressQuery'
|
|
@@ -39,7 +39,7 @@ export function useCheckoutAddresses() {
|
|
|
39
39
|
|
|
40
40
|
const inactiveShippingAddresses = computed(() =>
|
|
41
41
|
addressListQuery.data.value?.elements.filter(
|
|
42
|
-
address => address.id !==
|
|
42
|
+
address => address.id !== activeShippingAddress.value?.id,
|
|
43
43
|
) ?? [])
|
|
44
44
|
|
|
45
45
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MaybeRef } from 'vue'
|
|
2
2
|
import { computed, unref } from 'vue'
|
|
3
3
|
import { useReadOrderQuery } from '../../query/order'
|
|
4
|
-
import { Schemas } from '../../query/types'
|
|
4
|
+
import type { Schemas } from '../../query/types'
|
|
5
5
|
|
|
6
6
|
export function useOrderDetails(
|
|
7
7
|
orderId: MaybeRef<string>,
|
|
@@ -8,7 +8,7 @@ export function usePaymentMethods() {
|
|
|
8
8
|
const contextUpdateMutation = useUpdateContextMutation()
|
|
9
9
|
const paymentMethodsQuery = useReadPaymentMethodQuery({
|
|
10
10
|
query: {
|
|
11
|
-
|
|
11
|
+
onlyAvailable: true,
|
|
12
12
|
},
|
|
13
13
|
})
|
|
14
14
|
|
|
@@ -21,7 +21,10 @@ export function usePaymentMethods() {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const activePaymentMethod = computed(() => contextQuery.data?.value?.paymentMethod)
|
|
24
|
-
const paymentMethods = computed(() =>
|
|
24
|
+
const paymentMethods = computed(() =>
|
|
25
|
+
paymentMethodsQuery.data?.value?.elements?.sort((a, b) => {
|
|
26
|
+
return (a.position ?? 0) - (b.position ?? 0)
|
|
27
|
+
}) ?? [])
|
|
25
28
|
|
|
26
29
|
return {
|
|
27
30
|
contextUpdateMutation,
|
|
@@ -8,7 +8,7 @@ export function useShippingMethods() {
|
|
|
8
8
|
const contextUpdateMutation = useUpdateContextMutation()
|
|
9
9
|
const shippingMethodsQuery = useReadShippingMethodQuery({
|
|
10
10
|
query: {
|
|
11
|
-
|
|
11
|
+
onlyAvailable: true,
|
|
12
12
|
},
|
|
13
13
|
})
|
|
14
14
|
|
|
@@ -21,7 +21,10 @@ export function useShippingMethods() {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const activeShippingMethod = computed(() => contextQuery.data?.value?.shippingMethod)
|
|
24
|
-
const shippingMethods = computed(() =>
|
|
24
|
+
const shippingMethods = computed(() =>
|
|
25
|
+
shippingMethodsQuery.data?.value?.elements.sort((a, b) => {
|
|
26
|
+
return (a.position ?? 0) - (b.position ?? 0)
|
|
27
|
+
}) ?? [])
|
|
25
28
|
|
|
26
29
|
return {
|
|
27
30
|
contextUpdateMutation,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Schemas } from '#store-types'
|
|
2
|
+
import { keepPreviousData } from '@tanstack/vue-query'
|
|
2
3
|
import type { MaybeRef } from 'vue'
|
|
3
4
|
import { computed, reactive, toRef, unref, watch } from 'vue'
|
|
4
5
|
|
|
@@ -6,15 +7,16 @@ interface PaginationOptions {
|
|
|
6
7
|
page?: MaybeRef<number>
|
|
7
8
|
total?: MaybeRef<number>
|
|
8
9
|
limit?: MaybeRef<number>
|
|
10
|
+
totalCountMode?: MaybeRef<'exact' | 'next-pages' | 'none'>
|
|
9
11
|
}
|
|
10
|
-
|
|
11
12
|
export function usePagination(opts?: PaginationOptions) {
|
|
12
|
-
const { total, limit, page } = opts ?? {}
|
|
13
|
+
const { total, limit, page, totalCountMode } = opts ?? {}
|
|
13
14
|
|
|
14
15
|
const state = reactive({
|
|
15
16
|
page: page ?? 1,
|
|
16
17
|
total: total ?? 0,
|
|
17
18
|
limit: limit,
|
|
19
|
+
totalCountMode: totalCountMode,
|
|
18
20
|
})
|
|
19
21
|
|
|
20
22
|
const pageCount = computed(() => {
|
|
@@ -46,12 +48,15 @@ export function usePagination(opts?: PaginationOptions) {
|
|
|
46
48
|
const isFirstPage = computed(() => state.page === 1)
|
|
47
49
|
|
|
48
50
|
const queryOptions = computed(() => ({
|
|
49
|
-
p: state.page,
|
|
50
|
-
limit: state.limit,
|
|
51
|
+
'p': state.page,
|
|
52
|
+
'limit': state.limit,
|
|
53
|
+
'total-count-mode': state.totalCountMode ?? 'none',
|
|
51
54
|
}))
|
|
52
55
|
|
|
53
|
-
const usePaginationSync = (data: MaybeRef<Schemas['EntitySearchResult']>) => {
|
|
56
|
+
const usePaginationSync = (data: MaybeRef<Schemas['EntitySearchResult'] | undefined>) => {
|
|
54
57
|
watch(() => unref(data), (newData) => {
|
|
58
|
+
if (!newData) return
|
|
59
|
+
|
|
55
60
|
state.total = newData?.total ?? 0
|
|
56
61
|
state.limit = newData?.limit ?? 0
|
|
57
62
|
})
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { computed } from 'vue'
|
|
2
|
-
import {
|
|
1
|
+
import { computed, type MaybeRef, unref } from 'vue'
|
|
2
|
+
import type { Schemas } from '#store-types'
|
|
3
3
|
|
|
4
|
-
export function useIsLoggedIn() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
&& !!context.value?.customer?.active
|
|
9
|
-
&& !context.value?.customer?.guest)
|
|
4
|
+
export function useIsLoggedIn(context: MaybeRef<Schemas['SalesChannelContext'] | undefined>) {
|
|
5
|
+
return computed(() => !!unref(context)?.customer?.id
|
|
6
|
+
&& !!unref(context)?.customer?.active
|
|
7
|
+
&& !unref(context)?.customer?.guest)
|
|
10
8
|
}
|
|
@@ -2,7 +2,7 @@ import { computed } from 'vue'
|
|
|
2
2
|
import {
|
|
3
3
|
useReadCustomerQuery,
|
|
4
4
|
} from '../../query/customer'
|
|
5
|
-
import { Schemas } from '../../query/types'
|
|
5
|
+
import type { Schemas } from '../../query/types'
|
|
6
6
|
|
|
7
7
|
export function useUser(criteria?: Schemas['Criteria']) {
|
|
8
8
|
// Create customer query
|
package/src/inject.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ShopwareClient } from '@teamnovu/kit-shopware-api-client'
|
|
2
2
|
import type { InjectionKey } from 'vue'
|
|
3
3
|
import { inject } from 'vue'
|
|
4
|
-
import { Operations } from './query/types/operations'
|
|
4
|
+
import type { Operations } from './query/types/operations'
|
|
5
5
|
|
|
6
6
|
export const shopwareClientKey = Symbol('shopwareClient') as InjectionKey<ShopwareClient<never>>
|
|
7
7
|
|
package/src/keys.ts
CHANGED
|
@@ -16,6 +16,29 @@ export const categoryKeys = {
|
|
|
16
16
|
},
|
|
17
17
|
] as const,
|
|
18
18
|
}
|
|
19
|
+
export const navigationKeys = {
|
|
20
|
+
all: () => ['navigation'] as const,
|
|
21
|
+
lists: () => [...navigationKeys.all(), 'list'] as const,
|
|
22
|
+
list: (body: MaybeRef<unknown>) =>
|
|
23
|
+
[
|
|
24
|
+
...navigationKeys.all(),
|
|
25
|
+
'list',
|
|
26
|
+
{
|
|
27
|
+
body,
|
|
28
|
+
},
|
|
29
|
+
] as const,
|
|
30
|
+
details: () => [...navigationKeys.all(), 'detail'] as const,
|
|
31
|
+
detail: (activeId: MaybeRef<string>, rootId: MaybeRef<string>, body: MaybeRef<unknown>) =>
|
|
32
|
+
[
|
|
33
|
+
...navigationKeys.all(),
|
|
34
|
+
'detail',
|
|
35
|
+
{
|
|
36
|
+
activeId,
|
|
37
|
+
rootId,
|
|
38
|
+
body,
|
|
39
|
+
},
|
|
40
|
+
] as const,
|
|
41
|
+
}
|
|
19
42
|
|
|
20
43
|
export const productKeys = {
|
|
21
44
|
all: () => ['product'] as const,
|
|
@@ -46,7 +69,8 @@ export const cartKeys = {
|
|
|
46
69
|
}
|
|
47
70
|
|
|
48
71
|
export const customerKeys = {
|
|
49
|
-
|
|
72
|
+
all: () => ['customer'] as const,
|
|
73
|
+
detail: (body: MaybeRef<unknown>) => ['customer', { body }] as const,
|
|
50
74
|
}
|
|
51
75
|
|
|
52
76
|
export const addressKeys = {
|
|
@@ -60,6 +84,8 @@ export const addressKeys = {
|
|
|
60
84
|
body,
|
|
61
85
|
},
|
|
62
86
|
] as const,
|
|
87
|
+
details: () => [...addressKeys.all(), 'detail'] as const,
|
|
88
|
+
detail: (addressId: string, body?: MaybeRef<unknown>) => [...addressKeys.details(), addressId, ...(body ? [{ body }] : [])] as const,
|
|
63
89
|
}
|
|
64
90
|
|
|
65
91
|
export const shippingKeys = {
|
|
@@ -101,3 +127,42 @@ export const orderKeys = {
|
|
|
101
127
|
},
|
|
102
128
|
] as const,
|
|
103
129
|
}
|
|
130
|
+
|
|
131
|
+
export const seoUrlKeys = {
|
|
132
|
+
all: () => ['seoUrl'] as const,
|
|
133
|
+
lists: () => [...seoUrlKeys.all(), 'list'] as const,
|
|
134
|
+
list: (body: MaybeRef<unknown>) =>
|
|
135
|
+
[
|
|
136
|
+
...seoUrlKeys.all(),
|
|
137
|
+
'list',
|
|
138
|
+
{
|
|
139
|
+
body,
|
|
140
|
+
},
|
|
141
|
+
] as const,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export const salutationKeys = {
|
|
145
|
+
all: () => ['salutation'] as const,
|
|
146
|
+
lists: () => [...salutationKeys.all(), 'list'] as const,
|
|
147
|
+
list: (body: MaybeRef<unknown>) =>
|
|
148
|
+
[
|
|
149
|
+
...salutationKeys.all(),
|
|
150
|
+
'list',
|
|
151
|
+
{
|
|
152
|
+
body,
|
|
153
|
+
},
|
|
154
|
+
] as const,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export const countryKeys = {
|
|
158
|
+
all: () => ['country'] as const,
|
|
159
|
+
lists: () => [...countryKeys.all(), 'list'] as const,
|
|
160
|
+
list: (body: MaybeRef<unknown>) =>
|
|
161
|
+
[
|
|
162
|
+
...countryKeys.all(),
|
|
163
|
+
'list',
|
|
164
|
+
{
|
|
165
|
+
body,
|
|
166
|
+
},
|
|
167
|
+
] as const,
|
|
168
|
+
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
1
|
+
import { useMutation, type UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
|
|
2
3
|
import { unref } from 'vue'
|
|
3
|
-
import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
|
|
4
4
|
import { useShopwareQueryClient } from '../../inject'
|
|
5
5
|
import { addressKeys } from '../../keys'
|
|
6
6
|
import { unrefOptions } from '../../util/unrefOptions'
|
|
7
|
+
import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
|
|
7
8
|
|
|
8
9
|
const createCustomerAddressOperation = 'createCustomerAddress post /account/address' satisfies OperationKey
|
|
9
10
|
|
|
10
11
|
export function useCreateCustomerAddressMutation(
|
|
11
12
|
mutationOptions?: UseMutationOptions<
|
|
12
13
|
OperationResponse<typeof createCustomerAddressOperation>,
|
|
13
|
-
|
|
14
|
+
ShopwareApiError | Error,
|
|
14
15
|
OperationOptions<typeof createCustomerAddressOperation>
|
|
15
16
|
>,
|
|
16
17
|
) {
|
|
@@ -22,11 +23,11 @@ export function useCreateCustomerAddressMutation(
|
|
|
22
23
|
mutationFn: async (options: OperationOptions<typeof createCustomerAddressOperation>) => {
|
|
23
24
|
return client.query(createCustomerAddressOperation, unrefOptions(options))
|
|
24
25
|
},
|
|
25
|
-
onSuccess: (data, variables, context) => {
|
|
26
|
+
onSuccess: async (data, variables, context) => {
|
|
26
27
|
// Invalidate address list queries to refetch data
|
|
27
|
-
queryClient.invalidateQueries({ queryKey: addressKeys.lists() })
|
|
28
|
+
await queryClient.invalidateQueries({ queryKey: addressKeys.lists() })
|
|
28
29
|
|
|
29
|
-
unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
30
|
+
await unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
30
31
|
},
|
|
31
32
|
})
|
|
32
33
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
1
|
+
import { useMutation, type UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
|
|
2
3
|
import { unref } from 'vue'
|
|
3
|
-
import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
|
|
4
4
|
import { useShopwareQueryClient } from '../../inject'
|
|
5
5
|
import { addressKeys } from '../../keys'
|
|
6
6
|
import { unrefOptions } from '../../util/unrefOptions'
|
|
7
|
+
import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
|
|
7
8
|
|
|
8
9
|
const deleteCustomerAddressOperation = 'deleteCustomerAddress delete /account/address/{addressId}' satisfies OperationKey
|
|
9
10
|
|
|
10
11
|
export function useDeleteCustomerAddressMutation(
|
|
11
12
|
mutationOptions?: UseMutationOptions<
|
|
12
13
|
OperationResponse<typeof deleteCustomerAddressOperation>,
|
|
13
|
-
|
|
14
|
+
ShopwareApiError | Error,
|
|
14
15
|
OperationOptions<typeof deleteCustomerAddressOperation>
|
|
15
16
|
>,
|
|
16
17
|
) {
|
|
@@ -22,11 +23,11 @@ export function useDeleteCustomerAddressMutation(
|
|
|
22
23
|
mutationFn: async (options: OperationOptions<typeof deleteCustomerAddressOperation>) => {
|
|
23
24
|
return client.query(deleteCustomerAddressOperation, unrefOptions(options))
|
|
24
25
|
},
|
|
25
|
-
onSuccess: (data, variables, context) => {
|
|
26
|
+
onSuccess: async (data, variables, context) => {
|
|
26
27
|
// Invalidate address list queries to refetch data
|
|
27
|
-
queryClient.invalidateQueries({ queryKey: addressKeys.lists() })
|
|
28
|
+
await queryClient.invalidateQueries({ queryKey: addressKeys.lists() })
|
|
28
29
|
|
|
29
|
-
unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
30
|
+
await unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
30
31
|
},
|
|
31
32
|
})
|
|
32
33
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useMutation, type UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
|
|
3
|
+
import { unref } from 'vue'
|
|
4
|
+
import { useShopwareQueryClient } from '../../inject'
|
|
5
|
+
import { addressKeys } from '../../keys'
|
|
6
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
7
|
+
import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
|
|
8
|
+
|
|
9
|
+
const updateCustomerAddressOperation = 'updateCustomerAddress patch /account/address/{addressId}' satisfies OperationKey
|
|
10
|
+
|
|
11
|
+
export function useUpdateCustomerAddressMutation(
|
|
12
|
+
mutationOptions?: UseMutationOptions<
|
|
13
|
+
OperationResponse<typeof updateCustomerAddressOperation>,
|
|
14
|
+
ShopwareApiError | Error,
|
|
15
|
+
OperationOptions<typeof updateCustomerAddressOperation>
|
|
16
|
+
>,
|
|
17
|
+
) {
|
|
18
|
+
const client = useShopwareQueryClient()
|
|
19
|
+
const queryClient = useQueryClient()
|
|
20
|
+
|
|
21
|
+
return useMutation({
|
|
22
|
+
...mutationOptions,
|
|
23
|
+
mutationFn: async (options: OperationOptions<typeof updateCustomerAddressOperation>) => {
|
|
24
|
+
return client.query(updateCustomerAddressOperation, unrefOptions(options))
|
|
25
|
+
},
|
|
26
|
+
onSuccess: async (data, variables, context) => {
|
|
27
|
+
const { addressId } = unrefOptions(variables).params
|
|
28
|
+
queryClient.setQueryData(addressKeys.detail(addressId), data)
|
|
29
|
+
|
|
30
|
+
// Invalidate address list queries to refetch data
|
|
31
|
+
await Promise.all([
|
|
32
|
+
queryClient.invalidateQueries({ queryKey: addressKeys.lists() }),
|
|
33
|
+
queryClient.invalidateQueries({
|
|
34
|
+
queryKey: addressKeys.detail(unrefOptions(variables).params.addressId),
|
|
35
|
+
predicate: query => query.queryKey.at(-1) !== addressId,
|
|
36
|
+
}),
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
await unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
1
|
+
import { useMutation, type UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
|
|
2
3
|
import { unref } from 'vue'
|
|
3
|
-
import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
|
|
4
4
|
import { useShopwareQueryClient } from '../../inject'
|
|
5
5
|
import { cartKeys } from '../../keys'
|
|
6
|
+
import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
|
|
6
7
|
|
|
7
8
|
const addCartItemOperation = 'addLineItem post /checkout/cart/line-item' satisfies OperationKey
|
|
8
9
|
|
|
@@ -20,9 +21,9 @@ type Body = Omit<
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export function useAddLineItemMutation(
|
|
23
|
-
mutationOptions
|
|
24
|
+
mutationOptions?: UseMutationOptions<
|
|
24
25
|
OperationResponse<typeof addCartItemOperation>,
|
|
25
|
-
|
|
26
|
+
ShopwareApiError | Error,
|
|
26
27
|
Body
|
|
27
28
|
>,
|
|
28
29
|
) {
|
|
@@ -36,10 +37,10 @@ export function useAddLineItemMutation(
|
|
|
36
37
|
body: body as OperationBody<typeof addCartItemOperation>,
|
|
37
38
|
})
|
|
38
39
|
},
|
|
39
|
-
onSuccess: (newCart, variables, context) => {
|
|
40
|
+
onSuccess: async (newCart, variables, context) => {
|
|
40
41
|
queryClient.setQueryData(cartKeys.get(), newCart)
|
|
41
42
|
// queryClient.invalidateQueries({ queryKey: cartKeys.get() })
|
|
42
|
-
unref(unref(mutationOptions)
|
|
43
|
+
await unref(unref(mutationOptions)?.onSuccess)?.(newCart, variables, context)
|
|
43
44
|
},
|
|
44
45
|
})
|
|
45
46
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
1
|
+
import { useMutation, type UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
|
|
2
3
|
import { unref } from 'vue'
|
|
3
|
-
import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
|
|
4
4
|
import { useShopwareQueryClient } from '../../inject'
|
|
5
5
|
import { cartKeys } from '../../keys'
|
|
6
|
+
import type { OperationBody, OperationKey, OperationResponse } from '../types/query'
|
|
6
7
|
|
|
7
8
|
const removeCartItemOperation = 'removeLineItem post /checkout/cart/line-item/delete' satisfies OperationKey
|
|
8
9
|
|
|
9
10
|
export function useRemoveLineItemMutation(
|
|
10
11
|
mutationOptions?: UseMutationOptions<
|
|
11
12
|
OperationResponse<typeof removeCartItemOperation>,
|
|
12
|
-
|
|
13
|
+
ShopwareApiError | Error,
|
|
13
14
|
OperationBody<typeof removeCartItemOperation>
|
|
14
15
|
>,
|
|
15
16
|
) {
|
|
@@ -23,10 +24,10 @@ export function useRemoveLineItemMutation(
|
|
|
23
24
|
body: body as OperationBody<typeof removeCartItemOperation>,
|
|
24
25
|
})
|
|
25
26
|
},
|
|
26
|
-
onSuccess: (newCart, variables, context) => {
|
|
27
|
+
onSuccess: async (newCart, variables, context) => {
|
|
27
28
|
queryClient.setQueryData(cartKeys.get(), newCart)
|
|
28
29
|
// queryClient.invalidateQueries({ queryKey: cartKeys.get() })
|
|
29
|
-
unref(unref(mutationOptions)?.onSuccess)?.(newCart, variables, context)
|
|
30
|
+
await unref(unref(mutationOptions)?.onSuccess)?.(newCart, variables, context)
|
|
30
31
|
},
|
|
31
32
|
})
|
|
32
33
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
1
|
+
import { useMutation, type UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
|
|
2
3
|
import { unref } from 'vue'
|
|
3
4
|
import { useShopwareQueryClient } from '../../inject'
|
|
4
5
|
import { cartKeys } from '../../keys'
|
|
@@ -22,7 +23,7 @@ type Body = Omit<
|
|
|
22
23
|
export function useUpdateLineItemMutation(
|
|
23
24
|
mutationOptions?: UseMutationOptions<
|
|
24
25
|
OperationResponse<typeof updateCartItemOperation>,
|
|
25
|
-
|
|
26
|
+
ShopwareApiError | Error,
|
|
26
27
|
Body
|
|
27
28
|
>,
|
|
28
29
|
) {
|
|
@@ -36,10 +37,10 @@ export function useUpdateLineItemMutation(
|
|
|
36
37
|
body: body as OperationBody<typeof updateCartItemOperation>,
|
|
37
38
|
})
|
|
38
39
|
},
|
|
39
|
-
onSuccess: (newCart, variables, context) => {
|
|
40
|
+
onSuccess: async (newCart, variables, context) => {
|
|
40
41
|
queryClient.setQueryData(cartKeys.get(), newCart)
|
|
41
42
|
// queryClient.invalidateQueries({ queryKey: cartKeys.get() })
|
|
42
|
-
unref(unref(mutationOptions)?.onSuccess)?.(newCart, variables, context)
|
|
43
|
+
await unref(unref(mutationOptions)?.onSuccess)?.(newCart, variables, context)
|
|
43
44
|
},
|
|
44
45
|
})
|
|
45
46
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
|
|
2
|
+
import { useMutation, type UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
2
3
|
import { unref } from 'vue'
|
|
3
4
|
import type { OperationKey, OperationOptions, OperationResponse } from '../types/query'
|
|
4
5
|
import { useShopwareQueryClient } from '../../inject'
|
|
@@ -10,7 +11,7 @@ const createOrderOperation = 'createOrder post /checkout/order' satisfies Operat
|
|
|
10
11
|
export function useCreateOrderMutation(
|
|
11
12
|
mutationOptions?: UseMutationOptions<
|
|
12
13
|
OperationResponse<typeof createOrderOperation>,
|
|
13
|
-
|
|
14
|
+
ShopwareApiError | Error,
|
|
14
15
|
OperationOptions<typeof createOrderOperation>
|
|
15
16
|
>,
|
|
16
17
|
) {
|
|
@@ -22,14 +23,16 @@ export function useCreateOrderMutation(
|
|
|
22
23
|
mutationFn: async (options?: OperationOptions<typeof createOrderOperation>) => {
|
|
23
24
|
return client.query(createOrderOperation, unrefOptions(options))
|
|
24
25
|
},
|
|
25
|
-
onSuccess: (data, variables, context) => {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
onSuccess: async (data, variables, context) => {
|
|
27
|
+
await Promise.all([
|
|
28
|
+
// Clear cart after successful order creation
|
|
29
|
+
queryClient.invalidateQueries({ queryKey: cartKeys.get() }),
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
// Invalidate order list to refetch data
|
|
32
|
+
queryClient.invalidateQueries({ queryKey: orderKeys.lists() }),
|
|
33
|
+
])
|
|
31
34
|
|
|
32
|
-
unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
35
|
+
await unref(unref(mutationOptions)?.onSuccess)?.(data, variables, context)
|
|
33
36
|
},
|
|
34
37
|
})
|
|
35
38
|
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { queryOptions, useQuery } from '@tanstack/vue-query'
|
|
2
2
|
import { useShopwareQueryClient } from '../../inject'
|
|
3
3
|
import { contextKeys } from '../../keys'
|
|
4
|
-
import type { OperationKey } from '../types/query'
|
|
4
|
+
import type { OperationKey, OperationOptions } from '../types/query'
|
|
5
|
+
import { unrefOptions } from '../../util'
|
|
5
6
|
|
|
6
7
|
const readContextOperation = 'readContext get /context' satisfies OperationKey
|
|
7
8
|
|
|
8
|
-
export function
|
|
9
|
+
export function useReadContextQueryOptions(
|
|
10
|
+
options?: OperationOptions<typeof readContextOperation>,
|
|
11
|
+
) {
|
|
9
12
|
const client = useShopwareQueryClient()
|
|
10
13
|
|
|
11
14
|
return queryOptions({
|
|
12
15
|
queryKey: contextKeys.all(),
|
|
13
|
-
queryFn: ({ signal }) =>
|
|
16
|
+
queryFn: ({ signal }) =>
|
|
17
|
+
client.query(readContextOperation, {
|
|
18
|
+
...unrefOptions(options),
|
|
19
|
+
signal,
|
|
20
|
+
}),
|
|
14
21
|
})
|
|
15
22
|
}
|
|
16
23
|
|
|
17
|
-
export function useReadContextQuery(
|
|
18
|
-
|
|
24
|
+
export function useReadContextQuery(
|
|
25
|
+
options?: OperationOptions<typeof readContextOperation>,
|
|
26
|
+
) {
|
|
27
|
+
return useQuery(useReadContextQueryOptions(options))
|
|
19
28
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
1
|
+
import { useMutation, type UseMutationOptions, useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import { ShopwareApiError } from '@teamnovu/kit-shopware-api-client'
|
|
2
3
|
import { unref } from 'vue'
|
|
3
4
|
import { useShopwareQueryClient } from '../../inject'
|
|
4
5
|
import { contextKeys } from '../../keys'
|
|
@@ -9,7 +10,7 @@ const updateContextOperation = 'updateContext patch /context' satisfies Operatio
|
|
|
9
10
|
export function useUpdateContextMutation(
|
|
10
11
|
mutationOptions?: UseMutationOptions<
|
|
11
12
|
OperationResponse<typeof updateContextOperation>,
|
|
12
|
-
|
|
13
|
+
ShopwareApiError | Error,
|
|
13
14
|
OperationBody<typeof updateContextOperation>
|
|
14
15
|
>,
|
|
15
16
|
) {
|
|
@@ -27,10 +28,10 @@ export function useUpdateContextMutation(
|
|
|
27
28
|
})
|
|
28
29
|
},
|
|
29
30
|
|
|
30
|
-
onSuccess: (newContext, variables, context) => {
|
|
31
|
-
queryClient.invalidateQueries({ queryKey: contextKeys.all() })
|
|
31
|
+
onSuccess: async (newContext, variables, context) => {
|
|
32
|
+
await queryClient.invalidateQueries({ queryKey: contextKeys.all() })
|
|
32
33
|
|
|
33
|
-
unref(unref(mutationOptions)?.onSuccess)?.(newContext, variables, context)
|
|
34
|
+
await unref(unref(mutationOptions)?.onSuccess)?.(newContext, variables, context)
|
|
34
35
|
},
|
|
35
36
|
})
|
|
36
37
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useReadCountryQuery'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/vue-query'
|
|
2
|
+
import { useShopwareQueryClient } from '../../inject'
|
|
3
|
+
import { countryKeys } from '../../keys'
|
|
4
|
+
import { unrefOptions } from '../../util/unrefOptions'
|
|
5
|
+
import type { OperationKey, OperationOptions } from '../types/query'
|
|
6
|
+
|
|
7
|
+
const readCountryOperation = 'readCountry post /country' satisfies OperationKey
|
|
8
|
+
|
|
9
|
+
export const useReadCountryQueryOptions = function useReadCountryQueryOptions(
|
|
10
|
+
options?: OperationOptions<typeof readCountryOperation>,
|
|
11
|
+
) {
|
|
12
|
+
const client = useShopwareQueryClient()
|
|
13
|
+
const queryKey = countryKeys.list(options)
|
|
14
|
+
|
|
15
|
+
return queryOptions({
|
|
16
|
+
queryKey,
|
|
17
|
+
queryFn: async ({ signal }) => {
|
|
18
|
+
const unrefedOptions = unrefOptions(options)
|
|
19
|
+
|
|
20
|
+
return client.query(readCountryOperation, {
|
|
21
|
+
...unrefedOptions,
|
|
22
|
+
signal,
|
|
23
|
+
})
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useReadCountryQuery(options?: OperationOptions<typeof readCountryOperation>) {
|
|
29
|
+
return useQuery(useReadCountryQueryOptions(options))
|
|
30
|
+
}
|
|
31
|
+
|