From cdc9fa686f6fa17ec4e29883d0ae3fdfa634342c Mon Sep 17 00:00:00 2001 From: Jelaletdin12 Date: Fri, 19 Dec 2025 18:14:29 +0500 Subject: [PATCH] cleaned code from logs and some comments --- Soraglar.txt | 4 +- app/[locale]/cart/page.tsx | 37 +- app/[locale]/category/[slug]/page.tsx | 1 - app/[locale]/collections/[slug]/page.tsx | 1 - app/[locale]/openStore/page.tsx | 59 +-- app/[locale]/product/[slug]/page.tsx | 1 - components/layout/Header.tsx | 6 +- components/layout/MobileBar.tsx | 11 - components/layout/ui/ActionButtons.tsx | 4 +- components/layout/ui/AuthDialog.tsx | 2 +- components/layout/ui/SearchBar.tsx | 6 +- features/cart/components/CartItemCard.tsx | 6 +- features/cart/components/EmptyCart.tsx | 4 +- features/cart/components/OrderSummary.tsx | 2 +- features/cart/hooks/useCart.ts | 64 +-- .../category/components/CategoryFilters.tsx | 2 +- .../components/CategoryFiltersSheet.tsx | 4 +- .../components/CategoryPageClient.tsx | 12 +- .../components/CategoryProductsGrid.tsx | 4 +- .../components/CollectionFilters.tsx | 2 +- .../components/CollectionFiltersSheet.tsx | 4 +- .../favorites/components/EmptyFavorites.tsx | 4 +- features/home/components/HomePage.tsx | 1 - features/home/components/ProductCard.tsx | 20 +- features/home/hooks/useCollections.ts | 1 - features/orders/components/EmptyOrders.tsx | 4 +- features/orders/components/OrderPage.tsx | 6 +- features/orders/hooks/useOrders.ts | 3 +- .../components/ProductImageGallery.tsx | 4 +- .../products/components/ProductInfoCard.tsx | 17 +- .../components/ProductPageContent.tsx | 464 +++++++++--------- .../components/ProductPurchaseCard.tsx | 10 +- .../components/ProductReviewsSection.tsx | 2 +- .../components/RelatedProductsSection.tsx | 1 - features/products/components/ReviewModal.tsx | 4 +- .../products/components/StockLimitModal.tsx | 2 +- features/products/hooks/useProducts.ts | 2 +- .../profile/components/ProfilePageContent.tsx | 14 +- features/profile/hooks/useUserProfile.ts | 6 +- features/profile/userStore.ts | 30 -- i18n/messages/ru.json | 7 +- i18n/messages/tm.json | 13 +- lib/hooks/useAuth.ts | 1 - lib/tokenStorage.ts | 3 +- lib/types/api.ts | 14 + 45 files changed, 368 insertions(+), 501 deletions(-) delete mode 100644 features/profile/userStore.ts diff --git a/Soraglar.txt b/Soraglar.txt index 9900e27..a94b4dd 100644 --- a/Soraglar.txt +++ b/Soraglar.txt @@ -8,4 +8,6 @@ 5. Review feed back yazylyan yer bamy bolmalymy -6. Open Store api field ler nahili bolmaly. \ No newline at end of file +6. Open Store api field ler nahili bolmaly. + +7. Delivery type soramaly, type lar yok \ No newline at end of file diff --git a/app/[locale]/cart/page.tsx b/app/[locale]/cart/page.tsx index 51add10..e8d67f3 100644 --- a/app/[locale]/cart/page.tsx +++ b/app/[locale]/cart/page.tsx @@ -10,11 +10,11 @@ import { useRegions, usePaymentTypes, } from "@/lib/hooks"; -import { userStore } from "@/features/profile/userStore"; import { useTranslations } from "next-intl"; import { useRouter } from "next/navigation"; import type { DeliveryType, PaymentType } from "@/lib/types/api"; import EmptyCart from "@/features/cart/components/EmptyCart"; + export default function CartPage() { const [isClient, setIsClient] = useState(false); const [paymentType, setPaymentType] = useState(null); @@ -38,14 +38,6 @@ export default function CartPage() { useEffect(() => { setIsClient(true); - - // Get user data from store if available - const orderData = userStore.getOrderData(); - if (orderData) { - if (orderData.customer_name) setName(orderData.customer_name); - if (orderData.customer_last_name) setLastName(orderData.customer_last_name); - if (orderData.customer_phone) setPhone(orderData.customer_phone); - } }, []); const regionGroups = useMemo(() => { @@ -92,7 +84,13 @@ export default function CartPage() { }; const handleCompleteOrder = () => { - if (!selectedRegion || !selectedProvince || !paymentType || !phone || !name) { + if ( + !selectedRegion || + !selectedProvince || + !paymentType || + !phone || + !name + ) { console.warn("Missing required fields for order"); return; } @@ -102,13 +100,6 @@ export default function CartPage() { ); if (!selectedProvinceData) return; - const orderData = userStore.getOrderData(); - if (!orderData) { - console.error("User data not found"); - router.push("/"); - return; - } - createOrder( { customer_name: name, @@ -129,17 +120,15 @@ export default function CartPage() { if (!isClient) return null; - - if (isError || cartItems.length === 0) { - return ( - - ); + return ; } return (
-

{t("cart")}

+

+ {t("cart")} +

@@ -234,4 +223,4 @@ export default function CartPage() {
); -} \ No newline at end of file +} diff --git a/app/[locale]/category/[slug]/page.tsx b/app/[locale]/category/[slug]/page.tsx index e623def..3f3abf4 100644 --- a/app/[locale]/category/[slug]/page.tsx +++ b/app/[locale]/category/[slug]/page.tsx @@ -22,7 +22,6 @@ export async function generateMetadata({ params }: Props): Promise { } export async function generateStaticParams() { - // Generate static params for popular categories const categories = ["electronics", "clothing", "home-garden"] return categories.map((slug) => ({ slug })) } diff --git a/app/[locale]/collections/[slug]/page.tsx b/app/[locale]/collections/[slug]/page.tsx index f784543..845351c 100644 --- a/app/[locale]/collections/[slug]/page.tsx +++ b/app/[locale]/collections/[slug]/page.tsx @@ -22,7 +22,6 @@ export async function generateMetadata({ params }: Props): Promise { } export async function generateStaticParams() { - // Generate static params for popular collections const collections = ["new-arrivals", "best-sellers", "featured"] return collections.map((slug) => ({ slug })) } diff --git a/app/[locale]/openStore/page.tsx b/app/[locale]/openStore/page.tsx index 7d78101..e97289f 100644 --- a/app/[locale]/openStore/page.tsx +++ b/app/[locale]/openStore/page.tsx @@ -15,6 +15,7 @@ import { } from "@/components/ui/card"; import { useOpenStore } from "@/lib/hooks"; import { toast } from "sonner"; +import { useTranslations } from "next-intl"; interface OpenStorePageProps { locale?: string; @@ -68,56 +69,39 @@ export default function OpenStorePage({ const [fileName, setFileName] = useState(""); const { mutate: submitOpenStore, isPending: loading } = useOpenStore(); - - const t = translations || { - title: "Форма подачи заявления на открытие магазина", - firstName: "Имя", - lastName: "Фамилия", - email: "Email", - phone: "Телефон", - uploadPatent: "Загрузите патент на розничную торговлю (PDF, JPG)", - submit: "Отправить", - selectedFile: "Выбранный файл", - firstNameRequired: "Имя обязательно", - lastNameRequired: "Фамилия обязательна", - emailInvalid: "Некорректный email", - phoneInvalid: "Некорректный номер телефона", - fileRequired: "Патент обязателен", - fileSizeError: "Файл слишком большой (макс. 25MB)", - fileTypeError: "Только PDF и JPG документы", - }; + const t = useTranslations(); const validateForm = (): boolean => { const newErrors: FormErrors = {}; if (!formData.firstName.trim()) { - newErrors.firstName = t.firstNameRequired; + newErrors.firstName = t("firstNameRequired"); } if (!formData.lastName.trim()) { - newErrors.lastName = t.lastNameRequired; + newErrors.lastName = t("lastNameRequired"); } const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(formData.email)) { - newErrors.email = t.emailInvalid; + newErrors.email = t("emailInvalid"); } const phoneRegex = /^\+?[0-9]{6,15}$/; if (!phoneRegex.test(formData.phone)) { - newErrors.phone = t.phoneInvalid; + newErrors.phone = t("phoneInvalid"); } if (!formData.file) { - newErrors.file = t.fileRequired; + newErrors.file = t("fileRequired"); } else { const allowedTypes = ["image/jpeg", "image/jpg", "application/pdf"]; if (!allowedTypes.includes(formData.file.type)) { - newErrors.file = t.fileTypeError; + newErrors.file = t("fileTypeError"); } if (formData.file.size > 25 * 1024 * 1024) { - newErrors.file = t.fileSizeError; + newErrors.file = t("fileSizeError"); } } @@ -160,9 +144,8 @@ export default function OpenStorePage({ }, { onSuccess: () => { - toast.success("Your store request has been submitted successfully"); + toast.success(t("submit_success")); - setFormData({ firstName: "", lastName: "", @@ -173,7 +156,7 @@ export default function OpenStorePage({ setFileName(""); }, onError: (error: any) => { - toast.error(error?.message || "Failed to submit store request"); + toast.error(error?.message || t("submit_error")); }, } ); @@ -184,7 +167,7 @@ export default function OpenStorePage({
- {t.title} + {t("title")} Заполните форму для подачи заявления @@ -193,7 +176,7 @@ export default function OpenStorePage({
{/* First Name */}
- + - + - + - + - +
document.getElementById("file")?.click()} > - {t.uploadPatent} + {t("uploadPatent")} {fileName && (

- {t.selectedFile}: {fileName} + {t("selectedFile")}: {fileName}

)} {errors.file && ( @@ -290,7 +273,7 @@ export default function OpenStorePage({ className="w-full cursor-pointer bg-[#005bff] hover:bg-[#0041c4]" disabled={loading} > - {loading ? "Загрузка..." : t.submit} + {loading ? "Загрузка..." : t("submit")} diff --git a/app/[locale]/product/[slug]/page.tsx b/app/[locale]/product/[slug]/page.tsx index 3beaec3..bc43420 100644 --- a/app/[locale]/product/[slug]/page.tsx +++ b/app/[locale]/product/[slug]/page.tsx @@ -23,7 +23,6 @@ export async function generateMetadata({ params }: Props): Promise { } export async function generateStaticParams() { - // Generate static params for popular products return [{ slug: "nike-air-max" }, { slug: "adidas-ultraboost" }]; } diff --git a/components/layout/Header.tsx b/components/layout/Header.tsx index 0b72748..c846476 100644 --- a/components/layout/Header.tsx +++ b/components/layout/Header.tsx @@ -3,7 +3,7 @@ import { useState, useEffect, useCallback } from "react"; import Link from "next/link"; import Image from "next/image"; -import { X, Search, Store, User as UserIcon } from "lucide-react"; +import { X, Search, User as UserIcon } from "lucide-react"; import { Button } from "@/components/ui/button"; import Logo from "@/public/logo.webp"; import CategoryMenu from "./ui/CategoryMenu"; @@ -70,14 +70,14 @@ export default function Header({ locale = "ru" }: HeaderProps) { -
+
diff --git a/features/cart/components/CartItemCard.tsx b/features/cart/components/CartItemCard.tsx index 7991c35..8c34dcc 100644 --- a/features/cart/components/CartItemCard.tsx +++ b/features/cart/components/CartItemCard.tsx @@ -349,7 +349,7 @@ export default function CartItemCard({ item, onUpdate }: CartItemCardProps) { size="sm" onClick={handleDelete} disabled={isRemoving} - className="w-fit p-0 h-auto hover:bg-transparent hover:text-red-500" + className="w-fit cursor-pointer p-0 h-auto hover:bg-transparent hover:text-red-500" > @@ -387,7 +387,7 @@ export default function CartItemCard({ item, onUpdate }: CartItemCardProps) { variant="outline" size="icon" onClick={handleQuantityDecrease} - className={` cursor-pointerrounded-xl bg-blue-50 ${ + className={` cursor-pointer rounded-xl bg-blue-50 ${ isSyncing ? "opacity-70" : "" }`} > @@ -449,7 +449,7 @@ export default function CartItemCard({ item, onUpdate }: CartItemCardProps) {
diff --git a/features/cart/components/EmptyCart.tsx b/features/cart/components/EmptyCart.tsx index f53bdc2..f82b050 100644 --- a/features/cart/components/EmptyCart.tsx +++ b/features/cart/components/EmptyCart.tsx @@ -8,7 +8,7 @@ export default function EmptyCart() { const router=useRouter(); return (
-
+
@@ -21,7 +21,7 @@ export default function EmptyCart() { {t("cart_empty_message")}

-
diff --git a/features/cart/components/OrderSummary.tsx b/features/cart/components/OrderSummary.tsx index 2fe88f2..0e5deeb 100644 --- a/features/cart/components/OrderSummary.tsx +++ b/features/cart/components/OrderSummary.tsx @@ -265,7 +265,7 @@ export default function OrderSummary({
diff --git a/features/category/components/CategoryFiltersSheet.tsx b/features/category/components/CategoryFiltersSheet.tsx index d25a563..cb7ef6c 100644 --- a/features/category/components/CategoryFiltersSheet.tsx +++ b/features/category/components/CategoryFiltersSheet.tsx @@ -28,7 +28,7 @@ export default function CategoryFiltersSheet({
- {/* İlk yükleme için skeleton göster */} {isFetching && products.length === 0 && (
{Array.from({ length: 6 }).map((_, i) => ( diff --git a/features/collections/components/CollectionFilters.tsx b/features/collections/components/CollectionFilters.tsx index c24ad51..4f40cf5 100644 --- a/features/collections/components/CollectionFilters.tsx +++ b/features/collections/components/CollectionFilters.tsx @@ -107,7 +107,7 @@ export default function CollectionFilters({ }} /> -
diff --git a/features/collections/components/CollectionFiltersSheet.tsx b/features/collections/components/CollectionFiltersSheet.tsx index 45d1825..a25ab29 100644 --- a/features/collections/components/CollectionFiltersSheet.tsx +++ b/features/collections/components/CollectionFiltersSheet.tsx @@ -28,7 +28,7 @@ export default function CollectionFiltersSheet({
diff --git a/features/home/components/HomePage.tsx b/features/home/components/HomePage.tsx index 44789d9..ac12c78 100644 --- a/features/home/components/HomePage.tsx +++ b/features/home/components/HomePage.tsx @@ -29,7 +29,6 @@ export default function HomePage() { isError: collectionsError, } = useCollections(); - // Prefetch favorites useFavorites(); const loadMore = () => { diff --git a/features/home/components/ProductCard.tsx b/features/home/components/ProductCard.tsx index c4ce3a7..8024e1c 100644 --- a/features/home/components/ProductCard.tsx +++ b/features/home/components/ProductCard.tsx @@ -169,7 +169,7 @@ export default function ProductCard({ { onSuccess: (data) => toast.success( - data.wasAdded ? "Added to favorites" : "Removed from favorites" + data.wasAdded ? t("added_to_favorites") : t("removed_from_favorites") ), onError: () => toast.error("Error. Try again"), } @@ -196,12 +196,12 @@ export default function ProductCard({ quantity: localQuantity, }); await refetchCart(); - toast.success("Added to cart", { - description: `${name} has been added to your cart`, + toast.success(t("added_to_cart"), { + description: `${name} ${t("added_to_cart_description")}`, }); } catch (error) { console.error("Add to cart error:", error); - toast.error("Failed to add to cart"); + toast.error(t("add_to_cart_failed")); } finally { setIsSyncing(false); } @@ -303,7 +303,7 @@ export default function ProductCard({ @@ -409,7 +409,7 @@ export default function ProductCard({ size="icon" onClick={(e) => handleQuantityChange(e, 1)} disabled={isSyncing} - className="rounded-lg h-9 w-9 shrink-0" + className="rounded-lg cursor-pointer h-9 w-9 shrink-0" > @@ -444,7 +444,7 @@ export default function ProductCard({ e.stopPropagation(); setShowStockModal(false); }} - className="w-full rounded-lg" + className="w-full rounded-lg cursor-pointer" > {t("understood")} diff --git a/features/home/hooks/useCollections.ts b/features/home/hooks/useCollections.ts index cba260c..ae47c55 100644 --- a/features/home/hooks/useCollections.ts +++ b/features/home/hooks/useCollections.ts @@ -139,7 +139,6 @@ export function useCollectionProductsInfinite( }, getNextPageParam: (lastPage) => { if (lastPage.pagination?.next_page_url) { - // Extract page number from URL or increment const currentPage = lastPage.pagination.page || 1; return currentPage + 1; } diff --git a/features/orders/components/EmptyOrders.tsx b/features/orders/components/EmptyOrders.tsx index b158a21..96d3b8a 100644 --- a/features/orders/components/EmptyOrders.tsx +++ b/features/orders/components/EmptyOrders.tsx @@ -8,7 +8,7 @@ export default function EmptyOrders() { const router=useRouter(); return (
-
+
@@ -21,7 +21,7 @@ export default function EmptyOrders() { {t("orders_empty_message")}

-
diff --git a/features/orders/components/OrderPage.tsx b/features/orders/components/OrderPage.tsx index 1e63a63..2e90a39 100644 --- a/features/orders/components/OrderPage.tsx +++ b/features/orders/components/OrderPage.tsx @@ -258,6 +258,7 @@ export default function OrdersPageClient({ locale }: OrdersPageClientProps) { variant="outline" onClick={() => setIsCancelDialogOpen(false)} disabled={isCancellingOrder} + className="cursor-pointer" > {t("keep_order")} @@ -265,6 +266,7 @@ export default function OrdersPageClient({ locale }: OrdersPageClientProps) { variant="destructive" onClick={confirmCancelOrder} disabled={isCancellingOrder} + className="cursor-pointer" > {isCancellingOrder ? t("cancelling") : t("cancel_order")} @@ -404,7 +406,7 @@ function CompactOrderCard({ key={index} className="flex items-center gap-4 p-3 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors" > -
+
{t("cancel_order")} diff --git a/features/orders/hooks/useOrders.ts b/features/orders/hooks/useOrders.ts index d19d195..be0a9da 100644 --- a/features/orders/hooks/useOrders.ts +++ b/features/orders/hooks/useOrders.ts @@ -1,6 +1,6 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { apiClient } from "@/lib/api"; -import type { Order, OrdersResponse, CreateOrderRequest } from "@/lib/types/api"; +import type { Order, OrdersResponse } from "@/lib/types/api"; export function useOrders(options?: { page?: number; perPage?: number }) { return useQuery({ @@ -13,7 +13,6 @@ export function useOrders(options?: { page?: number; perPage?: number }) { }, }); - // API response'dan data array'ini döndür return response.data.data; }, staleTime: 1000 * 60 * 5, diff --git a/features/products/components/ProductImageGallery.tsx b/features/products/components/ProductImageGallery.tsx index cc6f811..eb416e4 100644 --- a/features/products/components/ProductImageGallery.tsx +++ b/features/products/components/ProductImageGallery.tsx @@ -44,7 +44,7 @@ export function ProductImageGallery({ ); return ( -
+
{images.length > 0 ? ( @@ -68,7 +68,7 @@ export function ProductImageGallery({
), - [], - ) + [] + ); - if (productLoading) return loadingSkeleton + if (productLoading) return loadingSkeleton; if (error || !product) { return (
-

{t("product_not_found")}

-

{t("product_not_found_description")}

+

+ {t("product_not_found")} +

+

+ {t("product_not_found_description")} +

- ) + ); } return ( <>
- + - ) + ); } diff --git a/features/products/components/ProductPurchaseCard.tsx b/features/products/components/ProductPurchaseCard.tsx index adbef78..ad2a6ee 100644 --- a/features/products/components/ProductPurchaseCard.tsx +++ b/features/products/components/ProductPurchaseCard.tsx @@ -62,7 +62,7 @@ export function ProductPurchaseCard({
- diff --git a/features/products/components/ProductReviewsSection.tsx b/features/products/components/ProductReviewsSection.tsx index 2fc6a3b..ab7f150 100644 --- a/features/products/components/ProductReviewsSection.tsx +++ b/features/products/components/ProductReviewsSection.tsx @@ -56,7 +56,7 @@ export function ProductReviewsSection({ */}
- diff --git a/features/products/components/RelatedProductsSection.tsx b/features/products/components/RelatedProductsSection.tsx index c43b5cd..553c642 100644 --- a/features/products/components/RelatedProductsSection.tsx +++ b/features/products/components/RelatedProductsSection.tsx @@ -38,7 +38,6 @@ export function RelatedProductsSection({

{t("related_products")}

{products.slice(0, 4).map((product) => { - // Extract image URLs from media const images = product.media?.map( (m) => diff --git a/features/products/components/ReviewModal.tsx b/features/products/components/ReviewModal.tsx index b2e90a0..3f8a740 100644 --- a/features/products/components/ReviewModal.tsx +++ b/features/products/components/ReviewModal.tsx @@ -96,14 +96,14 @@ export function ReviewModal({ diff --git a/features/products/hooks/useProducts.ts b/features/products/hooks/useProducts.ts index 1f3dd6a..216aec9 100644 --- a/features/products/hooks/useProducts.ts +++ b/features/products/hooks/useProducts.ts @@ -207,7 +207,7 @@ export function useSubmitReview() { }, (variables) => [ reviewKeys.byProduct(variables.productId), - productKeys.bySlug(""), // Invalidates all slug queries + productKeys.bySlug(""), reviewKeys.all, ] ); diff --git a/features/profile/components/ProfilePageContent.tsx b/features/profile/components/ProfilePageContent.tsx index e3d149e..5714881 100644 --- a/features/profile/components/ProfilePageContent.tsx +++ b/features/profile/components/ProfilePageContent.tsx @@ -38,7 +38,6 @@ export default function ClientProfilePage(props: ProfilePageProps) { useEffect(() => { if (user && !isEditing) { - console.log("[Profile] User data loaded:", user); setFormData({ name: user.first_name || "", last_name: user.last_name || "", @@ -90,7 +89,6 @@ export default function ClientProfilePage(props: ProfilePageProps) { address: formData.address.trim(), }; - console.log("[Profile] Saving data:", apiData); try { await updateProfile.mutateAsync(apiData); @@ -160,7 +158,7 @@ export default function ClientProfilePage(props: ProfilePageProps) {

@@ -186,7 +184,7 @@ export default function ClientProfilePage(props: ProfilePageProps) { : t("view_your_information")}

-
+
@@ -209,7 +207,7 @@ export default function ClientProfilePage(props: ProfilePageProps) { onClick={handleEdit} variant="outline" size="sm" - className="self-start sm:self-center border-gray-300 hover:bg-gray-50 text-gray-700 h-9" + className="self-start sm:self-center cursor-pointer border-gray-300 hover:bg-gray-50 text-gray-700 h-9" > {t("edit")} @@ -329,7 +327,7 @@ export default function ClientProfilePage(props: ProfilePageProps) {