fix: Remove custom code and clean all code

This commit is contained in:
Alessandro Casazza 2021-12-17 20:48:35 +01:00
parent c4ec67a1e0
commit efc8a01cdb
No known key found for this signature in database
GPG Key ID: 3AF41B06C6495D3D
11 changed files with 55 additions and 51 deletions

View File

@ -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'

View File

@ -1,4 +1,4 @@
import type { Product, ProductVariant } from '@commerce/types/product'
import type { Product } from '@commerce/types/product'
export type SelectedOptions = Record<string, string | null>
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,
}
: {}
}

View File

@ -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

View File

@ -17,7 +17,6 @@ const loginEndpoint: GetAPISchema<
) {
return
}
debugger
try {
const body = req.body ?? {}
return await handlers['login']({ ...ctx, body })

View File

@ -146,7 +146,6 @@ export const createEndpoint =
options?: API['schema']['endpoint']['options']
}
): NextApiHandler => {
debugger
return getEndpoint(commerce, { ...endpoint, ...context })
}

View File

@ -8,7 +8,6 @@ const loginEndpoint: GetAPISchema<
LoginSchema<any>
>['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 })

View File

@ -11,7 +11,6 @@ export default function getAllPagesOperation() {
config?: Partial<CommercelayerAPI>
preview?: boolean
}): Promise<GetAllPagesResult> {
console.log(`config`, config, preview)
return Promise.resolve({
pages: [
{

View File

@ -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,

View File

@ -17,14 +17,14 @@ export const handler: MutationHook<any> = {
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<any> = {
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,

View File

@ -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",

View File

@ -21,9 +21,7 @@ export const handler: SWRHook<any> = {
fetchOptions: {
query: '',
},
async fetcher({ input, options, fetch }) {
debugger
},
async fetcher({ input, options, fetch }) {},
useHook:
({ useData }) =>
({ search, categoryId, brandId }) => {