mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
fix: Remove custom code and clean all code
This commit is contained in:
parent
c4ec67a1e0
commit
efc8a01cdb
@ -1,6 +1,6 @@
|
|||||||
import { FC, useEffect, useState, useCallback } from 'react'
|
import { FC, useEffect, useState, useCallback } from 'react'
|
||||||
import { Logo, Button, Input } from '@components/ui'
|
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 { useUI } from '@components/ui/context'
|
||||||
import { validate } from 'email-validator'
|
import { validate } from 'email-validator'
|
||||||
|
|
||||||
|
@ -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>
|
export type SelectedOptions = Record<string, string | null>
|
||||||
import { Dispatch, SetStateAction } from 'react'
|
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,
|
|
||||||
}
|
|
||||||
: {}
|
|
||||||
}
|
|
||||||
|
@ -48,7 +48,6 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
|||||||
algorithm: 'HS256',
|
algorithm: 'HS256',
|
||||||
})
|
})
|
||||||
let checkouturl = `${config.storeUrl}/login/token/${token}`
|
let checkouturl = `${config.storeUrl}/login/token/${token}`
|
||||||
console.log('checkouturl', checkouturl)
|
|
||||||
if (fullCheckout) {
|
if (fullCheckout) {
|
||||||
res.redirect(checkouturl)
|
res.redirect(checkouturl)
|
||||||
return
|
return
|
||||||
|
@ -17,7 +17,6 @@ const loginEndpoint: GetAPISchema<
|
|||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
debugger
|
|
||||||
try {
|
try {
|
||||||
const body = req.body ?? {}
|
const body = req.body ?? {}
|
||||||
return await handlers['login']({ ...ctx, body })
|
return await handlers['login']({ ...ctx, body })
|
||||||
|
@ -146,7 +146,6 @@ export const createEndpoint =
|
|||||||
options?: API['schema']['endpoint']['options']
|
options?: API['schema']['endpoint']['options']
|
||||||
}
|
}
|
||||||
): NextApiHandler => {
|
): NextApiHandler => {
|
||||||
debugger
|
|
||||||
return getEndpoint(commerce, { ...endpoint, ...context })
|
return getEndpoint(commerce, { ...endpoint, ...context })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ const loginEndpoint: GetAPISchema<
|
|||||||
LoginSchema<any>
|
LoginSchema<any>
|
||||||
>['endpoint']['handler'] = async (ctx) => {
|
>['endpoint']['handler'] = async (ctx) => {
|
||||||
const { req, res, handlers } = ctx
|
const { req, res, handlers } = ctx
|
||||||
debugger
|
|
||||||
if (
|
if (
|
||||||
!isAllowedOperation(req, res, {
|
!isAllowedOperation(req, res, {
|
||||||
POST: handlers['login'],
|
POST: handlers['login'],
|
||||||
@ -16,7 +15,6 @@ const loginEndpoint: GetAPISchema<
|
|||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
debugger
|
|
||||||
try {
|
try {
|
||||||
const body = req.body ?? {}
|
const body = req.body ?? {}
|
||||||
return await handlers['login']({ ...ctx, body })
|
return await handlers['login']({ ...ctx, body })
|
||||||
|
@ -11,7 +11,6 @@ export default function getAllPagesOperation() {
|
|||||||
config?: Partial<CommercelayerAPI>
|
config?: Partial<CommercelayerAPI>
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
}): Promise<GetAllPagesResult> {
|
}): Promise<GetAllPagesResult> {
|
||||||
console.log(`config`, config, preview)
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
pages: [
|
pages: [
|
||||||
{
|
{
|
||||||
|
@ -3,10 +3,11 @@ import type { GraphQLFetcher } from '@commerce/api'
|
|||||||
import type { CommercelayerConfig } from '../index'
|
import type { CommercelayerConfig } from '../index'
|
||||||
import fetch from './fetch'
|
import fetch from './fetch'
|
||||||
|
|
||||||
const fetchGraphqlApi: (getConfig: () => CommercelayerConfig) => GraphQLFetcher =
|
const fetchGraphqlApi: (
|
||||||
|
getConfig: () => CommercelayerConfig
|
||||||
|
) => GraphQLFetcher =
|
||||||
(getConfig) =>
|
(getConfig) =>
|
||||||
async (query: string, { variables, preview } = {}, fetchOptions) => {
|
async (query: string, { variables, preview } = {}, fetchOptions) => {
|
||||||
debugger
|
|
||||||
const config = getConfig()
|
const config = getConfig()
|
||||||
const res = await fetch(config.commerceUrl, {
|
const res = await fetch(config.commerceUrl, {
|
||||||
...fetchOptions,
|
...fetchOptions,
|
||||||
|
@ -17,14 +17,14 @@ export const handler: MutationHook<any> = {
|
|||||||
localOrderId ||
|
localOrderId ||
|
||||||
(credentials.accessToken &&
|
(credentials.accessToken &&
|
||||||
(await Order.withCredentials(credentials).create({})).id)
|
(await Order.withCredentials(credentials).create({})).id)
|
||||||
if (orderId && input.sizeId) {
|
if (orderId && input.variantId) {
|
||||||
!localOrderId && localStorage.setItem('CL_ORDER_ID', orderId)
|
!localOrderId && localStorage.setItem('CL_ORDER_ID', orderId)
|
||||||
const lineItem = await LineItem.withCredentials(credentials).create(
|
const lineItem = await LineItem.withCredentials(credentials).create(
|
||||||
{
|
{
|
||||||
skuCode: input.sizeId,
|
skuCode: input.variantId,
|
||||||
order: Order.build({ id: orderId }),
|
order: Order.build({ id: orderId }),
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
reference: input.variantId,
|
reference: input.productId,
|
||||||
_update_quantity: 1,
|
_update_quantity: 1,
|
||||||
},
|
},
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -41,10 +41,10 @@ export const handler: MutationHook<any> = {
|
|||||||
variant: {
|
variant: {
|
||||||
id: lineItem.data.id,
|
id: lineItem.data.id,
|
||||||
name: attributes.name,
|
name: attributes.name,
|
||||||
sku: input.sizeId,
|
sku: input.variantId,
|
||||||
price: attributes.unit_amount_float,
|
price: attributes.unit_amount_float,
|
||||||
image: {
|
image: {
|
||||||
url: `/commercelayer_assets/${input.variantId}_FLAT.png`,
|
url: `/commercelayer_assets/${input.productId}_FLAT.png`,
|
||||||
altText: 'Black Women Long Sleeve Shirt',
|
altText: 'Black Women Long Sleeve Shirt',
|
||||||
width: 1000,
|
width: 1000,
|
||||||
height: 1000,
|
height: 1000,
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
],
|
],
|
||||||
"variants": [
|
"variants": [
|
||||||
{
|
{
|
||||||
"id": "SHIRTWLS000000FFFFFF",
|
"id": "SHIRTWLS000000FFFFFFXSXX",
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
@ -42,7 +42,12 @@
|
|||||||
"label": "XS"
|
"label": "XS"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "SHIRTWLS000000FFFFFFSXXX",
|
||||||
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
"id": "SHIRTWLS000000FFFFFFSXXX",
|
"id": "SHIRTWLS000000FFFFFFSXXX",
|
||||||
@ -52,7 +57,12 @@
|
|||||||
"label": "S"
|
"label": "S"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "SHIRTWLS000000FFFFFFMXXX",
|
||||||
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
"id": "SHIRTWLS000000FFFFFFMXXX",
|
"id": "SHIRTWLS000000FFFFFFMXXX",
|
||||||
@ -62,7 +72,12 @@
|
|||||||
"label": "M"
|
"label": "M"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "SHIRTWLS000000FFFFFFLXXX",
|
||||||
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
"id": "SHIRTWLS000000FFFFFFLXXX",
|
"id": "SHIRTWLS000000FFFFFFLXXX",
|
||||||
@ -138,7 +153,7 @@
|
|||||||
],
|
],
|
||||||
"variants": [
|
"variants": [
|
||||||
{
|
{
|
||||||
"id": "EMUG12OZFFFFFF000000",
|
"id": "EMUG12OZFFFFFF000000XXXX",
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
@ -212,7 +227,7 @@
|
|||||||
],
|
],
|
||||||
"variants": [
|
"variants": [
|
||||||
{
|
{
|
||||||
"id": "VFLEXFIT000000FFFFFF",
|
"id": "VFLEXFIT000000FFFFFFXXXX",
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
@ -268,7 +283,7 @@
|
|||||||
],
|
],
|
||||||
"variants": [
|
"variants": [
|
||||||
{
|
{
|
||||||
"id": "FACEMASK000000FFFFFF",
|
"id": "FACEMASK000000FFFFFFXXXX",
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
@ -324,7 +339,7 @@
|
|||||||
],
|
],
|
||||||
"variants": [
|
"variants": [
|
||||||
{
|
{
|
||||||
"id": "SHIRTWLS9397A0000000",
|
"id": "SHIRTWLS9397A0000000XSXX",
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
@ -335,7 +350,12 @@
|
|||||||
"label": "XS"
|
"label": "XS"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "SHIRTWLS9397A0000000SXXX",
|
||||||
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
"id": "SHIRTWLS9397A0000000SXXX",
|
"id": "SHIRTWLS9397A0000000SXXX",
|
||||||
@ -345,7 +365,12 @@
|
|||||||
"label": "S"
|
"label": "S"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "SHIRTWLS9397A0000000MXXX",
|
||||||
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
"id": "SHIRTWLS9397A0000000MXXX",
|
"id": "SHIRTWLS9397A0000000MXXX",
|
||||||
@ -355,7 +380,12 @@
|
|||||||
"label": "M"
|
"label": "M"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "SHIRTWLS9397A0000000LXXX",
|
||||||
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
"id": "SHIRTWLS9397A0000000LXXX",
|
"id": "SHIRTWLS9397A0000000LXXX",
|
||||||
@ -419,7 +449,7 @@
|
|||||||
],
|
],
|
||||||
"variants": [
|
"variants": [
|
||||||
{
|
{
|
||||||
"id": "FACEMASKFFFFFF000000",
|
"id": "FACEMASKFFFFFF000000XXXX",
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
@ -475,7 +505,7 @@
|
|||||||
],
|
],
|
||||||
"variants": [
|
"variants": [
|
||||||
{
|
{
|
||||||
"id": "BEANIEXXFFFFFF000000",
|
"id": "BEANIEXXFFFFFF000000XXXX",
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
@ -531,7 +561,7 @@
|
|||||||
],
|
],
|
||||||
"variants": [
|
"variants": [
|
||||||
{
|
{
|
||||||
"id": "DUFFLBAGFFFFFF000000",
|
"id": "DUFFLBAGFFFFFF000000XXXX",
|
||||||
"options": [
|
"options": [
|
||||||
{
|
{
|
||||||
"__typename": "MultipleChoiceOption",
|
"__typename": "MultipleChoiceOption",
|
||||||
|
@ -21,9 +21,7 @@ export const handler: SWRHook<any> = {
|
|||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
query: '',
|
query: '',
|
||||||
},
|
},
|
||||||
async fetcher({ input, options, fetch }) {
|
async fetcher({ input, options, fetch }) {},
|
||||||
debugger
|
|
||||||
},
|
|
||||||
useHook:
|
useHook:
|
||||||
({ useData }) =>
|
({ useData }) =>
|
||||||
({ search, categoryId, brandId }) => {
|
({ search, categoryId, brandId }) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user