Skip to content

Commit

Permalink
regenerated models refactor and bugfixes (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevelko authored Aug 25, 2024
1 parent d984fa2 commit 50520c0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 33 deletions.
3 changes: 1 addition & 2 deletions src/app/archive/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export default async function Page() {
{a.archive?.archiveBody?.heading}
</div>
<div className="flex justify-between gap-6">
{/* @ts-ignore */}
<p>{a.archive?.archiveBody?.description}</p>
<p>{a.archive?.archiveBody?.text}</p>
<p>{a.archive?.createdAt}</p>
</div>
</div>
Expand Down
15 changes: 8 additions & 7 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -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 && <HeroSection {...main} />} */}
{main && <HeroSection {...main} />}
<CoreLayout>
<AdsSection ads={ads} />
<Button asChild style={ButtonStyle.bigButton}>
<Link href="/catalog">view all</Link>
</Button>
<ProductsSection products={productsFeatured} />
<ProductsSection products={hero.productsFeatured} />
</CoreLayout>
</>
);
Expand Down
9 changes: 4 additions & 5 deletions src/components/forms/NewOrderForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 8 additions & 7 deletions src/components/sections/Cart/CartItemRow.tsx
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -10,8 +11,6 @@ export default function CartItemRow({
}) {
if (!product) return null;

const basicCurrencyValue = product.productPrice;

return (
<div className="flex justify-between gap-6 text-textColor">
<div className="flex w-1/2 gap-6">
Expand All @@ -26,16 +25,18 @@ export default function CartItemRow({
<div className="space-y-2">
<p className="text-md">{product.productName}</p>
<p className="text-sm">{product.color}</p>
{/* // TO-DO map size id */}
<p className="text-xs">{product.orderItem?.sizeId}</p>
<p className="text-xs">
{product.orderItem?.sizeId && (
<Size sizeId={product.orderItem?.sizeId} />
)}
</p>
</div>
</div>
<div className="flex w-1/2 whitespace-nowrap text-sm">
{product.id !== undefined && basicCurrencyValue && (
{product.orderItem?.productId !== undefined && (
<ProductAmountButtons
id={product.id}
id={product.orderItem?.productId}
size={product.orderItem?.sizeId + "" || ""}
price={parseInt(basicCurrencyValue)}
removeProduct={removeCartProduct}
changeProductAmount={changeCartProductQuantity}
/>
Expand Down
11 changes: 5 additions & 6 deletions src/components/sections/Cart/CartProductsList/index.tsx
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -55,6 +52,8 @@ export default async function CartProductsList() {
</Link>
</Button>
))}
<p className="mb-8 text-sm">total:</p>
<SelectedCurrency baseCurrencyTotal={Number(response.totalSale?.value)} />
</div>
);
}
8 changes: 2 additions & 6 deletions src/components/sections/Cart/ProductAmountButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@ 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({
changeProductAmount,
removeProduct,
id,
size,
price,
}: Props) {
// todo: check if product is in stock

Expand All @@ -38,7 +34,7 @@ export default function ProductAmountButtons({
onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();

changeProductAmount({ id, size, operation: "increase", price });
changeProductAmount({ id, size, operation: "increase" });
}}
>
[+]
Expand All @@ -48,7 +44,7 @@ export default function ProductAmountButtons({
onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();

changeProductAmount({ id, size, operation: "decrease", price });
changeProductAmount({ id, size, operation: "decrease" });
}}
>
[-]
Expand Down
8 changes: 8 additions & 0 deletions src/components/sections/Common/Size.tsx
Original file line number Diff line number Diff line change
@@ -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}</>;
}

0 comments on commit 50520c0

Please sign in to comment.