diff --git a/proto b/proto index 2ed69669..d90a83ff 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 2ed69669078ede137ae770434e8e519302c3dbcd +Subproject commit d90a83ff5a1e175b66c3e71a33b45dd12da704eb diff --git a/src/api/proto-http/common/index.ts b/src/api/proto-http/common/index.ts index abb3d0e4..f25dd4b9 100644 --- a/src/api/proto-http/common/index.ts +++ b/src/api/proto-http/common/index.ts @@ -110,49 +110,95 @@ export type BuyerInsert = { receivePromoEmails: boolean | undefined; }; -export type OrderFactor = - | "ORDER_FACTOR_UNKNOWN" - | "ORDER_FACTOR_ASC" - | "ORDER_FACTOR_DESC"; -export type SortFactor = - | "SORT_FACTOR_UNKNOWN" - | "SORT_FACTOR_CREATED_AT" - | "SORT_FACTOR_UPDATED_AT" - | "SORT_FACTOR_NAME" - | "SORT_FACTOR_PRICE"; -export type FilterConditions = { - from: string | undefined; - to: string | undefined; - onSale: boolean | undefined; - color: string | undefined; - categoryIds: number[] | undefined; - sizesIds: number[] | undefined; - preorder: boolean | undefined; - byTag: string | undefined; +export type CategoryEnum = + | "CATEGORY_ENUM_UNKNOWN" + | "CATEGORY_ENUM_T_SHIRT" + | "CATEGORY_ENUM_JEANS" + | "CATEGORY_ENUM_DRESS" + | "CATEGORY_ENUM_JACKET" + | "CATEGORY_ENUM_SWEATER" + | "CATEGORY_ENUM_PANT" + | "CATEGORY_ENUM_SKIRT" + | "CATEGORY_ENUM_SHORT" + | "CATEGORY_ENUM_BLAZER" + | "CATEGORY_ENUM_COAT" + | "CATEGORY_ENUM_SOCKS" + | "CATEGORY_ENUM_UNDERWEAR" + | "CATEGORY_ENUM_BRA" + | "CATEGORY_ENUM_HAT" + | "CATEGORY_ENUM_SCARF" + | "CATEGORY_ENUM_GLOVES" + | "CATEGORY_ENUM_SHOES" + | "CATEGORY_ENUM_BELT" + | "CATEGORY_ENUM_OTHER"; +export type SizeEnum = + | "SIZE_ENUM_UNKNOWN" + | "SIZE_ENUM_XXS" + | "SIZE_ENUM_XS" + | "SIZE_ENUM_S" + | "SIZE_ENUM_M" + | "SIZE_ENUM_L" + | "SIZE_ENUM_XL" + | "SIZE_ENUM_XXL" + | "SIZE_ENUM_OS"; +export type MeasurementNameEnum = + | "MEASUREMENT_NAME_ENUM_UNKNOWN" + | "MEASUREMENT_NAME_ENUM_WAIST" + | "MEASUREMENT_NAME_ENUM_INSEAM" + | "MEASUREMENT_NAME_ENUM_LENGTH" + | "MEASUREMENT_NAME_ENUM_RISE" + | "MEASUREMENT_NAME_ENUM_HIPS" + | "MEASUREMENT_NAME_ENUM_SHOULDERS" + | "MEASUREMENT_NAME_ENUM_BUST" + | "MEASUREMENT_NAME_ENUM_SLEEVE" + | "MEASUREMENT_NAME_ENUM_WIDTH" + | "MEASUREMENT_NAME_ENUM_HEIGHT"; +export type GenderEnum = + | "GENDER_ENUM_UNKNOWN" + | "GENDER_ENUM_MALE" + | "GENDER_ENUM_FEMALE" + | "GENDER_ENUM_UNISEX"; +export type Category = { + id: number | undefined; + name: CategoryEnum | undefined; }; -export type PaymentMethodNameEnum = - | "PAYMENT_METHOD_NAME_ENUM_UNKNOWN" - | "PAYMENT_METHOD_NAME_ENUM_CARD" - | "PAYMENT_METHOD_NAME_ENUM_ETH" - | "PAYMENT_METHOD_NAME_ENUM_USDT_TRON" - | "PAYMENT_METHOD_NAME_ENUM_USDT_SHASTA"; -// Payment represents the payment table -export type Payment = { +export type Size = { id: number | undefined; - createdAt: wellKnownTimestamp | undefined; - modifiedAt: wellKnownTimestamp | undefined; - paymentInsert: PaymentInsert | undefined; + name: SizeEnum | undefined; }; -export type PaymentInsert = { - paymentMethod: PaymentMethodNameEnum | undefined; - transactionId: string | undefined; - transactionAmount: googletype_Decimal | undefined; - transactionAmountPaymentCurrency: googletype_Decimal | undefined; - payer: string | undefined; - payee: string | undefined; - isTransactionDone: boolean | undefined; +export type MeasurementName = { + id: number | undefined; + name: MeasurementNameEnum | undefined; +}; + +export type ProductNew = { + product: ProductInsert | undefined; + sizeMeasurements: SizeWithMeasurementInsert[] | undefined; + mediaIds: number[] | undefined; + tags: ProductTagInsert[] | undefined; +}; + +export type ProductInsert = { + productBody: ProductBody | undefined; + thumbnailMediaId: number | undefined; +}; + +export type ProductBody = { + preorder: wellKnownTimestamp | undefined; + name: string | undefined; + brand: string | undefined; + sku: string | undefined; + color: string | undefined; + colorHex: string | undefined; + countryOfOrigin: string | undefined; + price: googletype_Decimal | undefined; + salePercentage: googletype_Decimal | undefined; + categoryId: number | undefined; + description: string | undefined; + hidden: boolean | undefined; + targetGender: GenderEnum | undefined; }; // A representation of a decimal value, such as 2.5. Clients may convert values @@ -209,6 +255,124 @@ export type googletype_Decimal = { value: string | undefined; }; +export type SizeWithMeasurementInsert = { + productSize: ProductSizeInsert | undefined; + measurements: ProductMeasurementInsert[] | undefined; +}; + +export type ProductSizeInsert = { + quantity: googletype_Decimal | undefined; + sizeId: number | undefined; +}; + +export type ProductMeasurementInsert = { + measurementNameId: number | undefined; + measurementValue: googletype_Decimal | undefined; +}; + +export type ProductTagInsert = { + tag: string | undefined; +}; + +export type ProductFull = { + product: Product | undefined; + sizes: ProductSize[] | undefined; + measurements: ProductMeasurement[] | undefined; + media: MediaFull[] | undefined; + tags: ProductTag[] | undefined; +}; + +export type Product = { + id: number | undefined; + createdAt: wellKnownTimestamp | undefined; + updatedAt: wellKnownTimestamp | undefined; + slug: string | undefined; + productDisplay: ProductDisplay | undefined; +}; + +export type ProductDisplay = { + productBody: ProductBody | undefined; + thumbnail: MediaFull | undefined; +}; + +export type ProductSize = { + id: number | undefined; + quantity: googletype_Decimal | undefined; + productId: number | undefined; + sizeId: number | undefined; +}; + +export type ProductMeasurement = { + id: number | undefined; + productId: number | undefined; + productSizeId: number | undefined; + measurementNameId: number | undefined; + measurementValue: googletype_Decimal | undefined; +}; + +export type ProductTag = { + id: number | undefined; + productId: number | undefined; + productTagInsert: ProductTagInsert | undefined; +}; + +export type ProductMeasurementUpdate = { + sizeId: number | undefined; + measurementNameId: number | undefined; + measurementValue: googletype_Decimal | undefined; +}; + +export type SizeWithMeasurement = { + productSize: ProductSize | undefined; + measurements: ProductMeasurement[] | undefined; +}; + +export type OrderFactor = + | "ORDER_FACTOR_UNKNOWN" + | "ORDER_FACTOR_ASC" + | "ORDER_FACTOR_DESC"; +export type SortFactor = + | "SORT_FACTOR_UNKNOWN" + | "SORT_FACTOR_CREATED_AT" + | "SORT_FACTOR_UPDATED_AT" + | "SORT_FACTOR_NAME" + | "SORT_FACTOR_PRICE"; +export type FilterConditions = { + from: string | undefined; + to: string | undefined; + onSale: boolean | undefined; + gender: GenderEnum | undefined; + color: string | undefined; + categoryIds: number[] | undefined; + sizesIds: number[] | undefined; + preorder: boolean | undefined; + byTag: string | undefined; +}; + +export type PaymentMethodNameEnum = + | "PAYMENT_METHOD_NAME_ENUM_UNKNOWN" + | "PAYMENT_METHOD_NAME_ENUM_CARD" + | "PAYMENT_METHOD_NAME_ENUM_ETH" + | "PAYMENT_METHOD_NAME_ENUM_USDT_TRON" + | "PAYMENT_METHOD_NAME_ENUM_USDT_SHASTA"; +// Payment represents the payment table +export type Payment = { + id: number | undefined; + createdAt: wellKnownTimestamp | undefined; + modifiedAt: wellKnownTimestamp | undefined; + paymentInsert: PaymentInsert | undefined; +}; + +export type PaymentInsert = { + paymentMethod: PaymentMethodNameEnum | undefined; + transactionId: string | undefined; + transactionAmount: googletype_Decimal | undefined; + transactionAmountPaymentCurrency: googletype_Decimal | undefined; + payer: string | undefined; + payee: string | undefined; + isTransactionDone: boolean | undefined; +}; + // PaymentMethod represents the payment_method table export type PaymentMethod = { id: number | undefined; @@ -322,169 +486,6 @@ export type OrderStatus = { name: OrderStatusEnum | undefined; }; -export type CategoryEnum = - | "CATEGORY_ENUM_UNKNOWN" - | "CATEGORY_ENUM_T_SHIRT" - | "CATEGORY_ENUM_JEANS" - | "CATEGORY_ENUM_DRESS" - | "CATEGORY_ENUM_JACKET" - | "CATEGORY_ENUM_SWEATER" - | "CATEGORY_ENUM_PANT" - | "CATEGORY_ENUM_SKIRT" - | "CATEGORY_ENUM_SHORT" - | "CATEGORY_ENUM_BLAZER" - | "CATEGORY_ENUM_COAT" - | "CATEGORY_ENUM_SOCKS" - | "CATEGORY_ENUM_UNDERWEAR" - | "CATEGORY_ENUM_BRA" - | "CATEGORY_ENUM_HAT" - | "CATEGORY_ENUM_SCARF" - | "CATEGORY_ENUM_GLOVES" - | "CATEGORY_ENUM_SHOES" - | "CATEGORY_ENUM_BELT" - | "CATEGORY_ENUM_OTHER"; -export type SizeEnum = - | "SIZE_ENUM_UNKNOWN" - | "SIZE_ENUM_XXS" - | "SIZE_ENUM_XS" - | "SIZE_ENUM_S" - | "SIZE_ENUM_M" - | "SIZE_ENUM_L" - | "SIZE_ENUM_XL" - | "SIZE_ENUM_XXL" - | "SIZE_ENUM_OS"; -export type MeasurementNameEnum = - | "MEASUREMENT_NAME_ENUM_UNKNOWN" - | "MEASUREMENT_NAME_ENUM_WAIST" - | "MEASUREMENT_NAME_ENUM_INSEAM" - | "MEASUREMENT_NAME_ENUM_LENGTH" - | "MEASUREMENT_NAME_ENUM_RISE" - | "MEASUREMENT_NAME_ENUM_HIPS" - | "MEASUREMENT_NAME_ENUM_SHOULDERS" - | "MEASUREMENT_NAME_ENUM_BUST" - | "MEASUREMENT_NAME_ENUM_SLEEVE" - | "MEASUREMENT_NAME_ENUM_WIDTH" - | "MEASUREMENT_NAME_ENUM_HEIGHT"; -export type GenderEnum = - | "GENDER_ENUM_UNKNOWN" - | "GENDER_ENUM_MALE" - | "GENDER_ENUM_FEMALE" - | "GENDER_ENUM_UNISEX"; -export type Category = { - id: number | undefined; - name: CategoryEnum | undefined; -}; - -export type Size = { - id: number | undefined; - name: SizeEnum | undefined; -}; - -export type MeasurementName = { - id: number | undefined; - name: MeasurementNameEnum | undefined; -}; - -export type ProductNew = { - product: ProductInsert | undefined; - sizeMeasurements: SizeWithMeasurementInsert[] | undefined; - mediaIds: number[] | undefined; - tags: ProductTagInsert[] | undefined; -}; - -export type ProductInsert = { - productBody: ProductBody | undefined; - thumbnailMediaId: number | undefined; -}; - -export type ProductBody = { - preorder: wellKnownTimestamp | undefined; - name: string | undefined; - brand: string | undefined; - sku: string | undefined; - color: string | undefined; - colorHex: string | undefined; - countryOfOrigin: string | undefined; - price: googletype_Decimal | undefined; - salePercentage: googletype_Decimal | undefined; - categoryId: number | undefined; - description: string | undefined; - hidden: boolean | undefined; - targetGender: GenderEnum | undefined; -}; - -export type SizeWithMeasurementInsert = { - productSize: ProductSizeInsert | undefined; - measurements: ProductMeasurementInsert[] | undefined; -}; - -export type ProductSizeInsert = { - quantity: googletype_Decimal | undefined; - sizeId: number | undefined; -}; - -export type ProductMeasurementInsert = { - measurementNameId: number | undefined; - measurementValue: googletype_Decimal | undefined; -}; - -export type ProductTagInsert = { - tag: string | undefined; -}; - -export type ProductFull = { - product: Product | undefined; - sizes: ProductSize[] | undefined; - measurements: ProductMeasurement[] | undefined; - media: MediaFull[] | undefined; - tags: ProductTag[] | undefined; -}; - -export type Product = { - id: number | undefined; - createdAt: wellKnownTimestamp | undefined; - updatedAt: wellKnownTimestamp | undefined; - slug: string | undefined; - productDisplay: ProductDisplay | undefined; -}; - -export type ProductDisplay = { - productBody: ProductBody | undefined; - thumbnail: MediaFull | undefined; -}; - -export type ProductSize = { - id: number | undefined; - quantity: googletype_Decimal | undefined; - productId: number | undefined; - sizeId: number | undefined; -}; - -export type ProductMeasurement = { - id: number | undefined; - productId: number | undefined; - productSizeId: number | undefined; - measurementNameId: number | undefined; - measurementValue: googletype_Decimal | undefined; -}; - -export type ProductTag = { - id: number | undefined; - productId: number | undefined; - productTagInsert: ProductTagInsert | undefined; -}; - -export type ProductMeasurementUpdate = { - sizeId: number | undefined; - measurementNameId: number | undefined; - measurementValue: googletype_Decimal | undefined; -}; - -export type SizeWithMeasurement = { - productSize: ProductSize | undefined; - measurements: ProductMeasurement[] | undefined; -}; - export type Dictionary = { categories: Category[] | undefined; measurements: MeasurementName[] | undefined; diff --git a/src/api/proto-http/frontend/index.ts b/src/api/proto-http/frontend/index.ts index bd5d8322..42dafaf5 100644 --- a/src/api/proto-http/frontend/index.ts +++ b/src/api/proto-http/frontend/index.ts @@ -349,6 +349,7 @@ export type common_FilterConditions = { from: string | undefined; to: string | undefined; onSale: boolean | undefined; + gender: common_GenderEnum | undefined; color: string | undefined; categoryIds: number[] | undefined; sizesIds: number[] | undefined; @@ -749,6 +750,9 @@ export function createFrontendServiceClient( if (request.filterConditions?.onSale) { queryParams.push(`filterConditions.onSale=${encodeURIComponent(request.filterConditions.onSale.toString())}`) } + if (request.filterConditions?.gender) { + queryParams.push(`filterConditions.gender=${encodeURIComponent(request.filterConditions.gender.toString())}`) + } if (request.filterConditions?.color) { queryParams.push(`filterConditions.color=${encodeURIComponent(request.filterConditions.color.toString())}`) } diff --git a/src/app/cart/checkout/page.tsx b/src/app/cart/checkout/page.tsx index 337e1559..c4c8a782 100644 --- a/src/app/cart/checkout/page.tsx +++ b/src/app/cart/checkout/page.tsx @@ -1,4 +1,7 @@ -import { common_OrderItemInsert } from "@/api/proto-http/frontend"; +import { + common_OrderItemInsert, + common_OrderNew, +} from "@/api/proto-http/frontend"; import NewOrderForm from "@/components/forms/NewOrderForm"; import { redirect } from "next/navigation"; import CoreLayout from "@/components/layouts/CoreLayout"; @@ -6,6 +9,7 @@ import { getCartProductSlugAndSizeFromKey, getCookieCart, } from "@/lib/utils/cart"; +import { serviceClient } from "@/lib/api"; export default async function Page() { const cartData = getCookieCart(); @@ -36,9 +40,51 @@ export default async function Page() { [] as common_OrderItemInsert[], ); + async function submitNewOrder(newOrderData: common_OrderNew) { + "use server"; + + try { + const submitOrderResponse = await serviceClient.SubmitOrder({ + order: newOrderData, + }); + + console.log("new order"); + console.log(submitOrderResponse); + + const { order } = submitOrderResponse; + + if (!order?.uuid) { + console.log("no data to create order invoice"); + + return { + ok: false, + }; + } + + const getOrderInvoiceResponse = await serviceClient.GetOrderInvoice({ + orderUuid: order.uuid, + paymentMethod: "PAYMENT_METHOD_NAME_ENUM_USDT_SHASTA", + }); + + console.log("new invoice"); + console.log(getOrderInvoiceResponse); + + return { + ok: true, + submitOrderResponse, + getOrderInvoiceResponse, + }; + } catch (error) { + console.error("Error submitting new order:", error); + return { + ok: false, + }; + } + } + return ( - + ); } diff --git a/src/components/forms/NewOrderForm/index.tsx b/src/components/forms/NewOrderForm/index.tsx index 6f0495af..eabd7ded 100644 --- a/src/components/forms/NewOrderForm/index.tsx +++ b/src/components/forms/NewOrderForm/index.tsx @@ -9,23 +9,22 @@ import { useState } from "react"; import { useForm } from "react-hook-form"; import AddressFields from "./AddressFields"; -import { - SubmitOrderRequest, - common_AddressInsert, - common_BuyerInsert, +import type { common_OrderItemInsert, common_OrderNew, } from "@/api/proto-http/frontend"; import InputMaskedField from "@/components/ui/Form/fields/InputMaskedField"; -import { serviceClient } from "@/lib/api"; import { CheckoutData, checkoutSchema, defaultData } from "./schema"; +import { mapFormFieldToOrderDataFormat } from "./utils"; export default function NewOrderForm({ initialData, orderItems, + submitNewOrder, }: { initialData?: CheckoutData; orderItems: common_OrderItemInsert[]; + submitNewOrder: (newOrderData: common_OrderNew) => Promise<{ ok: boolean }>; }) { const [loading, setLoading] = useState(false); @@ -39,73 +38,20 @@ export default function NewOrderForm({ ); const paymentMethod = form.watch("paymentMethod"); - console.log(paymentMethod); - const onSubmit = async (data: CheckoutData) => { + const newOrderData = mapFormFieldToOrderDataFormat(data, orderItems); + try { - // todo: check if all items are in stock + const data = await submitNewOrder(newOrderData); - const response = await serviceClient.SubmitOrder( - createSubmitOrderRequest(data), - ); - console.log("Order submitted successfully:", response); + console.log("submit new order response", data); + + console.log("New order submitted successfully"); } catch (error) { - console.error("Error submitting order:", error); + console.error("Error submitting new order:", error); } }; - function createSubmitOrderRequest(data: CheckoutData): SubmitOrderRequest { - const shippingAddress: common_AddressInsert = { - street: data.address, - houseNumber: "1", // common_AddressInsert will be changed to just have full address - apartmentNumber: data.additionalAddress, - city: data.city, - state: data.state, - country: data.country, - postalCode: data.postalCode, - }; - - const billingAddress: common_AddressInsert | undefined = - data.billingAddressIsSameAsAddress - ? shippingAddress - : data.billingAddress - ? { - street: data.billingAddress.address, - houseNumber: "1", // common_AddressInsert will be changed to just have full address - apartmentNumber: data.billingAddress.additionalAddress, - city: data.billingAddress.city, - state: data.billingAddress.state, - country: data.billingAddress.country, - postalCode: data.billingAddress.postalCode, - } - : undefined; - - const buyer: common_BuyerInsert = { - firstName: data.firstName, - lastName: data.lastName, - email: data.email, - phone: data.phone, - receivePromoEmails: data.subscribe, - }; - - const order: common_OrderNew = { - items: orderItems, - shippingAddress, - billingAddress, - buyer, - // TO-DO map payment method and carrier id from dictionary - // paymentMethodId: mapPaymentMethod(data.paymentMethod), - // shipmentCarrierId: mapShipmentCarrierId(data.shippingMethod), - paymentMethodId: 1, - shipmentCarrierId: 1, - promoCode: undefined, // Add promo code if applicable - }; - - return { - order, - }; - } - return (