-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/submit order request 2 (#114)
* submit order request * submit order refactor * rename refactor * removed console log
- Loading branch information
Showing
10 changed files
with
92 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,57 @@ | ||
import CoreLayout from "@/components/layouts/CoreLayout"; | ||
import { common_OrderItemInsert } from "@/api/proto-http/frontend"; | ||
import CheckoutForm from "@/components/forms/CheckoutForm"; | ||
import CoreLayout from "@/components/layouts/CoreLayout"; | ||
import { | ||
getCartProductSlugAndSizeFromKey, | ||
getCookieCart, | ||
} from "@/lib/utils/cart"; | ||
|
||
export default async function Page() { | ||
const orderItems = createOrderArray(); | ||
|
||
function createOrderArray(): common_OrderItemInsert[] { | ||
const cartItems = getCookieCart(); | ||
if (!cartItems || !cartItems.products) return []; | ||
|
||
const orderArray: common_OrderItemInsert[] = []; | ||
|
||
for (const key in cartItems.products) { | ||
const productData = cartItems.products[key]; | ||
const slugAndSize = getCartProductSlugAndSizeFromKey(key); | ||
|
||
if (!slugAndSize) continue; | ||
|
||
const { slug, size } = slugAndSize; | ||
const productId = getProductIdFromSlug(slug); | ||
|
||
//TO-DO map size id from dictionary | ||
// const sizeId = getSizeIdBySize(size); | ||
|
||
const sizeId = 1; | ||
|
||
const orderItem: common_OrderItemInsert = { | ||
productId, | ||
quantity: productData.quantity, | ||
sizeId, | ||
}; | ||
|
||
orderArray.push(orderItem); | ||
} | ||
|
||
return orderArray; | ||
} | ||
|
||
function getProductIdFromSlug(slug: string): number | undefined { | ||
const [gender, brand, name, id] = slug | ||
?.replaceAll("/product/", "") | ||
.split("/"); | ||
|
||
return id ? parseInt(id) : undefined; | ||
} | ||
|
||
return ( | ||
<CoreLayout> | ||
<CheckoutForm /> | ||
<CheckoutForm orderItems={orderItems} /> | ||
</CoreLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters