Initial commit: Kottgard production website code
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
'use client';
|
||||
|
||||
import { Address, Order, User } from '@/domain/entities';
|
||||
import { RegisterInput } from '@/domain/services/AuthDomainService';
|
||||
import { container } from '@/application/container';
|
||||
import { useAuthStore } from '@/infrastructure/persistence/zustand/authStore';
|
||||
|
||||
export function useAuth() {
|
||||
const user = useAuthStore((s) => s.user);
|
||||
const orders = useAuthStore((s) => s.orders);
|
||||
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
||||
|
||||
return {
|
||||
user,
|
||||
orders,
|
||||
isAuthenticated,
|
||||
login: (email: string, password: string) =>
|
||||
container.login.execute(email, password),
|
||||
register: (data: RegisterInput) => container.register.execute(data),
|
||||
logout: () => container.authRepository.logout(),
|
||||
updateProfile: (data: Partial<User>) =>
|
||||
container.authRepository.updateProfile(data),
|
||||
addOrder: (order: Order) => container.authRepository.addOrder(order),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
'use client';
|
||||
|
||||
import { Product, ProductCustomization } from '@/domain/entities';
|
||||
import { container } from '@/application/container';
|
||||
import { useCartStore } from '@/infrastructure/persistence/zustand/cartStore';
|
||||
|
||||
/**
|
||||
* PRESENTATION — Cart hook: React state + use cases (Clean Architecture boundary)
|
||||
*/
|
||||
export function useCart() {
|
||||
const items = useCartStore((s) => s.items);
|
||||
const summary = container.getCartSummary.execute();
|
||||
|
||||
return {
|
||||
items,
|
||||
summary,
|
||||
addItem: (
|
||||
product: Product,
|
||||
customization: ProductCustomization,
|
||||
customizationLabel: string,
|
||||
quantity?: number
|
||||
) => {
|
||||
container.addToCart.execute(
|
||||
product,
|
||||
customization,
|
||||
customizationLabel,
|
||||
quantity
|
||||
);
|
||||
},
|
||||
removeItem: (id: string) => container.removeFromCart.execute(id),
|
||||
updateQuantity: (id: string, quantity: number) =>
|
||||
container.updateCartQuantity.execute(id, quantity),
|
||||
clearCart: () => container.cartRepository.clearCart(),
|
||||
/** @deprecated Use summary.subtotal */
|
||||
getTotal: () => summary.subtotal,
|
||||
/** @deprecated Use summary.itemCount */
|
||||
getItemCount: () => summary.itemCount,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
'use client';
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import { Category, SortOption } from '@/domain/entities';
|
||||
import { CategoryFilter } from '@/domain/services/CatalogDomainService';
|
||||
import { container } from '@/application/container';
|
||||
import { useLocaleStore } from '@/infrastructure/persistence/zustand/localeStore';
|
||||
import { LocalizedProduct } from '@/application/dtos/LocalizedProduct';
|
||||
|
||||
export function useCatalogFilter(input: {
|
||||
category: CategoryFilter;
|
||||
searchQuery: string;
|
||||
sortBy: SortOption;
|
||||
}): LocalizedProduct[] {
|
||||
const locale = useLocaleStore((s) => s.locale);
|
||||
|
||||
return useMemo(() => {
|
||||
return container.createFilterProducts(locale).execute(input);
|
||||
}, [locale, input.category, input.searchQuery, input.sortBy]);
|
||||
}
|
||||
|
||||
export function useLocalizedProduct(
|
||||
productId: string
|
||||
): LocalizedProduct | undefined {
|
||||
const locale = useLocaleStore((s) => s.locale);
|
||||
|
||||
return useMemo(() => {
|
||||
const product = container.productRepository.findById(productId);
|
||||
if (!product) return undefined;
|
||||
return container.createLocalizeProduct(locale).execute(product);
|
||||
}, [locale, productId]);
|
||||
}
|
||||
|
||||
export { FilterProductsUseCase as CatalogHelpers } from '@/application/use-cases/catalog/FilterProducts';
|
||||
|
||||
export type { CategoryFilter };
|
||||
export type { Category };
|
||||
@@ -0,0 +1,13 @@
|
||||
'use client';
|
||||
|
||||
import { Address } from '@/domain/entities';
|
||||
import { container } from '@/application/container';
|
||||
|
||||
export function useCheckout() {
|
||||
return {
|
||||
placeOrder: (input: {
|
||||
deliveryAddress: Address;
|
||||
paymentMethod: string;
|
||||
}) => container.placeOrder.execute(input),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
'use client';
|
||||
|
||||
import { Product } from '@/domain/entities';
|
||||
import { container } from '@/application/container';
|
||||
import { useWishlistStore } from '@/infrastructure/persistence/zustand/wishlistStore';
|
||||
|
||||
export function useWishlist() {
|
||||
const items = useWishlistStore((s) => s.items);
|
||||
|
||||
return {
|
||||
items,
|
||||
isInWishlist: (productId: string) =>
|
||||
container.wishlistRepository.isInWishlist(productId),
|
||||
toggleItem: (product: Product) =>
|
||||
container.toggleWishlist.execute(product),
|
||||
removeItem: (productId: string) =>
|
||||
container.wishlistRepository.removeItem(productId),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user