From 50520c0195d84dbf37147f8267bcf604399ae369 Mon Sep 17 00:00:00 2001 From: Mike Velko <44818580+mikevelko@users.noreply.github.com> Date: Sun, 25 Aug 2024 09:03:50 +0200 Subject: [PATCH] regenerated models refactor and bugfixes (#122) --- src/app/archive/page.tsx | 3 +-- src/app/page.tsx | 15 ++++++++------- src/components/forms/NewOrderForm/index.tsx | 9 ++++----- src/components/sections/Cart/CartItemRow.tsx | 15 ++++++++------- .../sections/Cart/CartProductsList/index.tsx | 11 +++++------ .../sections/Cart/ProductAmountButtons.tsx | 8 ++------ src/components/sections/Common/Size.tsx | 8 ++++++++ 7 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 src/components/sections/Common/Size.tsx diff --git a/src/app/archive/page.tsx b/src/app/archive/page.tsx index f9087c96..9f664851 100644 --- a/src/app/archive/page.tsx +++ b/src/app/archive/page.tsx @@ -34,8 +34,7 @@ export default async function Page() { {a.archive?.archiveBody?.heading}
- {/* @ts-ignore */} -

{a.archive?.archiveBody?.description}

+

{a.archive?.archiveBody?.text}

{a.archive?.createdAt}

diff --git a/src/app/page.tsx b/src/app/page.tsx index 2b35349b..4f7f687e 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,30 +1,31 @@ -import Button from "@/components/ui/Button"; -import { ButtonStyle } from "@/components/ui/Button/styles"; import CoreLayout from "@/components/layouts/CoreLayout"; import AdsSection from "@/components/sections/AdsSection"; import HeroSection from "@/components/sections/HeroSection"; import ProductsSection from "@/components/sections/ProductsGridSection"; +import Button from "@/components/ui/Button"; +import { ButtonStyle } from "@/components/ui/Button/styles"; import { serviceClient } from "@/lib/api"; -import { notFound } from "next/navigation"; import Link from "next/link"; +import { notFound } from "next/navigation"; export default async function Page() { const { hero } = await serviceClient.GetHero({}); if (!hero) return notFound(); - const { productsFeatured, ads } = hero; + const main = hero.ads?.find((x) => x.isMain); + + const ads = hero.ads?.filter((x) => !x.isMain); return ( <> - {/* ads */} - {/* {rest?.main && } */} + {main && } - + ); diff --git a/src/components/forms/NewOrderForm/index.tsx b/src/components/forms/NewOrderForm/index.tsx index 23aa4d94..2f254c9f 100644 --- a/src/components/forms/NewOrderForm/index.tsx +++ b/src/components/forms/NewOrderForm/index.tsx @@ -5,24 +5,23 @@ import CheckboxField from "@/components/ui/Form/fields/CheckboxField"; import InputField from "@/components/ui/Form/fields/InputField"; import RadioGroupField from "@/components/ui/Form/fields/RadioGroupField"; import { zodResolver } from "@hookform/resolvers/zod"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { useForm } from "react-hook-form"; import AddressFields from "./AddressFields"; import type { - common_Order, common_OrderNew, SubmitOrderResponse, ValidateOrderItemsInsertResponse, } from "@/api/proto-http/frontend"; +import { useHeroContext } from "@/components/contexts/HeroContext"; import InputMaskedField from "@/components/ui/Form/fields/InputMaskedField"; +import { serviceClient } from "@/lib/api"; import { useRouter } from "next/navigation"; +import { toast } from "sonner"; import PromoCode from "./PromoCode"; import { CheckoutData, checkoutSchema, defaultData } from "./schema"; import { mapFormFieldToOrderDataFormat } from "./utils"; -import { useHeroContext } from "@/components/contexts/HeroContext"; -import { serviceClient } from "@/lib/api"; -import { toast } from "sonner"; export default function NewOrderForm({ order, diff --git a/src/components/sections/Cart/CartItemRow.tsx b/src/components/sections/Cart/CartItemRow.tsx index 4c9e7ee1..26d6070a 100644 --- a/src/components/sections/Cart/CartItemRow.tsx +++ b/src/components/sections/Cart/CartItemRow.tsx @@ -1,6 +1,7 @@ import { changeCartProductQuantity, removeCartProduct } from "@/actions/cart"; import type { common_OrderItem } from "@/api/proto-http/frontend"; import ImageComponent from "@/components/ui/Image"; +import Size from "../Common/Size"; import ProductAmountButtons from "./ProductAmountButtons"; export default function CartItemRow({ @@ -10,8 +11,6 @@ export default function CartItemRow({ }) { if (!product) return null; - const basicCurrencyValue = product.productPrice; - return (
@@ -26,16 +25,18 @@ export default function CartItemRow({

{product.productName}

{product.color}

- {/* // TO-DO map size id */} -

{product.orderItem?.sizeId}

+

+ {product.orderItem?.sizeId && ( + + )} +

- {product.id !== undefined && basicCurrencyValue && ( + {product.orderItem?.productId !== undefined && ( diff --git a/src/components/sections/Cart/CartProductsList/index.tsx b/src/components/sections/Cart/CartProductsList/index.tsx index 599804cb..6935f52b 100644 --- a/src/components/sections/Cart/CartProductsList/index.tsx +++ b/src/components/sections/Cart/CartProductsList/index.tsx @@ -1,13 +1,10 @@ +import { addCartProduct, clearCartProducts } from "@/actions/cart"; import Button from "@/components/ui/Button"; import { serviceClient } from "@/lib/api"; +import { getValidateOrderItemsInsertItems } from "@/lib/utils/cart"; import Link from "next/link"; import CartItemRow from "../CartItemRow"; -import { - getCartProductIdAndSizeFromKey, - getCookieCart, - getValidateOrderItemsInsertItems, -} from "@/lib/utils/cart"; -import { clearCartProducts, addCartProduct } from "@/actions/cart"; +import SelectedCurrency from "../TotalPrice/SelectedCurrency"; import HACK__UpdateCookieCart from "./HACK__UpdateCookieCart"; export default async function CartProductsList() { @@ -55,6 +52,8 @@ export default async function CartProductsList() { ))} +

total:

+
); } diff --git a/src/components/sections/Cart/ProductAmountButtons.tsx b/src/components/sections/Cart/ProductAmountButtons.tsx index eaf39c34..de1d6991 100644 --- a/src/components/sections/Cart/ProductAmountButtons.tsx +++ b/src/components/sections/Cart/ProductAmountButtons.tsx @@ -8,17 +8,14 @@ type Props = { id, size, operation, - price, }: { id: number; size: string; - price: number; operation: "increase" | "decrease"; }) => void; removeProduct: ({ id, size }: { id: number; size: string }) => void; id: number; size: string; - price: number; }; export default function ProductAmountButtons({ @@ -26,7 +23,6 @@ export default function ProductAmountButtons({ removeProduct, id, size, - price, }: Props) { // todo: check if product is in stock @@ -38,7 +34,7 @@ export default function ProductAmountButtons({ onClick={(e: React.MouseEvent) => { e.preventDefault(); - changeProductAmount({ id, size, operation: "increase", price }); + changeProductAmount({ id, size, operation: "increase" }); }} > [+] @@ -48,7 +44,7 @@ export default function ProductAmountButtons({ onClick={(e: React.MouseEvent) => { e.preventDefault(); - changeProductAmount({ id, size, operation: "decrease", price }); + changeProductAmount({ id, size, operation: "decrease" }); }} > [-] diff --git a/src/components/sections/Common/Size.tsx b/src/components/sections/Common/Size.tsx new file mode 100644 index 00000000..5589f2cf --- /dev/null +++ b/src/components/sections/Common/Size.tsx @@ -0,0 +1,8 @@ +"use client"; +import { useHeroContext } from "@/components/contexts/HeroContext"; + +export default function Size({ sizeId }: { sizeId: number }) { + const { dictionary } = useHeroContext(); + + return <>{dictionary?.sizes?.find((size) => size.id === sizeId)?.name}; +}