From c68ac335c6606856844f2a2f054eef8a457ff0b4 Mon Sep 17 00:00:00 2001 From: Jelaletdin12 Date: Mon, 2 Feb 2026 16:22:27 +0500 Subject: [PATCH] removed some unnecessary ui elements --- app/[locale]/cart/page.tsx | 147 ++++++++++-------- app/[locale]/favorites/page.tsx | 3 +- app/[locale]/product/[slug]/page.tsx | 4 +- components/layout/ui/ActionButtons.tsx | 17 +- features/cart/components/CartItemCard.tsx | 20 +-- features/cart/components/OrderSummary.tsx | 37 +---- features/home/components/ProductCard.tsx | 35 +++-- features/home/components/ProductGrid.tsx | 1 + .../products/components/ProductInfoCard.tsx | 27 +--- .../components/ProductPageContent.tsx | 8 +- .../components/ProductPurchaseCard.tsx | 24 +-- package.json | 2 +- 12 files changed, 120 insertions(+), 205 deletions(-) diff --git a/app/[locale]/cart/page.tsx b/app/[locale]/cart/page.tsx index 103cf34..dafee5e 100644 --- a/app/[locale]/cart/page.tsx +++ b/app/[locale]/cart/page.tsx @@ -19,14 +19,13 @@ import EmptyCart from "@/features/cart/components/EmptyCart"; import ErrorPage from "@/components/ErrorPage"; export default function CartPage() { - const [isClient, setIsClient] = useState(false); const [paymentType, setPaymentType] = useState(null); const [deliveryType, setDeliveryType] = useState("SELECTED_DELIVERY"); const [selectedRegion, setSelectedRegion] = useState(""); const [selectedProvince, setSelectedProvince] = useState(null); const [note, setNote] = useState(""); - const [phone, setPhone] = useState("+993 "); + const [phone, setPhone] = useState("+993 "); const [name, setName] = useState(""); const [lastName, setLastName] = useState(""); const router = useRouter(); @@ -42,38 +41,52 @@ export default function CartPage() { const isLoading = cartLoading || provincesLoading || paymentTypesLoading; useEffect(() => { - setIsClient(true); - }, []); + if (paymentTypes.length > 0) { + const defaultType = paymentTypes.find((t) => t.id === 1); + if (defaultType) { + setPaymentType(defaultType); + } + } + }, [paymentTypes]); const regionGroups = useMemo(() => { - return provinces.reduce((acc, province) => { - if (!acc[province.region]) { - acc[province.region] = []; - } - acc[province.region].push(province); - return acc; - }, {} as Record); + return provinces.reduce( + (acc, province) => { + if (!acc[province.region]) { + acc[province.region] = []; + } + acc[province.region].push(province); + return acc; + }, + {} as Record, + ); }, [provinces]); const availableRegions = useMemo( () => Object.keys(regionGroups), - [regionGroups] + [regionGroups], ); const itemsBySeller = useMemo(() => { - return cartItems.reduce((acc, item) => { - const sellerId = item.product.channel?.[0]?.id || 0; - const sellerName = item.product.channel?.[0]?.name || "Unknown Seller"; + return cartItems.reduce( + (acc, item) => { + const sellerId = item.product.channel?.[0]?.id || 0; + const sellerName = item.product.channel?.[0]?.name || "Unknown Seller"; - if (!acc[sellerId]) { - acc[sellerId] = { - seller: { id: sellerId, name: sellerName }, - items: [], - }; - } - acc[sellerId].items.push(item); - return acc; - }, {} as Record); + if (!acc[sellerId]) { + acc[sellerId] = { + seller: { id: sellerId, name: sellerName }, + items: [], + }; + } + acc[sellerId].items.push(item); + return acc; + }, + {} as Record< + number, + { seller: { id: number; name: string }; items: typeof cartItems } + >, + ); }, [cartItems]); const totalAmount = useMemo(() => { @@ -88,46 +101,50 @@ export default function CartPage() { setSelectedProvince(null); }; - const formatPhoneForBackend = (phoneNumber: string): string => { - return phoneNumber.replace(/^\+993\s*/, "").replace(/\s+/g, ""); }; const handleCompleteOrder = () => { - if (!selectedRegion || !selectedProvince || !paymentType || !phone || !name) { - console.warn("Missing required fields for order"); - return; - } - - const phoneDigits = formatPhoneForBackend(phone); - if (phoneDigits.length !== 8) { - console.warn("Phone number must be exactly 8 digits"); - return; - } - - const selectedProvinceData = provinces.find((p) => p.id === selectedProvince); - if (!selectedProvinceData) return; - - createOrder( - { - customer_name: `${name} ${lastName}`.trim(), - customer_phone: parseInt(phoneDigits, 10), - customer_address: selectedProvinceData.name, - shipping_method: "standart", - payment_type_id: paymentType.id, - region: selectedRegion, - note: note || undefined, - }, - { - onSuccess: () => { - router.push(`/orders`); - }, + if ( + !selectedRegion || + !selectedProvince || + !paymentType || + !phone || + !name + ) { + console.warn("Missing required fields for order"); + return; } - ); -}; - if (!isClient) return null; + const phoneDigits = formatPhoneForBackend(phone); + if (phoneDigits.length !== 8) { + console.warn("Phone number must be exactly 8 digits"); + return; + } + + const selectedProvinceData = provinces.find( + (p) => p.id === selectedProvince, + ); + if (!selectedProvinceData) return; + + createOrder( + { + customer_name: `${name} ${lastName}`.trim(), + customer_phone: parseInt(phoneDigits, 10), + customer_address: selectedProvinceData.name, + shipping_method: "standart", + payment_type_id: paymentType.id, + region: selectedRegion, + note: note || undefined, + }, + { + onSuccess: () => { + router.push(`/orders`); + }, + }, + ); + }; if (isLoading) { return ( @@ -151,8 +168,8 @@ export default function CartPage() { ); } - - if (isError ) { + + if (isError) { return ; } if (cartItems.length === 0) { @@ -171,12 +188,10 @@ export default function CartPage() { {Object.entries(itemsBySeller).map( ([sellerId, { seller, items }]) => (
-

{seller.name}

+ {/*

{seller.name}

*/}
{items.map((item) => { - const price = parseFloat( - item.product.price_amount || "0" - ); + const price = parseInt(item.product.price_amount || "0"); const quantity = item.product_quantity; const total = price * quantity; @@ -200,7 +215,7 @@ export default function CartPage() { item.product.media?.[0]?.thumbnail, images: item.product.media?.map( - (m) => m.images_800x800 || m.thumbnail + (m) => m.images_800x800 || m.thumbnail, ) || [], }, }} @@ -212,7 +227,7 @@ export default function CartPage() { )}
- ) + ), )}
@@ -258,4 +273,4 @@ export default function CartPage() { ); -} \ No newline at end of file +} diff --git a/app/[locale]/favorites/page.tsx b/app/[locale]/favorites/page.tsx index 4bfcb84..25ad904 100644 --- a/app/[locale]/favorites/page.tsx +++ b/app/[locale]/favorites/page.tsx @@ -80,8 +80,9 @@ export default function FavoritesPage() { price_color="#0059ff" height={360} width={250} - button={false} + button={true} stock={product.stock} + /> ); })} diff --git a/app/[locale]/product/[slug]/page.tsx b/app/[locale]/product/[slug]/page.tsx index bc43420..90b7968 100644 --- a/app/[locale]/product/[slug]/page.tsx +++ b/app/[locale]/product/[slug]/page.tsx @@ -11,12 +11,12 @@ export async function generateMetadata({ params }: Props): Promise { const { locale, slug } = await params; return { - title: `Product ${slug} | E-Commerce`, + title: `Product ${slug} | Smart-Electronics`, description: `View details for product ${slug}`, openGraph: { locale, type: "website", - title: `Product ${slug} | E-Commerce`, + title: `Product ${slug} | Smart-Electronics`, description: `View details for product ${slug}`, }, }; diff --git a/components/layout/ui/ActionButtons.tsx b/components/layout/ui/ActionButtons.tsx index bc63251..40e6402 100644 --- a/components/layout/ui/ActionButtons.tsx +++ b/components/layout/ui/ActionButtons.tsx @@ -3,15 +3,8 @@ import { useRouter } from "next/navigation"; import { useMemo } from "react"; import type React from "react"; import Link from "next/link"; -import { User, Truck, Heart, Store, LogOut } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu"; import { useCart, useFavorites, useOrders, useCartCount } from "@/lib/hooks"; import { Skeleton } from "@/components/ui/skeleton"; import { useTranslations } from "next-intl"; @@ -20,7 +13,6 @@ import { CartIcon, FavoriteIcon, OrderIcon, - ProfileIcon, } from "@/components/icons"; interface ActionButtonsProps { @@ -78,11 +70,6 @@ const cartCount = useCartCount() const buttons: ActionButtonData[] = useMemo( () => [ - { - icon: , - label: t("common.openStore"), - href: "/openStore", - }, { icon: , label: t("common.orders"), @@ -119,7 +106,7 @@ const cartCount = useCartCount() return (
{/* Profile/Login Button with Dropdown */} - {authLoading ? ( + {/* {authLoading ? (
) : isAuthenticated ? ( @@ -154,7 +141,7 @@ const cartCount = useCartCount() {t("common.login")} - )} + )} */} {/* Other Action Buttons */} {buttons.map((button, index) => ( diff --git a/features/cart/components/CartItemCard.tsx b/features/cart/components/CartItemCard.tsx index cd9aa93..2927039 100644 --- a/features/cart/components/CartItemCard.tsx +++ b/features/cart/components/CartItemCard.tsx @@ -81,13 +81,13 @@ export default function CartItemCard({ item, onUpdate }: CartItemCardProps) { sessionStorage.setItem( PENDING_CART_UPDATES_KEY, - JSON.stringify(pending) + JSON.stringify(pending), ); } catch (error) { console.error("Failed to save pending update:", error); } }, - [item.product_id] + [item.product_id], ); // Remove from sessionStorage @@ -103,7 +103,7 @@ export default function CartItemCard({ item, onUpdate }: CartItemCardProps) { } else { sessionStorage.setItem( PENDING_CART_UPDATES_KEY, - JSON.stringify(pending) + JSON.stringify(pending), ); } } @@ -200,7 +200,7 @@ export default function CartItemCard({ item, onUpdate }: CartItemCardProps) { retrySyncRef.current?.(quantity); }, - } + }, ); } }, @@ -211,7 +211,7 @@ export default function CartItemCard({ item, onUpdate }: CartItemCardProps) { removeItem, onUpdate, clearPendingUpdate, - ] + ], ); // Update ref @@ -235,7 +235,7 @@ export default function CartItemCard({ item, onUpdate }: CartItemCardProps) { // Trigger sync after a short delay setTimeout( () => syncToServerRef.current?.(productPending.quantity), - 500 + 500, ); } } @@ -336,14 +336,6 @@ export default function CartItemCard({ item, onUpdate }: CartItemCardProps) {

{item.product.name}

-

- {item.seller?.name || "Store"} -

- {availableStock <= 5 && ( -

- {t("only_left", { count: availableStock })} -

- )}
- {/* Payment Type */} -
-

{t("payment_type")}

-
- {paymentTypes.map((type) => ( - onPaymentTypeChange(type)} - > -
- - {type.name} - -
-
- ))} -
- {showValidation && !paymentType && ( -

{t("requiredField")}

- )} -
- {/* Region Selection */}
); } diff --git a/package.json b/package.json index 76c68ae..ee80f89 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "ecommerce", + "name": "Smart-Electronics", "version": "0.1.0", "private": true, "scripts": {