@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,25 @@
|
|
|
1
|
+
interface GeneralImageProps {
|
|
2
|
+
src?: string;
|
|
3
|
+
alt: string;
|
|
4
|
+
width?: number;
|
|
5
|
+
height?: number;
|
|
6
|
+
className?: string;
|
|
7
|
+
fill?: boolean;
|
|
8
|
+
aspectRatio?: string;
|
|
9
|
+
style?: React.CSSProperties;
|
|
10
|
+
wrapperClassName?: string;
|
|
11
|
+
sizes?: string;
|
|
12
|
+
priority?: boolean;
|
|
13
|
+
quality?: number;
|
|
14
|
+
placeholder?: 'blur' | 'empty';
|
|
15
|
+
blurDataURL?: string;
|
|
16
|
+
onLoad?: () => void;
|
|
17
|
+
onError?: () => void;
|
|
18
|
+
loading?: 'lazy' | 'eager';
|
|
19
|
+
fetchPriority?: 'low' | 'high';
|
|
20
|
+
objectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
21
|
+
fallback?: 'placeholder' | 'hide' | 'error';
|
|
22
|
+
}
|
|
23
|
+
declare const GeneralImage: (props: GeneralImageProps) => import("react").JSX.Element;
|
|
24
|
+
export { GeneralImage };
|
|
25
|
+
//# sourceMappingURL=general.image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"general.image.d.ts","sourceRoot":"","sources":["../../../core/component/general.image.tsx"],"names":[],"mappings":"AAKA,UAAU,iBAAiB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IAEZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC/B,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;IACjE,QAAQ,CAAC,EAAE,aAAa,GAAG,MAAM,GAAG,OAAO,CAAC;CAC7C;AAED,QAAA,MAAM,YAAY,GAAI,OAAO,iBAAiB,gCAsD7C,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import Image from 'next/image';
|
|
5
|
+
const GeneralImage = (props) => {
|
|
6
|
+
// Placeholder image URL
|
|
7
|
+
const placeholderImage = 'https://placehold.co/600x400';
|
|
8
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
9
|
+
if (!props.src) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
let mageData = (_jsxs(_Fragment, { children: [isLoading && (_jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-gray-100", children: _jsx("div", { className: "animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" }) })), _jsx(Image, { placeholder: "empty", src: props.src, alt: props.alt, fill: props.fill, style: {
|
|
13
|
+
...props.style,
|
|
14
|
+
opacity: isLoading ? 0 : 1,
|
|
15
|
+
transition: 'opacity 0.3s ease-in-out'
|
|
16
|
+
}, className: props.className, width: props.width, height: props.height, priority: props.priority, quality: props.quality ?? 80, objectFit: props.objectFit, fetchPriority: props.fetchPriority, onLoad: () => {
|
|
17
|
+
setIsLoading(false);
|
|
18
|
+
props.onLoad?.();
|
|
19
|
+
}, onError: () => {
|
|
20
|
+
setIsLoading(false);
|
|
21
|
+
props.onError?.();
|
|
22
|
+
} })] }));
|
|
23
|
+
if (props.aspectRatio) {
|
|
24
|
+
return (_jsx(_Fragment, { children: _jsx("div", { className: `aspect-[${props.aspectRatio}] ${props.wrapperClassName}`, children: mageData }) }));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return mageData;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export { GeneralImage };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BasketSummaryInterface } from '@/core/interface/basket.interface';
|
|
2
|
+
import { PromoCode } from '@/core/interface/prisma.interface';
|
|
3
|
+
interface CartContextType {
|
|
4
|
+
cart: BasketSummaryInterface | null;
|
|
5
|
+
cartLoading: boolean;
|
|
6
|
+
isAddingToCart: boolean;
|
|
7
|
+
isUpdatingCart: boolean;
|
|
8
|
+
isProductAdding: (productId: string | number, variantId?: string | number | null) => boolean;
|
|
9
|
+
addToCart: (productId: string | number, quantity: number, variantId?: string | number, options?: {
|
|
10
|
+
linePay?: number;
|
|
11
|
+
}) => void;
|
|
12
|
+
updateQuantity: (itemId: string | number, quantity: number, productId?: string) => void;
|
|
13
|
+
changeQuantity: (itemId: string | number, delta: number, productId?: string, variantId?: string | number | null) => void;
|
|
14
|
+
removeItem: (itemId: string | number) => void;
|
|
15
|
+
cartTotal: number;
|
|
16
|
+
promoCode: PromoCode | null;
|
|
17
|
+
setPromoCode: (promoCode: PromoCode | null) => void;
|
|
18
|
+
}
|
|
19
|
+
export declare const CartContext: import("react").Context<CartContextType>;
|
|
20
|
+
export declare const CartProvider: ({ children }: {
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
}) => import("react").JSX.Element;
|
|
23
|
+
export declare const useCartContext: () => CartContextType;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=cart.context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart.context.d.ts","sourceRoot":"","sources":["../../../core/context/cart.context.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAiC9D,UAAU,eAAe;IACvB,IAAI,EAAE,sBAAsB,GAAG,IAAI,CAAC;IACpC,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;IACxB,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC;IAC7F,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC/H,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACxF,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACzH,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,CAAC;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;CACrD;AAED,eAAO,MAAM,WAAW,0CAAwD,CAAC;AAEjF,eAAO,MAAM,YAAY,GAAI,cAAc;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,gCA6YvE,CAAC;AAEF,eAAO,MAAM,cAAc,uBAM1B,CAAC"}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
5
|
+
import { useCart } from '@/core/feature/cart/hook/use.cart';
|
|
6
|
+
import { useSecurity } from '@/core/context/security.context';
|
|
7
|
+
import toast from 'react-hot-toast';
|
|
8
|
+
import { applyPendingAdds, applyPendingQuantities, cartLineKey, CART_QUANTITY_DEBOUNCE_MS, createEmptyOptimisticCart, extractBasketFromInsertResponse, extractInsertCartItem, findCartLine, applyBasketInsertResponse, mergeInsertItemIntoCart, patchCartCache, patchCartItemQuantity, readCartCache, removeCartLineByKey, } from '@/core/feature/cart/util/cart-optimistic';
|
|
9
|
+
export const CartContext = createContext(undefined);
|
|
10
|
+
export const CartProvider = ({ children }) => {
|
|
11
|
+
const { isAuthenticated } = useSecurity();
|
|
12
|
+
const queryClient = useQueryClient();
|
|
13
|
+
const [promoCode, setPromoCode] = useState(null);
|
|
14
|
+
const [pendingQuantities, setPendingQuantities] = useState({});
|
|
15
|
+
const [pendingAdds, setPendingAdds] = useState({});
|
|
16
|
+
const [addingKeys, setAddingKeys] = useState({});
|
|
17
|
+
const pendingUpdatesRef = useRef(new Map());
|
|
18
|
+
const debounceTimersRef = useRef(new Map());
|
|
19
|
+
const pendingAddsRef = useRef({});
|
|
20
|
+
const pendingQuantitiesRef = useRef({});
|
|
21
|
+
const insertQueueRef = useRef(Promise.resolve());
|
|
22
|
+
const cancelledInsertKeysRef = useRef(new Set());
|
|
23
|
+
const displayCartRef = useRef(null);
|
|
24
|
+
const cartHook = useCart();
|
|
25
|
+
const { data: cart, isLoading: cartLoading } = cartHook.fetch({
|
|
26
|
+
isEnabled: isAuthenticated,
|
|
27
|
+
});
|
|
28
|
+
const insertMutation = cartHook.insert();
|
|
29
|
+
const updateItemMutation = cartHook.updateItem();
|
|
30
|
+
const removeMutation = cartHook.remove();
|
|
31
|
+
const isUpdatingCart = updateItemMutation.isPending || removeMutation.isPending;
|
|
32
|
+
const isAddingToCart = Object.keys(addingKeys).length > 0 || insertMutation.isPending;
|
|
33
|
+
const serverCart = useMemo(() => readCartCache(queryClient) ?? cart, [cart, queryClient]);
|
|
34
|
+
const displayCart = useMemo(() => {
|
|
35
|
+
if (!serverCart && Object.keys(pendingAdds).length === 0)
|
|
36
|
+
return null;
|
|
37
|
+
const base = serverCart ?? createEmptyOptimisticCart();
|
|
38
|
+
let result = base;
|
|
39
|
+
if (Object.keys(pendingAdds).length > 0) {
|
|
40
|
+
result = applyPendingAdds(result, pendingAdds);
|
|
41
|
+
}
|
|
42
|
+
if (Object.keys(pendingQuantities).length > 0) {
|
|
43
|
+
result = applyPendingQuantities(result, pendingQuantities);
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}, [serverCart, pendingAdds, pendingQuantities]);
|
|
47
|
+
displayCartRef.current = displayCart;
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
pendingAddsRef.current = pendingAdds;
|
|
50
|
+
}, [pendingAdds]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
pendingQuantitiesRef.current = pendingQuantities;
|
|
53
|
+
}, [pendingQuantities]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!cart)
|
|
56
|
+
return;
|
|
57
|
+
if (cart.promoCode?.id) {
|
|
58
|
+
setPromoCode((prev) => (prev?.id === cart.promoCode?.id ? prev : cart.promoCode));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!cart.promoCode?.id) {
|
|
62
|
+
setPromoCode(null);
|
|
63
|
+
}
|
|
64
|
+
}, [cart?.promoCode?.id, cart?.promoCode?.code]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
return () => {
|
|
67
|
+
debounceTimersRef.current.forEach((timer) => clearTimeout(timer));
|
|
68
|
+
debounceTimersRef.current.clear();
|
|
69
|
+
};
|
|
70
|
+
}, []);
|
|
71
|
+
const isProductAdding = (productId, variantId) => {
|
|
72
|
+
return Boolean(addingKeys[cartLineKey(productId, variantId)]);
|
|
73
|
+
};
|
|
74
|
+
const setAdding = (key, value) => {
|
|
75
|
+
setAddingKeys((prev) => {
|
|
76
|
+
if (value)
|
|
77
|
+
return { ...prev, [key]: true };
|
|
78
|
+
if (!(key in prev))
|
|
79
|
+
return prev;
|
|
80
|
+
const next = { ...prev };
|
|
81
|
+
delete next[key];
|
|
82
|
+
return next;
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const applyLocalQuantity = (itemId, quantity) => {
|
|
86
|
+
setPendingQuantities((prev) => {
|
|
87
|
+
const next = { ...prev, [itemId]: quantity };
|
|
88
|
+
pendingQuantitiesRef.current = next;
|
|
89
|
+
return next;
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const getLineQuantity = (itemId) => {
|
|
93
|
+
if (itemId in pendingQuantitiesRef.current) {
|
|
94
|
+
return Number(pendingQuantitiesRef.current[itemId]);
|
|
95
|
+
}
|
|
96
|
+
if (itemId.startsWith('optimistic-')) {
|
|
97
|
+
const key = itemId.replace('optimistic-', '');
|
|
98
|
+
const add = pendingAddsRef.current[key];
|
|
99
|
+
if (add)
|
|
100
|
+
return Number(add.quantity);
|
|
101
|
+
}
|
|
102
|
+
const item = displayCartRef.current?.items?.find((line) => String(line.id) === itemId);
|
|
103
|
+
return Number(item?.quantity || 0);
|
|
104
|
+
};
|
|
105
|
+
const clearPendingQuantity = (itemId) => {
|
|
106
|
+
setPendingQuantities((prev) => {
|
|
107
|
+
if (!(itemId in prev))
|
|
108
|
+
return prev;
|
|
109
|
+
const next = { ...prev };
|
|
110
|
+
delete next[itemId];
|
|
111
|
+
return next;
|
|
112
|
+
});
|
|
113
|
+
pendingUpdatesRef.current.delete(itemId);
|
|
114
|
+
const timer = debounceTimersRef.current.get(itemId);
|
|
115
|
+
if (timer) {
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
debounceTimersRef.current.delete(itemId);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const flushQuantityUpdate = (itemId) => {
|
|
121
|
+
const pending = pendingUpdatesRef.current.get(itemId);
|
|
122
|
+
if (!pending)
|
|
123
|
+
return;
|
|
124
|
+
pendingUpdatesRef.current.delete(itemId);
|
|
125
|
+
debounceTimersRef.current.delete(itemId);
|
|
126
|
+
updateItemMutation.mutate({ id: itemId, quantity: pending.quantity, productId: pending.productId }, {
|
|
127
|
+
onSuccess: (data) => {
|
|
128
|
+
patchCartCache(queryClient, (old) => applyBasketInsertResponse(data, old));
|
|
129
|
+
if (!pendingUpdatesRef.current.has(itemId)) {
|
|
130
|
+
setPendingQuantities((prev) => {
|
|
131
|
+
if (!(itemId in prev))
|
|
132
|
+
return prev;
|
|
133
|
+
const next = { ...prev };
|
|
134
|
+
delete next[itemId];
|
|
135
|
+
return next;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
onError: (error) => {
|
|
140
|
+
queryClient.invalidateQueries({ queryKey: ['organization', 'cart'] });
|
|
141
|
+
setPendingQuantities((prev) => {
|
|
142
|
+
if (!(itemId in prev))
|
|
143
|
+
return prev;
|
|
144
|
+
const next = { ...prev };
|
|
145
|
+
delete next[itemId];
|
|
146
|
+
return next;
|
|
147
|
+
});
|
|
148
|
+
toast.error(error?.response?.data?.info?.message || 'Hata oluştu');
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
const applyInsertSuccess = (response, key, productId) => {
|
|
153
|
+
if (cancelledInsertKeysRef.current.has(key)) {
|
|
154
|
+
cancelledInsertKeysRef.current.delete(key);
|
|
155
|
+
const insertItem = extractInsertCartItem(response);
|
|
156
|
+
if (insertItem?.id) {
|
|
157
|
+
removeMutation.mutate(insertItem.id);
|
|
158
|
+
}
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const pendingAdd = pendingAddsRef.current[key];
|
|
162
|
+
const pendingQuantity = pendingAdd?.quantity ?? 1;
|
|
163
|
+
const basket = extractBasketFromInsertResponse(response);
|
|
164
|
+
const insertItem = extractInsertCartItem(response);
|
|
165
|
+
if (basket) {
|
|
166
|
+
patchCartCache(queryClient, (old) => applyBasketInsertResponse(basket, old));
|
|
167
|
+
}
|
|
168
|
+
else if (insertItem) {
|
|
169
|
+
patchCartCache(queryClient, (old) => {
|
|
170
|
+
const base = old ?? createEmptyOptimisticCart();
|
|
171
|
+
return mergeInsertItemIntoCart(base, insertItem, pendingAdd ? { ...pendingAdd, quantity: pendingQuantity } : undefined);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
queryClient.invalidateQueries({ queryKey: ['organization', 'cart'] });
|
|
176
|
+
}
|
|
177
|
+
if (insertItem || basket) {
|
|
178
|
+
const updatedCart = readCartCache(queryClient);
|
|
179
|
+
if (findCartLine(updatedCart, productId, pendingAdd?.variantId)) {
|
|
180
|
+
setPendingAdds((prev) => {
|
|
181
|
+
if (!(key in prev))
|
|
182
|
+
return prev;
|
|
183
|
+
const next = { ...prev };
|
|
184
|
+
delete next[key];
|
|
185
|
+
pendingAddsRef.current = next;
|
|
186
|
+
return next;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (insertItem && pendingQuantity > insertItem.quantity) {
|
|
191
|
+
updateItemMutation.mutate({ id: insertItem.id, quantity: pendingQuantity, productId: String(productId) }, {
|
|
192
|
+
onSuccess: (data) => {
|
|
193
|
+
patchCartCache(queryClient, (old) => applyBasketInsertResponse(data, old));
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const enqueueInsert = (payload, key) => {
|
|
199
|
+
setAdding(key, true);
|
|
200
|
+
insertQueueRef.current = insertQueueRef.current
|
|
201
|
+
.then(() => insertMutation.mutateAsync(payload))
|
|
202
|
+
.then((response) => {
|
|
203
|
+
applyInsertSuccess(response, key, payload.productId);
|
|
204
|
+
})
|
|
205
|
+
.catch((error) => {
|
|
206
|
+
setPendingAdds((prev) => {
|
|
207
|
+
if (!(key in prev))
|
|
208
|
+
return prev;
|
|
209
|
+
const next = { ...prev };
|
|
210
|
+
delete next[key];
|
|
211
|
+
pendingAddsRef.current = next;
|
|
212
|
+
return next;
|
|
213
|
+
});
|
|
214
|
+
patchCartCache(queryClient, (old) => {
|
|
215
|
+
const base = old ?? createEmptyOptimisticCart();
|
|
216
|
+
return removeCartLineByKey(base, key);
|
|
217
|
+
});
|
|
218
|
+
queryClient.invalidateQueries({ queryKey: ['organization', 'cart'] });
|
|
219
|
+
toast.error(error?.response?.data?.info?.message || 'Sepete eklenirken bir hata oluştu');
|
|
220
|
+
})
|
|
221
|
+
.finally(() => {
|
|
222
|
+
setAdding(key, false);
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
const addToCart = (productId, quantity, variantId, options) => {
|
|
226
|
+
const key = cartLineKey(productId, variantId);
|
|
227
|
+
const existing = findCartLine(displayCart, productId, variantId);
|
|
228
|
+
if (existing) {
|
|
229
|
+
changeQuantity(existing.id, quantity, String(productId), variantId);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const pendingAdd = {
|
|
233
|
+
productId: String(productId),
|
|
234
|
+
variantId: variantId != null ? String(variantId) : undefined,
|
|
235
|
+
quantity,
|
|
236
|
+
linePay: options?.linePay,
|
|
237
|
+
};
|
|
238
|
+
const nextPending = { ...pendingAddsRef.current, [key]: pendingAdd };
|
|
239
|
+
pendingAddsRef.current = nextPending;
|
|
240
|
+
setPendingAdds(nextPending);
|
|
241
|
+
patchCartCache(queryClient, (old) => {
|
|
242
|
+
const base = old ?? createEmptyOptimisticCart();
|
|
243
|
+
return applyPendingAdds(base, { [key]: pendingAdd });
|
|
244
|
+
});
|
|
245
|
+
enqueueInsert({
|
|
246
|
+
productId,
|
|
247
|
+
quantity,
|
|
248
|
+
variantId,
|
|
249
|
+
type: 'increment',
|
|
250
|
+
deposit: 'disable',
|
|
251
|
+
linePay: options?.linePay,
|
|
252
|
+
}, key);
|
|
253
|
+
};
|
|
254
|
+
const updateQuantity = (itemId, quantity, productId, variantId) => {
|
|
255
|
+
const id = itemId.toString();
|
|
256
|
+
if (quantity < 1)
|
|
257
|
+
return;
|
|
258
|
+
if (id.startsWith('optimistic-')) {
|
|
259
|
+
const key = id.replace('optimistic-', '');
|
|
260
|
+
const currentAdd = pendingAddsRef.current[key];
|
|
261
|
+
if (!currentAdd)
|
|
262
|
+
return;
|
|
263
|
+
const nextAdd = { ...currentAdd, quantity };
|
|
264
|
+
const nextPending = { ...pendingAddsRef.current, [key]: nextAdd };
|
|
265
|
+
pendingAddsRef.current = nextPending;
|
|
266
|
+
setPendingAdds(nextPending);
|
|
267
|
+
patchCartCache(queryClient, (old) => {
|
|
268
|
+
const base = old ?? createEmptyOptimisticCart();
|
|
269
|
+
return applyPendingAdds(base, { [key]: nextAdd });
|
|
270
|
+
});
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
applyLocalQuantity(id, quantity);
|
|
274
|
+
patchCartCache(queryClient, (old) => {
|
|
275
|
+
const base = old ?? createEmptyOptimisticCart();
|
|
276
|
+
return patchCartItemQuantity(base, id, quantity, productId, variantId);
|
|
277
|
+
});
|
|
278
|
+
pendingUpdatesRef.current.set(id, { quantity, productId });
|
|
279
|
+
const existingTimer = debounceTimersRef.current.get(id);
|
|
280
|
+
if (existingTimer)
|
|
281
|
+
clearTimeout(existingTimer);
|
|
282
|
+
debounceTimersRef.current.set(id, setTimeout(() => flushQuantityUpdate(id), CART_QUANTITY_DEBOUNCE_MS));
|
|
283
|
+
};
|
|
284
|
+
const changeQuantity = (itemId, delta, productId, variantId) => {
|
|
285
|
+
const id = itemId.toString();
|
|
286
|
+
const nextQuantity = getLineQuantity(id) + delta;
|
|
287
|
+
if (nextQuantity < 1) {
|
|
288
|
+
removeItem(id);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
updateQuantity(id, nextQuantity, productId, variantId);
|
|
292
|
+
};
|
|
293
|
+
const removeItem = (itemId) => {
|
|
294
|
+
const id = itemId.toString();
|
|
295
|
+
clearPendingQuantity(id);
|
|
296
|
+
if (id.startsWith('optimistic-')) {
|
|
297
|
+
const key = id.replace('optimistic-', '');
|
|
298
|
+
cancelledInsertKeysRef.current.add(key);
|
|
299
|
+
setPendingAdds((prev) => {
|
|
300
|
+
if (!(key in prev))
|
|
301
|
+
return prev;
|
|
302
|
+
const next = { ...prev };
|
|
303
|
+
delete next[key];
|
|
304
|
+
return next;
|
|
305
|
+
});
|
|
306
|
+
setAdding(key, false);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
removeMutation.mutate(id, {
|
|
310
|
+
onSuccess: () => {
|
|
311
|
+
toast.success('Ürün sepetten çıkarıldı');
|
|
312
|
+
},
|
|
313
|
+
onError: (error) => {
|
|
314
|
+
toast.error(error?.response?.data?.info?.message || 'Silinirken hata oluştu');
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
return (_jsx(CartContext.Provider, { value: {
|
|
319
|
+
cart: displayCart,
|
|
320
|
+
cartLoading,
|
|
321
|
+
isAddingToCart,
|
|
322
|
+
isUpdatingCart,
|
|
323
|
+
isProductAdding,
|
|
324
|
+
addToCart,
|
|
325
|
+
updateQuantity,
|
|
326
|
+
changeQuantity,
|
|
327
|
+
removeItem,
|
|
328
|
+
cartTotal: displayCart?.info?.payPrice?.pay || 0,
|
|
329
|
+
promoCode,
|
|
330
|
+
setPromoCode,
|
|
331
|
+
}, children: children }));
|
|
332
|
+
};
|
|
333
|
+
export const useCartContext = () => {
|
|
334
|
+
const context = useContext(CartContext);
|
|
335
|
+
if (context === undefined) {
|
|
336
|
+
throw new Error('useCartContext must be used within an CartProvider');
|
|
337
|
+
}
|
|
338
|
+
return context;
|
|
339
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { User } from '@/core/interface/prisma.interface';
|
|
3
|
+
interface SecurityContextType {
|
|
4
|
+
profile: User | null | undefined;
|
|
5
|
+
isLoading: boolean;
|
|
6
|
+
isAuthenticated: boolean;
|
|
7
|
+
isGuest: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface SecurityProviderProps {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare const SecurityProvider: React.FC<SecurityProviderProps>;
|
|
13
|
+
export declare const useSecurity: () => SecurityContextType;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=security.context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.context.d.ts","sourceRoot":"","sources":["../../../core/context/security.context.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA+E,MAAM,OAAO,CAAC;AAEpG,OAAO,EAAa,IAAI,EAAE,MAAM,mCAAmC,CAAC;AAIpE,UAAU,mBAAmB;IAC3B,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;CAClB;AAID,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA6I5D,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,mBAM9B,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useEffect, useState, useCallback, useMemo } from 'react';
|
|
4
|
+
import { useRouter, usePathname } from 'next/navigation';
|
|
5
|
+
import { LoginType } from '@/core/interface/prisma.interface';
|
|
6
|
+
import { useAuth } from '@/core/feature/auth/hook/use.auth';
|
|
7
|
+
import { useProfile } from '@/core/feature/profile/hook/use.profile';
|
|
8
|
+
const SecurityContext = createContext(undefined);
|
|
9
|
+
export const SecurityProvider = ({ children }) => {
|
|
10
|
+
const router = useRouter();
|
|
11
|
+
const pathname = usePathname();
|
|
12
|
+
const [authLoading, setAuthLoading] = useState(true);
|
|
13
|
+
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
14
|
+
const [isAuthEstablished, setIsAuthEstablished] = useState(false);
|
|
15
|
+
const { mutate: tokenCheck } = useAuth().token();
|
|
16
|
+
const { mutate: loginGuest } = useAuth().loginGuest();
|
|
17
|
+
const profileQuery = useProfile().fetch({ isEnabled: isAuthEstablished && isAuthenticated });
|
|
18
|
+
const profile = profileQuery.data;
|
|
19
|
+
const isGuest = useMemo(() => {
|
|
20
|
+
return profile?.loginType === LoginType.GUEST;
|
|
21
|
+
}, [profile]);
|
|
22
|
+
const isInvalidTokenError = (error) => {
|
|
23
|
+
const status = error?.response?.status;
|
|
24
|
+
return status === 401 || status === 403;
|
|
25
|
+
};
|
|
26
|
+
const isServerAccessError = (error) => {
|
|
27
|
+
// axios: response yoksa çoğunlukla network/cors/offline; 5xx ise sunucu erişim sorunu
|
|
28
|
+
const status = error?.response?.status;
|
|
29
|
+
return !error?.response || (typeof status === 'number' && status >= 500);
|
|
30
|
+
};
|
|
31
|
+
const ensureGuestLogin = useCallback(() => {
|
|
32
|
+
loginGuest(undefined, {
|
|
33
|
+
onSuccess: () => {
|
|
34
|
+
setIsAuthEstablished(true);
|
|
35
|
+
setIsAuthenticated(true);
|
|
36
|
+
setAuthLoading(false);
|
|
37
|
+
},
|
|
38
|
+
onError: () => {
|
|
39
|
+
setIsAuthEstablished(false);
|
|
40
|
+
setIsAuthenticated(false);
|
|
41
|
+
setAuthLoading(false);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}, [loginGuest]);
|
|
45
|
+
const checkToken = useCallback(() => {
|
|
46
|
+
if (typeof window !== 'undefined') {
|
|
47
|
+
const token = localStorage.getItem('koksal-token');
|
|
48
|
+
if (token && token.trim() !== "" && token.length > 3) {
|
|
49
|
+
setAuthLoading(true);
|
|
50
|
+
tokenCheck(undefined, {
|
|
51
|
+
onSuccess: () => {
|
|
52
|
+
setIsAuthEstablished(true);
|
|
53
|
+
setIsAuthenticated(true);
|
|
54
|
+
setAuthLoading(false);
|
|
55
|
+
},
|
|
56
|
+
onError: (error) => {
|
|
57
|
+
// Sunucu erişim sorunu varsa token silme
|
|
58
|
+
if (isServerAccessError(error)) {
|
|
59
|
+
setIsAuthEstablished(true);
|
|
60
|
+
setIsAuthenticated(true);
|
|
61
|
+
setAuthLoading(false);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Token geçersizse misafir girişe düş
|
|
65
|
+
if (isInvalidTokenError(error)) {
|
|
66
|
+
localStorage.removeItem('koksal-token');
|
|
67
|
+
ensureGuestLogin();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Diğer hatalarda da token silmeden misafir girişe düş
|
|
71
|
+
ensureGuestLogin();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
setAuthLoading(true);
|
|
77
|
+
ensureGuestLogin();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}, [tokenCheck, ensureGuestLogin]);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
checkToken();
|
|
83
|
+
}, [checkToken]);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (typeof window !== 'undefined') {
|
|
86
|
+
const handleStorageChange = (e) => {
|
|
87
|
+
if (e.key === 'koksal-token') {
|
|
88
|
+
checkToken();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
// localStorage değişikliklerini dinle
|
|
92
|
+
window.addEventListener('storage', handleStorageChange);
|
|
93
|
+
// Aynı tab içindeki localStorage değişikliklerini dinlemek için custom event
|
|
94
|
+
const handleCustomStorageChange = () => {
|
|
95
|
+
checkToken();
|
|
96
|
+
};
|
|
97
|
+
window.addEventListener('koksal-token-changed', handleCustomStorageChange);
|
|
98
|
+
return () => {
|
|
99
|
+
window.removeEventListener('storage', handleStorageChange);
|
|
100
|
+
window.removeEventListener('koksal-token-changed', handleCustomStorageChange);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}, [checkToken]);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
// Loading durumunda yönlendirme yapma
|
|
106
|
+
const isLoading = authLoading || (isAuthEstablished && (profileQuery.isLoading || profileQuery.isFetching));
|
|
107
|
+
if (isLoading)
|
|
108
|
+
return;
|
|
109
|
+
if (pathname.startsWith('/guvenlik') && isAuthenticated && profile?.loginType !== LoginType.GUEST) {
|
|
110
|
+
router.push('/hesabim');
|
|
111
|
+
}
|
|
112
|
+
if (pathname.startsWith('/hesabim') && (!isAuthenticated || profile?.loginType === LoginType.GUEST)) {
|
|
113
|
+
router.push('/guvenlik/giris-yap');
|
|
114
|
+
}
|
|
115
|
+
}, [pathname, isAuthenticated, authLoading, isAuthEstablished, profileQuery.isLoading, profileQuery.isFetching, router]);
|
|
116
|
+
const isLoading = authLoading || (isAuthEstablished && (profileQuery.isLoading || profileQuery.isFetching));
|
|
117
|
+
return (_jsx(SecurityContext.Provider, { value: {
|
|
118
|
+
profile,
|
|
119
|
+
isLoading,
|
|
120
|
+
isAuthenticated,
|
|
121
|
+
isGuest,
|
|
122
|
+
}, children: children }));
|
|
123
|
+
};
|
|
124
|
+
export const useSecurity = () => {
|
|
125
|
+
const context = useContext(SecurityContext);
|
|
126
|
+
if (context === undefined) {
|
|
127
|
+
throw new Error('useSecurity must be used within an SecurityProvider');
|
|
128
|
+
}
|
|
129
|
+
return context;
|
|
130
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GooglePlacePrediction } from '@/core/feature/address/util/address.types';
|
|
2
|
+
interface AddressSearchInputProps {
|
|
3
|
+
query: string;
|
|
4
|
+
onQueryChange: (value: string) => void;
|
|
5
|
+
results: GooglePlacePrediction[];
|
|
6
|
+
isSearching: boolean;
|
|
7
|
+
showResults: boolean;
|
|
8
|
+
onShowResultsChange: (show: boolean) => void;
|
|
9
|
+
onSelect: (placeId: string) => void;
|
|
10
|
+
error?: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
placeholder: string;
|
|
13
|
+
noResultsText: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function AddressSearchInput({ query, onQueryChange, results, isSearching, showResults, onShowResultsChange, onSelect, error, label, placeholder, noResultsText, }: AddressSearchInputProps): import("react").JSX.Element;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=address-search-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address-search-input.d.ts","sourceRoot":"","sources":["../../../../../core/feature/address/form/address-search-input.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAElF,UAAU,uBAAuB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,OAAO,EAAE,qBAAqB,EAAE,CAAC;IACjC,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,mBAAmB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,aAAa,EACb,OAAO,EACP,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,QAAQ,EACR,KAAK,EACL,KAAK,EACL,WAAW,EACX,aAAa,GACd,EAAE,uBAAuB,+BA4FzB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { Loader2, MapPin, Search } from 'lucide-react';
|
|
5
|
+
export function AddressSearchInput({ query, onQueryChange, results, isSearching, showResults, onShowResultsChange, onSelect, error, label, placeholder, noResultsText, }) {
|
|
6
|
+
const containerRef = useRef(null);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const handleClickOutside = (e) => {
|
|
9
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
10
|
+
onShowResultsChange(false);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
14
|
+
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
15
|
+
}, [onShowResultsChange]);
|
|
16
|
+
const handleKeyDown = (e) => {
|
|
17
|
+
if (e.key === 'Escape') {
|
|
18
|
+
onShowResultsChange(false);
|
|
19
|
+
}
|
|
20
|
+
if (e.key === 'Enter' && results.length > 0) {
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
onSelect(results[0].place_id);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const showDropdown = showResults && query.length >= 3;
|
|
26
|
+
return (_jsxs("div", { ref: containerRef, className: "relative", children: [label ? (_jsx("label", { htmlFor: "address-search", className: "rizzui-input-label mb-1.5 block text-sm font-medium", children: label })) : null, _jsxs("div", { className: "relative", children: [_jsx("input", { id: "address-search", type: "text", value: query, onChange: e => onQueryChange(e.target.value), onFocus: () => {
|
|
27
|
+
if (query.length >= 3 && results.length > 0)
|
|
28
|
+
onShowResultsChange(true);
|
|
29
|
+
}, onKeyDown: handleKeyDown, placeholder: placeholder, autoComplete: "off", className: `rizzui-input-container peer flex h-12 w-full items-center rounded-xl border bg-white py-2 pl-11 pr-11 text-sm shadow-sm transition-all placeholder:text-gray-400 focus:border-[#CF0A2C] focus:outline-none focus:ring-2 focus:ring-[#CF0A2C]/25 ${error ? 'border-red-400 focus:border-red-400 focus:ring-red-500/20' : 'border-gray-200'}` }), _jsx(Search, { className: "pointer-events-none absolute left-3.5 top-1/2 h-[18px] w-[18px] -translate-y-1/2 text-gray-400" }), isSearching ? (_jsx(Loader2, { className: "absolute right-3.5 top-1/2 h-[18px] w-[18px] -translate-y-1/2 animate-spin text-[#CF0A2C]" })) : null] }), error ? _jsx("p", { className: "mt-2 text-xs text-red-500", children: error }) : null, showDropdown ? (_jsx("div", { className: "absolute z-50 mt-2 w-full overflow-hidden rounded-xl border border-gray-200 bg-white shadow-xl", children: results.length > 0 ? (_jsx("ul", { className: "max-h-64 overflow-y-auto py-1", children: results.map(result => (_jsx("li", { children: _jsx("button", { type: "button", onMouseDown: e => e.preventDefault(), onClick: () => onSelect(result.place_id), className: "w-full px-4 py-3 text-left transition-colors hover:bg-red-50/80 focus:bg-red-50 focus:outline-none", children: _jsxs("div", { className: "flex items-start gap-3", children: [_jsx("div", { className: "mt-0.5 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-gray-100", children: _jsx(MapPin, { className: "h-3.5 w-3.5 text-gray-500" }) }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("p", { className: "truncate text-sm font-medium text-gray-900", children: result.structured_formatting.main_text }), _jsx("p", { className: "mt-0.5 truncate text-xs text-gray-500", children: result.structured_formatting.secondary_text || result.description })] })] }) }) }, result.place_id))) })) : (!isSearching && _jsx("p", { className: "px-4 py-6 text-center text-sm text-gray-500", children: noResultsText })) })) : null] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IData } from "@/core/interface/nexine.interface";
|
|
2
|
+
import { Address } from "@/core/interface/prisma.interface";
|
|
3
|
+
export declare const useAddress: () => {
|
|
4
|
+
fetch: () => import("@tanstack/react-query").UseQueryResult<NoInfer<IData<Address>>, Error>;
|
|
5
|
+
create: () => import("@tanstack/react-query").UseMutationResult<any, Error, any, unknown>;
|
|
6
|
+
detail: (id: string) => import("@tanstack/react-query").UseQueryResult<NoInfer<Address>, Error>;
|
|
7
|
+
update: () => import("@tanstack/react-query").UseMutationResult<import("axios").AxiosResponse<any, any, {}>, Error, any, unknown>;
|
|
8
|
+
delete: () => import("@tanstack/react-query").UseMutationResult<import("axios").AxiosResponse<any, any, {}>, Error, string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=use.addres.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.addres.d.ts","sourceRoot":"","sources":["../../../../../core/feature/address/hook/use.addres.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAG5D,eAAO,MAAM,UAAU;;;iBAyBC,MAAM;;;CAgC7B,CAAC"}
|