From efc8a01cdbc336004a3ef3b11c9950808d6f6494 Mon Sep 17 00:00:00 2001 From: Alessandro Casazza Date: Fri, 17 Dec 2021 20:48:35 +0100 Subject: [PATCH] fix: Remove custom code and clean all code --- components/auth/LoginView.tsx | 2 +- components/product/helpers.ts | 21 +------ .../api/endpoints/checkout/get-checkout.ts | 1 - framework/commerce/api/endpoints/login.ts | 1 - framework/commerce/api/index.ts | 1 - .../api/endpoints/login/index.ts | 2 - .../api/operations/get-all-pages.ts | 1 - .../commercelayer/api/utils/fetch-local.ts | 5 +- framework/commercelayer/cart/use-add-item.tsx | 10 ++-- framework/commercelayer/data.json | 58 ++++++++++++++----- .../commercelayer/product/use-search.tsx | 4 +- 11 files changed, 55 insertions(+), 51 deletions(-) diff --git a/components/auth/LoginView.tsx b/components/auth/LoginView.tsx index 9fba61ae3..5968e7a50 100644 --- a/components/auth/LoginView.tsx +++ b/components/auth/LoginView.tsx @@ -1,6 +1,6 @@ import { FC, useEffect, useState, useCallback } from 'react' import { Logo, Button, Input } from '@components/ui' -import useLogin from '@commerce/auth/use-login' +import useLogin from '@framework/auth/use-login' import { useUI } from '@components/ui/context' import { validate } from 'email-validator' diff --git a/components/product/helpers.ts b/components/product/helpers.ts index 7fff369a1..77e385bb8 100644 --- a/components/product/helpers.ts +++ b/components/product/helpers.ts @@ -1,4 +1,4 @@ -import type { Product, ProductVariant } from '@commerce/types/product' +import type { Product } from '@commerce/types/product' export type SelectedOptions = Record import { Dispatch, SetStateAction } from 'react' @@ -30,22 +30,3 @@ export function selectDefaultOptionFromProduct( })) }) } - -export function getSelectedOptionsIds( - variant: ProductVariant, - opts: SelectedOptions -) { - const [selected] = variant.options.filter((option) => { - const type = option.displayName.toLowerCase() - const typeSelected = option.values.filter( - ({ label }) => label.toLowerCase() === opts[type] - ) - if (typeSelected.length > 0) return true - return false - }) - return selected - ? { - [`${selected.displayName?.toLowerCase()}Id`]: selected.id, - } - : {} -} diff --git a/framework/bigcommerce/api/endpoints/checkout/get-checkout.ts b/framework/bigcommerce/api/endpoints/checkout/get-checkout.ts index e98e6ca54..301d6554c 100644 --- a/framework/bigcommerce/api/endpoints/checkout/get-checkout.ts +++ b/framework/bigcommerce/api/endpoints/checkout/get-checkout.ts @@ -48,7 +48,6 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({ algorithm: 'HS256', }) let checkouturl = `${config.storeUrl}/login/token/${token}` - console.log('checkouturl', checkouturl) if (fullCheckout) { res.redirect(checkouturl) return diff --git a/framework/commerce/api/endpoints/login.ts b/framework/commerce/api/endpoints/login.ts index a066e7ae6..3699c8d7f 100644 --- a/framework/commerce/api/endpoints/login.ts +++ b/framework/commerce/api/endpoints/login.ts @@ -17,7 +17,6 @@ const loginEndpoint: GetAPISchema< ) { return } - debugger try { const body = req.body ?? {} return await handlers['login']({ ...ctx, body }) diff --git a/framework/commerce/api/index.ts b/framework/commerce/api/index.ts index 3e34b3b71..6914b9364 100644 --- a/framework/commerce/api/index.ts +++ b/framework/commerce/api/index.ts @@ -146,7 +146,6 @@ export const createEndpoint = options?: API['schema']['endpoint']['options'] } ): NextApiHandler => { - debugger return getEndpoint(commerce, { ...endpoint, ...context }) } diff --git a/framework/commercelayer/api/endpoints/login/index.ts b/framework/commercelayer/api/endpoints/login/index.ts index 29b737af5..dd1cc643d 100644 --- a/framework/commercelayer/api/endpoints/login/index.ts +++ b/framework/commercelayer/api/endpoints/login/index.ts @@ -8,7 +8,6 @@ const loginEndpoint: GetAPISchema< LoginSchema >['endpoint']['handler'] = async (ctx) => { const { req, res, handlers } = ctx - debugger if ( !isAllowedOperation(req, res, { POST: handlers['login'], @@ -16,7 +15,6 @@ const loginEndpoint: GetAPISchema< ) { return } - debugger try { const body = req.body ?? {} return await handlers['login']({ ...ctx, body }) diff --git a/framework/commercelayer/api/operations/get-all-pages.ts b/framework/commercelayer/api/operations/get-all-pages.ts index 42a79cf0f..d78a95a68 100644 --- a/framework/commercelayer/api/operations/get-all-pages.ts +++ b/framework/commercelayer/api/operations/get-all-pages.ts @@ -11,7 +11,6 @@ export default function getAllPagesOperation() { config?: Partial preview?: boolean }): Promise { - console.log(`config`, config, preview) return Promise.resolve({ pages: [ { diff --git a/framework/commercelayer/api/utils/fetch-local.ts b/framework/commercelayer/api/utils/fetch-local.ts index 831eb9597..0f33745d0 100644 --- a/framework/commercelayer/api/utils/fetch-local.ts +++ b/framework/commercelayer/api/utils/fetch-local.ts @@ -3,10 +3,11 @@ import type { GraphQLFetcher } from '@commerce/api' import type { CommercelayerConfig } from '../index' import fetch from './fetch' -const fetchGraphqlApi: (getConfig: () => CommercelayerConfig) => GraphQLFetcher = +const fetchGraphqlApi: ( + getConfig: () => CommercelayerConfig +) => GraphQLFetcher = (getConfig) => async (query: string, { variables, preview } = {}, fetchOptions) => { - debugger const config = getConfig() const res = await fetch(config.commerceUrl, { ...fetchOptions, diff --git a/framework/commercelayer/cart/use-add-item.tsx b/framework/commercelayer/cart/use-add-item.tsx index 6b1790e93..45f8cc136 100644 --- a/framework/commercelayer/cart/use-add-item.tsx +++ b/framework/commercelayer/cart/use-add-item.tsx @@ -17,14 +17,14 @@ export const handler: MutationHook = { localOrderId || (credentials.accessToken && (await Order.withCredentials(credentials).create({})).id) - if (orderId && input.sizeId) { + if (orderId && input.variantId) { !localOrderId && localStorage.setItem('CL_ORDER_ID', orderId) const lineItem = await LineItem.withCredentials(credentials).create( { - skuCode: input.sizeId, + skuCode: input.variantId, order: Order.build({ id: orderId }), quantity: 1, - reference: input.variantId, + reference: input.productId, _update_quantity: 1, }, // @ts-ignore @@ -41,10 +41,10 @@ export const handler: MutationHook = { variant: { id: lineItem.data.id, name: attributes.name, - sku: input.sizeId, + sku: input.variantId, price: attributes.unit_amount_float, image: { - url: `/commercelayer_assets/${input.variantId}_FLAT.png`, + url: `/commercelayer_assets/${input.productId}_FLAT.png`, altText: 'Black Women Long Sleeve Shirt', width: 1000, height: 1000, diff --git a/framework/commercelayer/data.json b/framework/commercelayer/data.json index 4c64e0453..6513314e9 100644 --- a/framework/commercelayer/data.json +++ b/framework/commercelayer/data.json @@ -31,7 +31,7 @@ ], "variants": [ { - "id": "SHIRTWLS000000FFFFFF", + "id": "SHIRTWLS000000FFFFFFXSXX", "options": [ { "__typename": "MultipleChoiceOption", @@ -42,7 +42,12 @@ "label": "XS" } ] - }, + } + ] + }, + { + "id": "SHIRTWLS000000FFFFFFSXXX", + "options": [ { "__typename": "MultipleChoiceOption", "id": "SHIRTWLS000000FFFFFFSXXX", @@ -52,7 +57,12 @@ "label": "S" } ] - }, + } + ] + }, + { + "id": "SHIRTWLS000000FFFFFFMXXX", + "options": [ { "__typename": "MultipleChoiceOption", "id": "SHIRTWLS000000FFFFFFMXXX", @@ -62,7 +72,12 @@ "label": "M" } ] - }, + } + ] + }, + { + "id": "SHIRTWLS000000FFFFFFLXXX", + "options": [ { "__typename": "MultipleChoiceOption", "id": "SHIRTWLS000000FFFFFFLXXX", @@ -138,7 +153,7 @@ ], "variants": [ { - "id": "EMUG12OZFFFFFF000000", + "id": "EMUG12OZFFFFFF000000XXXX", "options": [ { "__typename": "MultipleChoiceOption", @@ -212,7 +227,7 @@ ], "variants": [ { - "id": "VFLEXFIT000000FFFFFF", + "id": "VFLEXFIT000000FFFFFFXXXX", "options": [ { "__typename": "MultipleChoiceOption", @@ -268,7 +283,7 @@ ], "variants": [ { - "id": "FACEMASK000000FFFFFF", + "id": "FACEMASK000000FFFFFFXXXX", "options": [ { "__typename": "MultipleChoiceOption", @@ -324,7 +339,7 @@ ], "variants": [ { - "id": "SHIRTWLS9397A0000000", + "id": "SHIRTWLS9397A0000000XSXX", "options": [ { "__typename": "MultipleChoiceOption", @@ -335,7 +350,12 @@ "label": "XS" } ] - }, + } + ] + }, + { + "id": "SHIRTWLS9397A0000000SXXX", + "options": [ { "__typename": "MultipleChoiceOption", "id": "SHIRTWLS9397A0000000SXXX", @@ -345,7 +365,12 @@ "label": "S" } ] - }, + } + ] + }, + { + "id": "SHIRTWLS9397A0000000MXXX", + "options": [ { "__typename": "MultipleChoiceOption", "id": "SHIRTWLS9397A0000000MXXX", @@ -355,7 +380,12 @@ "label": "M" } ] - }, + } + ] + }, + { + "id": "SHIRTWLS9397A0000000LXXX", + "options": [ { "__typename": "MultipleChoiceOption", "id": "SHIRTWLS9397A0000000LXXX", @@ -419,7 +449,7 @@ ], "variants": [ { - "id": "FACEMASKFFFFFF000000", + "id": "FACEMASKFFFFFF000000XXXX", "options": [ { "__typename": "MultipleChoiceOption", @@ -475,7 +505,7 @@ ], "variants": [ { - "id": "BEANIEXXFFFFFF000000", + "id": "BEANIEXXFFFFFF000000XXXX", "options": [ { "__typename": "MultipleChoiceOption", @@ -531,7 +561,7 @@ ], "variants": [ { - "id": "DUFFLBAGFFFFFF000000", + "id": "DUFFLBAGFFFFFF000000XXXX", "options": [ { "__typename": "MultipleChoiceOption", diff --git a/framework/commercelayer/product/use-search.tsx b/framework/commercelayer/product/use-search.tsx index 8da1a0b86..d195ad430 100644 --- a/framework/commercelayer/product/use-search.tsx +++ b/framework/commercelayer/product/use-search.tsx @@ -21,9 +21,7 @@ export const handler: SWRHook = { fetchOptions: { query: '', }, - async fetcher({ input, options, fetch }) { - debugger - }, + async fetcher({ input, options, fetch }) {}, useHook: ({ useData }) => ({ search, categoryId, brandId }) => {