@raxonltd/raxon-core 1.0.0
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/core/component/general.image.d.ts +25 -0
- package/dist/core/component/general.image.d.ts.map +1 -0
- package/dist/core/component/general.image.js +30 -0
- package/dist/core/context/cart.context.d.ts +25 -0
- package/dist/core/context/cart.context.d.ts.map +1 -0
- package/dist/core/context/cart.context.js +339 -0
- package/dist/core/context/security.context.d.ts +15 -0
- package/dist/core/context/security.context.d.ts.map +1 -0
- package/dist/core/context/security.context.js +130 -0
- package/dist/core/feature/address/form/address-search-input.d.ts +17 -0
- package/dist/core/feature/address/form/address-search-input.d.ts.map +1 -0
- package/dist/core/feature/address/form/address-search-input.js +30 -0
- package/dist/core/feature/address/hook/use.addres.d.ts +10 -0
- package/dist/core/feature/address/hook/use.addres.d.ts.map +1 -0
- package/dist/core/feature/address/hook/use.addres.js +57 -0
- package/dist/core/feature/address/hook/use.address-autocomplete.d.ts +13 -0
- package/dist/core/feature/address/hook/use.address-autocomplete.d.ts.map +1 -0
- package/dist/core/feature/address/hook/use.address-autocomplete.js +105 -0
- package/dist/core/feature/address/util/address.types.d.ts +37 -0
- package/dist/core/feature/address/util/address.types.d.ts.map +1 -0
- package/dist/core/feature/address/util/address.types.js +1 -0
- package/dist/core/feature/address/util/parse-google-place.d.ts +13 -0
- package/dist/core/feature/address/util/parse-google-place.d.ts.map +1 -0
- package/dist/core/feature/address/util/parse-google-place.js +49 -0
- package/dist/core/feature/analytic-event/analytic.event.context.d.ts +19 -0
- package/dist/core/feature/analytic-event/analytic.event.context.d.ts.map +1 -0
- package/dist/core/feature/analytic-event/analytic.event.context.js +151 -0
- package/dist/core/feature/article/hook/use.article.d.ts +7 -0
- package/dist/core/feature/article/hook/use.article.d.ts.map +1 -0
- package/dist/core/feature/article/hook/use.article.js +28 -0
- package/dist/core/feature/attribute/hook/use.attribute.d.ts +10 -0
- package/dist/core/feature/attribute/hook/use.attribute.d.ts.map +1 -0
- package/dist/core/feature/attribute/hook/use.attribute.js +21 -0
- package/dist/core/feature/auth/hook/use.auth.d.ts +29 -0
- package/dist/core/feature/auth/hook/use.auth.d.ts.map +1 -0
- package/dist/core/feature/auth/hook/use.auth.js +122 -0
- package/dist/core/feature/auth/modal/modal.auth.d.ts +9 -0
- package/dist/core/feature/auth/modal/modal.auth.d.ts.map +1 -0
- package/dist/core/feature/auth/modal/modal.auth.js +34 -0
- package/dist/core/feature/auth/view/view.login.d.ts +8 -0
- package/dist/core/feature/auth/view/view.login.d.ts.map +1 -0
- package/dist/core/feature/auth/view/view.login.js +45 -0
- package/dist/core/feature/auth/view/view.register.d.ts +8 -0
- package/dist/core/feature/auth/view/view.register.d.ts.map +1 -0
- package/dist/core/feature/auth/view/view.register.js +83 -0
- package/dist/core/feature/bank-account/hook/use.bank.account.d.ts +12 -0
- package/dist/core/feature/bank-account/hook/use.bank.account.d.ts.map +1 -0
- package/dist/core/feature/bank-account/hook/use.bank.account.js +38 -0
- package/dist/core/feature/cart/component/cart.order.summary.d.ts +8 -0
- package/dist/core/feature/cart/component/cart.order.summary.d.ts.map +1 -0
- package/dist/core/feature/cart/component/cart.order.summary.js +8 -0
- package/dist/core/feature/cart/component/cart.promo.code.section.d.ts +6 -0
- package/dist/core/feature/cart/component/cart.promo.code.section.d.ts.map +1 -0
- package/dist/core/feature/cart/component/cart.promo.code.section.js +109 -0
- package/dist/core/feature/cart/hook/use.cart.d.ts +67 -0
- package/dist/core/feature/cart/hook/use.cart.d.ts.map +1 -0
- package/dist/core/feature/cart/hook/use.cart.js +196 -0
- package/dist/core/feature/cart/util/basket-pay.response.d.ts +20 -0
- package/dist/core/feature/cart/util/basket-pay.response.d.ts.map +1 -0
- package/dist/core/feature/cart/util/basket-pay.response.js +40 -0
- package/dist/core/feature/cart/util/cart-optimistic.d.ts +36 -0
- package/dist/core/feature/cart/util/cart-optimistic.d.ts.map +1 -0
- package/dist/core/feature/cart/util/cart-optimistic.js +320 -0
- package/dist/core/feature/cart/util/garanti-payment.d.ts +4 -0
- package/dist/core/feature/cart/util/garanti-payment.d.ts.map +1 -0
- package/dist/core/feature/cart/util/garanti-payment.js +26 -0
- package/dist/core/feature/collection/hook/use.collection.d.ts +7 -0
- package/dist/core/feature/collection/hook/use.collection.d.ts.map +1 -0
- package/dist/core/feature/collection/hook/use.collection.js +27 -0
- package/dist/core/feature/delivery-method/hook/use.delivery.method.d.ts +10 -0
- package/dist/core/feature/delivery-method/hook/use.delivery.method.d.ts.map +1 -0
- package/dist/core/feature/delivery-method/hook/use.delivery.method.js +33 -0
- package/dist/core/feature/delivery-method/util/checkout.delivery.method.d.ts +5 -0
- package/dist/core/feature/delivery-method/util/checkout.delivery.method.d.ts.map +1 -0
- package/dist/core/feature/delivery-method/util/checkout.delivery.method.js +8 -0
- package/dist/core/feature/faq/hook/use.faq.d.ts +9 -0
- package/dist/core/feature/faq/hook/use.faq.d.ts.map +1 -0
- package/dist/core/feature/faq/hook/use.faq.js +20 -0
- package/dist/core/feature/favorite/hook/use.favorite.d.ts +17 -0
- package/dist/core/feature/favorite/hook/use.favorite.d.ts.map +1 -0
- package/dist/core/feature/favorite/hook/use.favorite.js +35 -0
- package/dist/core/feature/form-submit/form/form.contact.d.ts +6 -0
- package/dist/core/feature/form-submit/form/form.contact.d.ts.map +1 -0
- package/dist/core/feature/form-submit/form/form.contact.js +8 -0
- package/dist/core/feature/form-submit/hook/use.form.submit.d.ts +4 -0
- package/dist/core/feature/form-submit/hook/use.form.submit.d.ts.map +1 -0
- package/dist/core/feature/form-submit/hook/use.form.submit.js +13 -0
- package/dist/core/feature/invoice/hook/use.invoice.d.ts +9 -0
- package/dist/core/feature/invoice/hook/use.invoice.d.ts.map +1 -0
- package/dist/core/feature/invoice/hook/use.invoice.js +46 -0
- package/dist/core/feature/newsletter/hook/use.newsletter.d.ts +13 -0
- package/dist/core/feature/newsletter/hook/use.newsletter.d.ts.map +1 -0
- package/dist/core/feature/newsletter/hook/use.newsletter.js +21 -0
- package/dist/core/feature/newsletter/modal/modal.newsletter.product.d.ts +27 -0
- package/dist/core/feature/newsletter/modal/modal.newsletter.product.d.ts.map +1 -0
- package/dist/core/feature/newsletter/modal/modal.newsletter.product.js +77 -0
- package/dist/core/feature/order/hook/use.order.d.ts +7 -0
- package/dist/core/feature/order/hook/use.order.d.ts.map +1 -0
- package/dist/core/feature/order/hook/use.order.js +26 -0
- package/dist/core/feature/payment-method/checkout.payment.options.d.ts +18 -0
- package/dist/core/feature/payment-method/checkout.payment.options.d.ts.map +1 -0
- package/dist/core/feature/payment-method/checkout.payment.options.js +74 -0
- package/dist/core/feature/payment-method/hook/use.payment.method.d.ts +8 -0
- package/dist/core/feature/payment-method/hook/use.payment.method.d.ts.map +1 -0
- package/dist/core/feature/payment-method/hook/use.payment.method.js +36 -0
- package/dist/core/feature/product/hook/use.product.d.ts +62 -0
- package/dist/core/feature/product/hook/use.product.d.ts.map +1 -0
- package/dist/core/feature/product/hook/use.product.js +60 -0
- package/dist/core/feature/profile/hook/use.profile.d.ts +26 -0
- package/dist/core/feature/profile/hook/use.profile.d.ts.map +1 -0
- package/dist/core/feature/profile/hook/use.profile.js +83 -0
- package/dist/core/feature/promo-code/hook/use.promo.code.d.ts +8 -0
- package/dist/core/feature/promo-code/hook/use.promo.code.d.ts.map +1 -0
- package/dist/core/feature/promo-code/hook/use.promo.code.js +24 -0
- package/dist/core/interface/basket.interface.d.ts +347 -0
- package/dist/core/interface/basket.interface.d.ts.map +1 -0
- package/dist/core/interface/basket.interface.js +1 -0
- package/dist/core/interface/inventory.interface.d.ts +87 -0
- package/dist/core/interface/inventory.interface.d.ts.map +1 -0
- package/dist/core/interface/inventory.interface.js +1 -0
- package/dist/core/interface/nexine.interface.d.ts +5 -0
- package/dist/core/interface/nexine.interface.d.ts.map +1 -0
- package/dist/core/interface/nexine.interface.js +1 -0
- package/dist/core/interface/prisma.interface.d.ts +8404 -0
- package/dist/core/interface/prisma.interface.d.ts.map +1 -0
- package/dist/core/interface/prisma.interface.js +1227 -0
- package/dist/core/interface/product.interface.d.ts +100 -0
- package/dist/core/interface/product.interface.d.ts.map +1 -0
- package/dist/core/interface/product.interface.js +1 -0
- package/dist/core/raxon.context.d.ts +44 -0
- package/dist/core/raxon.context.d.ts.map +1 -0
- package/dist/core/raxon.context.js +90 -0
- package/dist/core/schema/checkout.schema.d.ts +46 -0
- package/dist/core/schema/checkout.schema.d.ts.map +1 -0
- package/dist/core/schema/checkout.schema.js +83 -0
- package/dist/core/util/basket.item.display.d.ts +3 -0
- package/dist/core/util/basket.item.display.d.ts.map +1 -0
- package/dist/core/util/basket.item.display.js +18 -0
- package/dist/core/util/category.nav.d.ts +9 -0
- package/dist/core/util/category.nav.d.ts.map +1 -0
- package/dist/core/util/category.nav.js +37 -0
- package/dist/core/util/client-ip.d.ts +2 -0
- package/dist/core/util/client-ip.d.ts.map +1 -0
- package/dist/core/util/client-ip.js +32 -0
- package/dist/core/util/collection.util.d.ts +31 -0
- package/dist/core/util/collection.util.d.ts.map +1 -0
- package/dist/core/util/collection.util.js +167 -0
- package/dist/core/util/garanti-payment.d.ts +2 -0
- package/dist/core/util/garanti-payment.d.ts.map +1 -0
- package/dist/core/util/garanti-payment.js +1 -0
- package/dist/core/util/nexine.axios.d.ts +2 -0
- package/dist/core/util/nexine.axios.d.ts.map +1 -0
- package/dist/core/util/nexine.axios.js +62 -0
- package/dist/core/util/no-cache.d.ts +6 -0
- package/dist/core/util/no-cache.d.ts.map +1 -0
- package/dist/core/util/no-cache.js +6 -0
- package/dist/core/util/util.d.ts +18 -0
- package/dist/core/util/util.d.ts.map +1 -0
- package/dist/core/util/util.js +163 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CartItem } from '@/core/interface/prisma.interface';
|
|
2
|
+
import { BasketSummaryInterface } from '@/core/interface/basket.interface';
|
|
3
|
+
import { IData } from '@/core/interface/nexine.interface';
|
|
4
|
+
export type BasketItemBulkInsertInput = {
|
|
5
|
+
id?: string;
|
|
6
|
+
productId?: string;
|
|
7
|
+
productUnitId?: string;
|
|
8
|
+
variantId?: string | null;
|
|
9
|
+
quantity?: number;
|
|
10
|
+
type?: 'increment' | 'decrement' | 'set';
|
|
11
|
+
};
|
|
12
|
+
export type BasketAddressInput = {
|
|
13
|
+
title?: string;
|
|
14
|
+
type?: string;
|
|
15
|
+
firstName?: string;
|
|
16
|
+
lastName?: string;
|
|
17
|
+
phoneNumber?: string;
|
|
18
|
+
postalCode?: string;
|
|
19
|
+
administrativeAreaLevel1?: string;
|
|
20
|
+
administrativeAreaLevel2?: string;
|
|
21
|
+
administrativeAreaLevel3?: string;
|
|
22
|
+
fullAddress?: string;
|
|
23
|
+
streetName?: string;
|
|
24
|
+
buildingName?: string | null;
|
|
25
|
+
apartmentNumber?: string | null;
|
|
26
|
+
companyName?: string;
|
|
27
|
+
taxNumber?: string;
|
|
28
|
+
country?: string;
|
|
29
|
+
countryCode?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare const useCart: () => {
|
|
32
|
+
fetch: (params?: {
|
|
33
|
+
promoCodeId?: string;
|
|
34
|
+
campaignId?: string;
|
|
35
|
+
deliveryMethodId?: string;
|
|
36
|
+
isEnabled: boolean;
|
|
37
|
+
}) => import("@tanstack/react-query").UseQueryResult<NoInfer<BasketSummaryInterface>, Error>;
|
|
38
|
+
insert: () => import("@tanstack/react-query").UseMutationResult<any, Error, any, any>;
|
|
39
|
+
generatePaymentUrl: () => import("@tanstack/react-query").UseMutationResult<any, Error, any, unknown>;
|
|
40
|
+
generateStripePaymentIntent: () => import("@tanstack/react-query").UseMutationResult<any, any, any, unknown>;
|
|
41
|
+
generateCashOnDeliveryPayment: () => import("@tanstack/react-query").UseMutationResult<any, any, any, unknown>;
|
|
42
|
+
pay: () => import("@tanstack/react-query").UseMutationResult<any, any, {
|
|
43
|
+
platform?: string;
|
|
44
|
+
webReturnUrl?: string;
|
|
45
|
+
}, unknown>;
|
|
46
|
+
bulkInsert: () => import("@tanstack/react-query").UseMutationResult<import("axios").AxiosResponse<IData<CartItem[]>, any, {}>, any, BasketItemBulkInsertInput[], unknown>;
|
|
47
|
+
remove: () => import("@tanstack/react-query").UseMutationResult<import("axios").AxiosResponse<CartItem, any, {}>, Error, string, any>;
|
|
48
|
+
update: () => import("@tanstack/react-query").UseMutationResult<BasketSummaryInterface, any, {
|
|
49
|
+
id: string;
|
|
50
|
+
email?: string;
|
|
51
|
+
invoiceAddressId?: string | null;
|
|
52
|
+
deliveryAddressId?: string | null;
|
|
53
|
+
deliveryMethodId?: string | null;
|
|
54
|
+
paymentMethodId?: string | null;
|
|
55
|
+
promoCodeId?: string | null;
|
|
56
|
+
campaignId?: string | null;
|
|
57
|
+
deliveryAddress?: BasketAddressInput;
|
|
58
|
+
invoiceAddress?: BasketAddressInput;
|
|
59
|
+
bankTransferCodeId?: string | null;
|
|
60
|
+
}, unknown>;
|
|
61
|
+
updateItem: () => import("@tanstack/react-query").UseMutationResult<BasketSummaryInterface, Error, {
|
|
62
|
+
id: string;
|
|
63
|
+
quantity: number;
|
|
64
|
+
productId?: string;
|
|
65
|
+
}, any>;
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=use.cart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.cart.d.ts","sourceRoot":"","sources":["../../../../../core/feature/cart/hook/use.cart.tsx"],"names":[],"mappings":"AACA,OAAO,EAAQ,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAGnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,C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;sBACjB,MAAM,GAAG,IAAI;qBACd,MAAM,GAAG,IAAI;0BACR,kBAAkB;yBACnB,kBAAkB;6BACd,MAAM,GAAG,IAAI;;;YAcL,MAAM;kBAAY,MAAM;oBAAc,MAAM;;CAqBlF,CAAC"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { nexineAxios } from '@/core/util/nexine.axios';
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { globalEmitter, GLOBAL_EVENTS } from '@/core/util/util';
|
|
4
|
+
import { mergeCartWithOptimisticExtras, applyBasketInsertResponse, readCartCache, patchCartCache, CART_QUERY_KEY } from '@/core/feature/cart/util/cart-optimistic';
|
|
5
|
+
export const useCart = () => {
|
|
6
|
+
const queryClient = useQueryClient();
|
|
7
|
+
const handleUnauthorizedError = (error) => {
|
|
8
|
+
if (error?.response?.status === 401) {
|
|
9
|
+
globalEmitter.emit(GLOBAL_EVENTS.SHOW_LOGIN_MODAL, {
|
|
10
|
+
message: 'Oturum süreniz dolmuş. Lütfen tekrar giriş yapın.',
|
|
11
|
+
source: 'cart_operation',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
fetch: (params) => {
|
|
17
|
+
return useQuery({
|
|
18
|
+
queryKey: [...CART_QUERY_KEY],
|
|
19
|
+
staleTime: 15_000,
|
|
20
|
+
refetchOnWindowFocus: false,
|
|
21
|
+
enabled: params?.isEnabled,
|
|
22
|
+
queryFn: async () => {
|
|
23
|
+
const response = await nexineAxios.get('/customer/basket/me', {
|
|
24
|
+
params: {
|
|
25
|
+
promoCodeId: params?.promoCodeId,
|
|
26
|
+
campaignId: params?.campaignId,
|
|
27
|
+
deliveryMethodId: params?.deliveryMethodId,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const serverCart = response.data;
|
|
31
|
+
const cachedCart = readCartCache(queryClient);
|
|
32
|
+
if (!serverCart?.items?.length) {
|
|
33
|
+
return cachedCart?.items?.length ? cachedCart : serverCart;
|
|
34
|
+
}
|
|
35
|
+
return mergeCartWithOptimisticExtras(serverCart, cachedCart ?? undefined);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
insert: () => {
|
|
40
|
+
return useMutation({
|
|
41
|
+
mutationFn: async (data) => {
|
|
42
|
+
const response = await nexineAxios.post('/customer/basket/me/item', data);
|
|
43
|
+
return response.data;
|
|
44
|
+
},
|
|
45
|
+
onError: (error, _newData, context) => {
|
|
46
|
+
if (context?.previousCarts) {
|
|
47
|
+
context.previousCarts.forEach(([key, value]) => {
|
|
48
|
+
queryClient.setQueryData(key, value);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
handleUnauthorizedError(error);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
generatePaymentUrl: () => {
|
|
56
|
+
return useMutation({
|
|
57
|
+
mutationFn: async (data) => {
|
|
58
|
+
try {
|
|
59
|
+
var response = await nexineAxios.post('/customer/basket/pay/paytr', data);
|
|
60
|
+
return response.data;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.log(error);
|
|
64
|
+
handleUnauthorizedError(error);
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
generateStripePaymentIntent: () => {
|
|
71
|
+
return useMutation({
|
|
72
|
+
mutationFn: async (data) => {
|
|
73
|
+
var response = await nexineAxios.post('/customer/basket/pay/stripe', data);
|
|
74
|
+
return response.data;
|
|
75
|
+
},
|
|
76
|
+
onError: handleUnauthorizedError,
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
generateCashOnDeliveryPayment: () => {
|
|
80
|
+
return useMutation({
|
|
81
|
+
mutationFn: async (data) => {
|
|
82
|
+
var response = await nexineAxios.post('/customer/basket/pay/cash-on-delivery', data);
|
|
83
|
+
return response.data;
|
|
84
|
+
},
|
|
85
|
+
onError: handleUnauthorizedError,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
pay: () => {
|
|
89
|
+
return useMutation({
|
|
90
|
+
mutationFn: async (data) => {
|
|
91
|
+
const response = await nexineAxios.post('/customer/basket/me/pay', {
|
|
92
|
+
platform: data?.platform ?? 'web',
|
|
93
|
+
webReturnUrl: data?.webReturnUrl ?? window.location.href,
|
|
94
|
+
});
|
|
95
|
+
return response.data;
|
|
96
|
+
},
|
|
97
|
+
onError: handleUnauthorizedError,
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
bulkInsert: () => {
|
|
101
|
+
return useMutation({
|
|
102
|
+
mutationFn: (data) => {
|
|
103
|
+
return nexineAxios.patch('/customer/basket/me/item', data);
|
|
104
|
+
},
|
|
105
|
+
onSuccess: () => {
|
|
106
|
+
queryClient.invalidateQueries({ queryKey: ['organization', 'cart'] });
|
|
107
|
+
},
|
|
108
|
+
onError: handleUnauthorizedError,
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
remove: () => {
|
|
112
|
+
return useMutation({
|
|
113
|
+
mutationFn: (id) => {
|
|
114
|
+
return nexineAxios.delete(`/customer/basket/me/item/${id}`);
|
|
115
|
+
},
|
|
116
|
+
onMutate: async (id) => {
|
|
117
|
+
await queryClient.cancelQueries({ queryKey: ['organization', 'cart'] });
|
|
118
|
+
const previousCarts = queryClient.getQueriesData({ queryKey: ['organization', 'cart'] });
|
|
119
|
+
queryClient.setQueriesData({ queryKey: CART_QUERY_KEY }, (old) => {
|
|
120
|
+
if (!old || !old.items)
|
|
121
|
+
return old;
|
|
122
|
+
const removedItem = old.items.find((item) => String(item.id) === String(id));
|
|
123
|
+
const priceDiff = removedItem ? -Number(removedItem.linePay || 0) : 0;
|
|
124
|
+
const updatedItems = old.items.filter((item) => String(item.id) !== String(id));
|
|
125
|
+
const newGesamt = updatedItems.reduce((sum, item) => sum + Number(item.quantity || 0), 0);
|
|
126
|
+
const newTotal = Number(old.info?.payPrice?.total || 0) + priceDiff;
|
|
127
|
+
const newPay = Number(old.info?.payPrice?.pay || 0) + priceDiff;
|
|
128
|
+
return {
|
|
129
|
+
...old,
|
|
130
|
+
items: updatedItems,
|
|
131
|
+
info: {
|
|
132
|
+
...old.info,
|
|
133
|
+
count: {
|
|
134
|
+
...old.info?.count,
|
|
135
|
+
Gesamt: newGesamt,
|
|
136
|
+
Artikel: updatedItems.length,
|
|
137
|
+
},
|
|
138
|
+
payPrice: {
|
|
139
|
+
...old.info?.payPrice,
|
|
140
|
+
total: newTotal,
|
|
141
|
+
pay: newPay,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
return { previousCarts };
|
|
147
|
+
},
|
|
148
|
+
onSuccess: () => {
|
|
149
|
+
queryClient.invalidateQueries({ queryKey: ['organization', 'cart'] });
|
|
150
|
+
},
|
|
151
|
+
onError: (error, id, context) => {
|
|
152
|
+
if (context?.previousCarts) {
|
|
153
|
+
context.previousCarts.forEach(([key, value]) => {
|
|
154
|
+
queryClient.setQueryData(key, value);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
handleUnauthorizedError(error);
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
update: () => {
|
|
162
|
+
return useMutation({
|
|
163
|
+
mutationFn: async (data) => {
|
|
164
|
+
const response = await nexineAxios.put('/customer/basket', data);
|
|
165
|
+
return response.data;
|
|
166
|
+
},
|
|
167
|
+
onSuccess: () => {
|
|
168
|
+
queryClient.invalidateQueries({ queryKey: ['organization', 'cart'] });
|
|
169
|
+
},
|
|
170
|
+
onError: handleUnauthorizedError,
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
updateItem: () => {
|
|
174
|
+
return useMutation({
|
|
175
|
+
mutationFn: async (data) => {
|
|
176
|
+
const response = await nexineAxios.put(`/customer/basket/me/item`, {
|
|
177
|
+
itemId: data.id,
|
|
178
|
+
quantity: Number(data.quantity || 0),
|
|
179
|
+
});
|
|
180
|
+
return response.data;
|
|
181
|
+
},
|
|
182
|
+
onSuccess: (data) => {
|
|
183
|
+
patchCartCache(queryClient, (old) => applyBasketInsertResponse(data, old));
|
|
184
|
+
},
|
|
185
|
+
onError: (error, _newData, context) => {
|
|
186
|
+
if (context?.previousCarts) {
|
|
187
|
+
context.previousCarts.forEach(([key, value]) => {
|
|
188
|
+
queryClient.setQueryData(key, value);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
handleUnauthorizedError(error);
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type BasketPayResponse = {
|
|
2
|
+
status?: boolean | string;
|
|
3
|
+
success?: boolean;
|
|
4
|
+
info?: Record<string, unknown> | null;
|
|
5
|
+
data?: Record<string, unknown> | null;
|
|
6
|
+
provider?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function parseBasketPayResponse(response: unknown): {
|
|
9
|
+
ok: boolean;
|
|
10
|
+
provider: string;
|
|
11
|
+
html: string;
|
|
12
|
+
transactionId: string;
|
|
13
|
+
token: string;
|
|
14
|
+
orderId: string;
|
|
15
|
+
url: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function isGarantiPayResponse(provider: string | null): boolean;
|
|
18
|
+
/** Provider alanı eksik gelse bile Garanti HTML yanıtını tanı */
|
|
19
|
+
export declare function isGarantiPayFlow(provider: string | null, html: string | null, transactionId: string | null): boolean;
|
|
20
|
+
//# sourceMappingURL=basket-pay.response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basket-pay.response.d.ts","sourceRoot":"","sources":["../../../../../core/feature/cart/util/basket-pay.response.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAWF,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,OAAO;;;;;;;;EAiCvD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,WAE3D;AAED,iEAAiE;AACjE,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,aAAa,EAAE,MAAM,GAAG,IAAI,WAI7B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PaymentProvider } from '@/core/interface/prisma.interface';
|
|
2
|
+
function readString(source, ...keys) {
|
|
3
|
+
if (!source)
|
|
4
|
+
return null;
|
|
5
|
+
for (const key of keys) {
|
|
6
|
+
const value = source[key];
|
|
7
|
+
if (typeof value === 'string' && value.trim())
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
export function parseBasketPayResponse(response) {
|
|
13
|
+
const payload = response && typeof response === 'object' ? response : {};
|
|
14
|
+
const ok = payload.status === true ||
|
|
15
|
+
payload.status === 'true' ||
|
|
16
|
+
payload.success === true;
|
|
17
|
+
const info = payload.info && typeof payload.info === 'object' ? payload.info : null;
|
|
18
|
+
const data = payload.data && typeof payload.data === 'object' ? payload.data : null;
|
|
19
|
+
const root = payload;
|
|
20
|
+
const provider = readString(info, 'provider', 'paymentProvider') ||
|
|
21
|
+
readString(data, 'provider', 'paymentProvider') ||
|
|
22
|
+
readString(root, 'provider', 'paymentProvider');
|
|
23
|
+
const html = readString(info, 'html', 'formHtml', 'paymentHtml') ||
|
|
24
|
+
readString(data, 'html', 'formHtml', 'paymentHtml');
|
|
25
|
+
const transactionId = readString(info, 'transactionId', 'transaction_id', 'id') ||
|
|
26
|
+
readString(data, 'transactionId', 'transaction_id', 'id');
|
|
27
|
+
const token = readString(info, 'token') || readString(data, 'token');
|
|
28
|
+
const orderId = readString(info, 'orderId', 'order_id') || readString(data, 'orderId', 'order_id');
|
|
29
|
+
const url = readString(info, 'url', 'redirectUrl') || readString(data, 'url', 'redirectUrl');
|
|
30
|
+
return { ok, provider, html, transactionId, token, orderId, url };
|
|
31
|
+
}
|
|
32
|
+
export function isGarantiPayResponse(provider) {
|
|
33
|
+
return provider === PaymentProvider.GARANTI || provider?.toUpperCase() === 'GARANTI';
|
|
34
|
+
}
|
|
35
|
+
/** Provider alanı eksik gelse bile Garanti HTML yanıtını tanı */
|
|
36
|
+
export function isGarantiPayFlow(provider, html, transactionId) {
|
|
37
|
+
if (!html || !transactionId)
|
|
38
|
+
return false;
|
|
39
|
+
return isGarantiPayResponse(provider) || /<form/i.test(html);
|
|
40
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BasketItemSummaryInterface, BasketSummaryInterface } from '@/core/interface/basket.interface';
|
|
2
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
export declare const CART_QUERY_KEY: readonly ["organization", "cart"];
|
|
4
|
+
export declare const CART_QUANTITY_DEBOUNCE_MS = 400;
|
|
5
|
+
export declare function createEmptyOptimisticCart(): BasketSummaryInterface;
|
|
6
|
+
export interface PendingCartAdd {
|
|
7
|
+
productId: string;
|
|
8
|
+
variantId?: string;
|
|
9
|
+
quantity: number;
|
|
10
|
+
linePay?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function unionMergeCarts(carts: (BasketSummaryInterface | undefined)[]): BasketSummaryInterface | undefined;
|
|
13
|
+
export declare function readCartCache(queryClient: QueryClient): BasketSummaryInterface | undefined;
|
|
14
|
+
export declare function patchCartCache(queryClient: QueryClient, updater: (old: BasketSummaryInterface | undefined) => BasketSummaryInterface): void;
|
|
15
|
+
export declare function cartLineKey(productId: string | number, variantId?: string | number | null): string;
|
|
16
|
+
export declare function cartLineIdentity(item: BasketItemSummaryInterface): string;
|
|
17
|
+
export declare function findCartLine(cart: BasketSummaryInterface | null | undefined, productId: string | number, variantId?: string | number | null): BasketItemSummaryInterface;
|
|
18
|
+
export declare function findConfirmedCartLine(cart: BasketSummaryInterface | null | undefined, productId: string | number, variantId?: string | number | null): BasketItemSummaryInterface;
|
|
19
|
+
export declare function isFullBasketSnapshot(basket: BasketSummaryInterface, cached?: BasketSummaryInterface): boolean;
|
|
20
|
+
export declare function mergeCartWithOptimisticExtras(server: BasketSummaryInterface, cached?: BasketSummaryInterface): BasketSummaryInterface;
|
|
21
|
+
export declare function applyBasketInsertResponse(basket: BasketSummaryInterface, cached?: BasketSummaryInterface): BasketSummaryInterface;
|
|
22
|
+
export declare function removeCartLineByKey(cart: BasketSummaryInterface, lineKey: string): BasketSummaryInterface;
|
|
23
|
+
export declare function createOptimisticCartLine(add: PendingCartAdd): BasketItemSummaryInterface;
|
|
24
|
+
export declare function applyPendingAdds(cart: BasketSummaryInterface, pendingAdds: Record<string, PendingCartAdd>): BasketSummaryInterface;
|
|
25
|
+
export declare function extractBasketFromInsertResponse(data: unknown): BasketSummaryInterface | null;
|
|
26
|
+
export interface InsertCartItemResponse {
|
|
27
|
+
id: string;
|
|
28
|
+
productId: string;
|
|
29
|
+
variantId?: string | null;
|
|
30
|
+
quantity: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function extractInsertCartItem(data: unknown): InsertCartItemResponse | null;
|
|
33
|
+
export declare function mergeInsertItemIntoCart(cart: BasketSummaryInterface, insertItem: InsertCartItemResponse, pendingAdd?: PendingCartAdd): BasketSummaryInterface;
|
|
34
|
+
export declare function patchCartItemQuantity(cart: BasketSummaryInterface, itemId: string, quantity: number, productId?: string, variantId?: string | number | null): BasketSummaryInterface;
|
|
35
|
+
export declare function applyPendingQuantities(cart: BasketSummaryInterface, pendingQuantities: Record<string, number>): BasketSummaryInterface;
|
|
36
|
+
//# sourceMappingURL=cart-optimistic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart-optimistic.d.ts","sourceRoot":"","sources":["../../../../../core/feature/cart/util/cart-optimistic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAEvG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,eAAO,MAAM,cAAc,mCAAoC,CAAC;AAEhE,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAE7C,wBAAgB,yBAAyB,IAAI,sBAAsB,CAiBlE;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,CAAC,sBAAsB,GAAG,SAAS,CAAC,EAAE,GAAG,sBAAsB,GAAG,SAAS,CAiCjH;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,sBAAsB,GAAG,SAAS,CAK1F;AAED,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,CAAC,GAAG,EAAE,sBAAsB,GAAG,SAAS,KAAK,sBAAsB,QAG7E;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,UAEzF;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,0BAA0B,UAGhE;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,EAC/C,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,SAAS,CAAC,EAAE,MAAM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