mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
New Release (#371)
* Custom Checkout Progress * Updates to Checkout * Custom Checkout Progress * Adding tabs * Adding Collapse * Adding Collapse * Improving Sidebar Scroll * Modif footer * Changes * More design updates * sidebar cart * More design updates * More design updates * More design updates * More design updates * Types * Types * Design Updates * More changes * More changes * More changes * Changes * Changes * Changes * New tailwind required changes * Sidebar Styling issues with Mobile * Latest changes - Normalizing cart * Styling Fixes * New changes * Changes * latest * Refactor and Renaming some UI Props * Adding Quantity Component * Adding Rating Component * Rating Component * More updates * User Select disabled, plus hidding horizontal scroll bars * Changes * Adding ProductOptions Component and more helpers * Styling updates * Styling updates * Fix for slim tags * Missmatch with RightArrow * Footer updates and some styles * Latest Updates * Latest Updates * Latest Updates * Removing Portal, since it's not needed. We might add it later I'd rather not to. * Removing Portal, since it's not needed. We might add it later I'd rather not to. * Sam backdrop filter * General UI Improvements * General UI Improvements * Search now with Geist Colors * Now with Geist Colors * Changes * Scroll for Mobile on IOs devises * LoadingDots Working (: * Changes * More Changes * Perf changes * More perf changes * Fade to the Nametags in the ProductCard * changes * Search issue ui * Search issue ui * Make sure to only refresh navbar and modals when required * Index revalidate * Fixed image issue * hide album scroll on windows * Fix scrollbar * Changing * Adding 404 with Layout * Removing Toast * Adding Assets * Adding Assets * Progress with LocalProvider * New productTag * Only images for the drop * changes * Empty SWRhooks * Adding Local Provider * Working local * Working view of a LocalProvider * More updates * Changes * Removed react-ticker * default to local if no env available * default to local if no env available * add missing `@` to css import * rewrite search rewrites to multiple pages * allow requests in getStaticProps to execute in parallel * make type import explicit * add a tsconfig.js file * use local provider in tsconfig.js * avoid a circular dependency * Saleor was not in the providers list * avoid circular dependency in bigcommerce * Adding more to the Local Provider (#366) * Adding more data * Adding more data * optimize assets (#370) * Optimize assets (#372) * optimize assets * remove assets * remove assets * cart enabled * Adding saleor * Changes with Webpack * Changes Co-authored-by: Luis Alvarez <luis@vercel.com> Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com> Co-authored-by: Shu Ding <g@shud.in>
This commit is contained in:
1
framework/local/.env.template
Normal file
1
framework/local/.env.template
Normal file
@@ -0,0 +1 @@
|
||||
COMMERCE_PROVIDER=local
|
1
framework/local/README.md
Normal file
1
framework/local/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# Next.js Local Provider
|
1
framework/local/api/endpoints/cart/index.ts
Normal file
1
framework/local/api/endpoints/cart/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
1
framework/local/api/endpoints/catalog/index.ts
Normal file
1
framework/local/api/endpoints/catalog/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
1
framework/local/api/endpoints/catalog/products.ts
Normal file
1
framework/local/api/endpoints/catalog/products.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
1
framework/local/api/endpoints/checkout/index.ts
Normal file
1
framework/local/api/endpoints/checkout/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
1
framework/local/api/endpoints/customer/index.ts
Normal file
1
framework/local/api/endpoints/customer/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
1
framework/local/api/endpoints/login/index.ts
Normal file
1
framework/local/api/endpoints/login/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
1
framework/local/api/endpoints/logout/index.ts
Normal file
1
framework/local/api/endpoints/logout/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
1
framework/local/api/endpoints/signup/index.ts
Normal file
1
framework/local/api/endpoints/signup/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
1
framework/local/api/endpoints/wishlist/index.tsx
Normal file
1
framework/local/api/endpoints/wishlist/index.tsx
Normal file
@@ -0,0 +1 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
42
framework/local/api/index.ts
Normal file
42
framework/local/api/index.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { CommerceAPI, CommerceAPIConfig } from '@commerce/api'
|
||||
import { getCommerceApi as commerceApi } from '@commerce/api'
|
||||
import createFetcher from './utils/fetch-local'
|
||||
|
||||
import getAllPages from './operations/get-all-pages'
|
||||
import getPage from './operations/get-page'
|
||||
import getSiteInfo from './operations/get-site-info'
|
||||
import getCustomerWishlist from './operations/get-customer-wishlist'
|
||||
import getAllProductPaths from './operations/get-all-product-paths'
|
||||
import getAllProducts from './operations/get-all-products'
|
||||
import getProduct from './operations/get-product'
|
||||
|
||||
export interface LocalConfig extends CommerceAPIConfig {}
|
||||
const config: LocalConfig = {
|
||||
commerceUrl: '',
|
||||
apiToken: '',
|
||||
cartCookie: '',
|
||||
customerCookie: '',
|
||||
cartCookieMaxAge: 2592000,
|
||||
fetch: createFetcher(() => getCommerceApi().getConfig()),
|
||||
}
|
||||
|
||||
const operations = {
|
||||
getAllPages,
|
||||
getPage,
|
||||
getSiteInfo,
|
||||
getCustomerWishlist,
|
||||
getAllProductPaths,
|
||||
getAllProducts,
|
||||
getProduct,
|
||||
}
|
||||
|
||||
export const provider = { config, operations }
|
||||
|
||||
export type Provider = typeof provider
|
||||
export type LocalAPI<P extends Provider = Provider> = CommerceAPI<P | any>
|
||||
|
||||
export function getCommerceApi<P extends Provider>(
|
||||
customProvider: P = provider as any
|
||||
): LocalAPI<P> {
|
||||
return commerceApi(customProvider as any)
|
||||
}
|
19
framework/local/api/operations/get-all-pages.ts
Normal file
19
framework/local/api/operations/get-all-pages.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export type Page = { url: string }
|
||||
export type GetAllPagesResult = { pages: Page[] }
|
||||
import type { LocalConfig } from '../index'
|
||||
|
||||
export default function getAllPagesOperation() {
|
||||
function getAllPages({
|
||||
config,
|
||||
preview,
|
||||
}: {
|
||||
url?: string
|
||||
config?: Partial<LocalConfig>
|
||||
preview?: boolean
|
||||
}): Promise<GetAllPagesResult> {
|
||||
return Promise.resolve({
|
||||
pages: [],
|
||||
})
|
||||
}
|
||||
return getAllPages
|
||||
}
|
15
framework/local/api/operations/get-all-product-paths.ts
Normal file
15
framework/local/api/operations/get-all-product-paths.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import data from '../../data.json'
|
||||
|
||||
export type GetAllProductPathsResult = {
|
||||
products: Array<{ path: string }>
|
||||
}
|
||||
|
||||
export default function getAllProductPathsOperation() {
|
||||
function getAllProductPaths(): Promise<GetAllProductPathsResult> {
|
||||
return Promise.resolve({
|
||||
products: data.products.map(({ path }) => ({ path })),
|
||||
})
|
||||
}
|
||||
|
||||
return getAllProductPaths
|
||||
}
|
25
framework/local/api/operations/get-all-products.ts
Normal file
25
framework/local/api/operations/get-all-products.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Product } from '@commerce/types/product'
|
||||
import { GetAllProductsOperation } from '@commerce/types/product'
|
||||
import type { OperationContext } from '@commerce/api/operations'
|
||||
import type { LocalConfig, Provider } from '../index'
|
||||
import data from '../../data.json'
|
||||
|
||||
export default function getAllProductsOperation({
|
||||
commerce,
|
||||
}: OperationContext<any>) {
|
||||
async function getAllProducts<T extends GetAllProductsOperation>({
|
||||
query = '',
|
||||
variables,
|
||||
config,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: T['variables']
|
||||
config?: Partial<LocalConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<{ products: Product[] | any[] }> {
|
||||
return {
|
||||
products: data.products,
|
||||
}
|
||||
}
|
||||
return getAllProducts
|
||||
}
|
6
framework/local/api/operations/get-customer-wishlist.ts
Normal file
6
framework/local/api/operations/get-customer-wishlist.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export default function getCustomerWishlistOperation() {
|
||||
function getCustomerWishlist(): any {
|
||||
return { wishlist: {} }
|
||||
}
|
||||
return getCustomerWishlist
|
||||
}
|
13
framework/local/api/operations/get-page.ts
Normal file
13
framework/local/api/operations/get-page.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export type Page = any
|
||||
export type GetPageResult = { page?: Page }
|
||||
|
||||
export type PageVariables = {
|
||||
id: number
|
||||
}
|
||||
|
||||
export default function getPageOperation() {
|
||||
function getPage(): Promise<GetPageResult> {
|
||||
return Promise.resolve({})
|
||||
}
|
||||
return getPage
|
||||
}
|
26
framework/local/api/operations/get-product.ts
Normal file
26
framework/local/api/operations/get-product.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { LocalConfig } from '../index'
|
||||
import { Product } from '@commerce/types/product'
|
||||
import { GetProductOperation } from '@commerce/types/product'
|
||||
import data from '../../data.json'
|
||||
import type { OperationContext } from '@commerce/api/operations'
|
||||
|
||||
export default function getProductOperation({
|
||||
commerce,
|
||||
}: OperationContext<any>) {
|
||||
async function getProduct<T extends GetProductOperation>({
|
||||
query = '',
|
||||
variables,
|
||||
config,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: T['variables']
|
||||
config?: Partial<LocalConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<Product | {} | any> {
|
||||
return {
|
||||
product: data.products.find(({ slug }) => slug === variables!.slug),
|
||||
}
|
||||
}
|
||||
|
||||
return getProduct
|
||||
}
|
43
framework/local/api/operations/get-site-info.ts
Normal file
43
framework/local/api/operations/get-site-info.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
import { Category } from '@commerce/types/site'
|
||||
import { LocalConfig } from '../index'
|
||||
|
||||
export type GetSiteInfoResult<
|
||||
T extends { categories: any[]; brands: any[] } = {
|
||||
categories: Category[]
|
||||
brands: any[]
|
||||
}
|
||||
> = T
|
||||
|
||||
export default function getSiteInfoOperation({}: OperationContext<any>) {
|
||||
function getSiteInfo({
|
||||
query,
|
||||
variables,
|
||||
config: cfg,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: any
|
||||
config?: Partial<LocalConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<GetSiteInfoResult> {
|
||||
return Promise.resolve({
|
||||
categories: [
|
||||
{
|
||||
id: 'new-arrivals',
|
||||
name: 'New Arrivals',
|
||||
slug: 'new-arrivals',
|
||||
path: '/new-arrivals',
|
||||
},
|
||||
{
|
||||
id: 'featured',
|
||||
name: 'Featured',
|
||||
slug: 'featured',
|
||||
path: '/featured',
|
||||
},
|
||||
],
|
||||
brands: [],
|
||||
})
|
||||
}
|
||||
|
||||
return getSiteInfo
|
||||
}
|
6
framework/local/api/operations/index.ts
Normal file
6
framework/local/api/operations/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export { default as getPage } from './get-page'
|
||||
export { default as getSiteInfo } from './get-site-info'
|
||||
export { default as getAllPages } from './get-all-pages'
|
||||
export { default as getProduct } from './get-product'
|
||||
export { default as getAllProducts } from './get-all-products'
|
||||
export { default as getAllProductPaths } from './get-all-product-paths'
|
34
framework/local/api/utils/fetch-local.ts
Normal file
34
framework/local/api/utils/fetch-local.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { FetcherError } from '@commerce/utils/errors'
|
||||
import type { GraphQLFetcher } from '@commerce/api'
|
||||
import type { LocalConfig } from '../index'
|
||||
import fetch from './fetch'
|
||||
|
||||
const fetchGraphqlApi: (getConfig: () => LocalConfig) => GraphQLFetcher =
|
||||
(getConfig) =>
|
||||
async (query: string, { variables, preview } = {}, fetchOptions) => {
|
||||
const config = getConfig()
|
||||
const res = await fetch(config.commerceUrl, {
|
||||
...fetchOptions,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...fetchOptions?.headers,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query,
|
||||
variables,
|
||||
}),
|
||||
})
|
||||
|
||||
const json = await res.json()
|
||||
if (json.errors) {
|
||||
throw new FetcherError({
|
||||
errors: json.errors ?? [{ message: 'Failed to fetch for API' }],
|
||||
status: res.status,
|
||||
})
|
||||
}
|
||||
|
||||
return { data: json.data, res }
|
||||
}
|
||||
|
||||
export default fetchGraphqlApi
|
3
framework/local/api/utils/fetch.ts
Normal file
3
framework/local/api/utils/fetch.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import zeitFetch from '@vercel/fetch'
|
||||
|
||||
export default zeitFetch()
|
3
framework/local/auth/index.ts
Normal file
3
framework/local/auth/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { default as useLogin } from './use-login'
|
||||
export { default as useLogout } from './use-logout'
|
||||
export { default as useSignup } from './use-signup'
|
16
framework/local/auth/use-login.tsx
Normal file
16
framework/local/auth/use-login.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
import useLogin, { UseLogin } from '@commerce/auth/use-login'
|
||||
|
||||
export default useLogin as UseLogin<typeof handler>
|
||||
|
||||
export const handler: MutationHook<any> = {
|
||||
fetchOptions: {
|
||||
query: '',
|
||||
},
|
||||
async fetcher() {
|
||||
return null
|
||||
},
|
||||
useHook: () => () => {
|
||||
return async function () {}
|
||||
},
|
||||
}
|
17
framework/local/auth/use-logout.tsx
Normal file
17
framework/local/auth/use-logout.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
||||
|
||||
export default useLogout as UseLogout<typeof handler>
|
||||
|
||||
export const handler: MutationHook<any> = {
|
||||
fetchOptions: {
|
||||
query: '',
|
||||
},
|
||||
async fetcher() {
|
||||
return null
|
||||
},
|
||||
useHook:
|
||||
({ fetch }) =>
|
||||
() =>
|
||||
async () => {},
|
||||
}
|
19
framework/local/auth/use-signup.tsx
Normal file
19
framework/local/auth/use-signup.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useCallback } from 'react'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
|
||||
|
||||
export default useSignup as UseSignup<typeof handler>
|
||||
|
||||
export const handler: MutationHook<any> = {
|
||||
fetchOptions: {
|
||||
query: '',
|
||||
},
|
||||
async fetcher() {
|
||||
return null
|
||||
},
|
||||
useHook:
|
||||
({ fetch }) =>
|
||||
() =>
|
||||
() => {},
|
||||
}
|
4
framework/local/cart/index.ts
Normal file
4
framework/local/cart/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export { default as useCart } from './use-cart'
|
||||
export { default as useAddItem } from './use-add-item'
|
||||
export { default as useRemoveItem } from './use-remove-item'
|
||||
export { default as useUpdateItem } from './use-update-item'
|
17
framework/local/cart/use-add-item.tsx
Normal file
17
framework/local/cart/use-add-item.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import useAddItem, { UseAddItem } from '@commerce/cart/use-add-item'
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
|
||||
export default useAddItem as UseAddItem<typeof handler>
|
||||
export const handler: MutationHook<any> = {
|
||||
fetchOptions: {
|
||||
query: '',
|
||||
},
|
||||
async fetcher({ input, options, fetch }) {},
|
||||
useHook:
|
||||
({ fetch }) =>
|
||||
() => {
|
||||
return async function addItem() {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
}
|
42
framework/local/cart/use-cart.tsx
Normal file
42
framework/local/cart/use-cart.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { useMemo } from 'react'
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useCart, { UseCart } from '@commerce/cart/use-cart'
|
||||
|
||||
export default useCart as UseCart<typeof handler>
|
||||
|
||||
export const handler: SWRHook<any> = {
|
||||
fetchOptions: {
|
||||
query: '',
|
||||
},
|
||||
async fetcher() {
|
||||
return {
|
||||
id: '',
|
||||
createdAt: '',
|
||||
currency: { code: '' },
|
||||
taxesIncluded: '',
|
||||
lineItems: [],
|
||||
lineItemsSubtotalPrice: '',
|
||||
subtotalPrice: 0,
|
||||
totalPrice: 0,
|
||||
}
|
||||
},
|
||||
useHook:
|
||||
({ useData }) =>
|
||||
(input) => {
|
||||
return useMemo(
|
||||
() =>
|
||||
Object.create(
|
||||
{},
|
||||
{
|
||||
isEmpty: {
|
||||
get() {
|
||||
return true
|
||||
},
|
||||
enumerable: true,
|
||||
},
|
||||
}
|
||||
),
|
||||
[]
|
||||
)
|
||||
},
|
||||
}
|
18
framework/local/cart/use-remove-item.tsx
Normal file
18
framework/local/cart/use-remove-item.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
import useRemoveItem, { UseRemoveItem } from '@commerce/cart/use-remove-item'
|
||||
|
||||
export default useRemoveItem as UseRemoveItem<typeof handler>
|
||||
|
||||
export const handler: MutationHook<any> = {
|
||||
fetchOptions: {
|
||||
query: '',
|
||||
},
|
||||
async fetcher({ input, options, fetch }) {},
|
||||
useHook:
|
||||
({ fetch }) =>
|
||||
() => {
|
||||
return async function removeItem(input) {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
}
|
18
framework/local/cart/use-update-item.tsx
Normal file
18
framework/local/cart/use-update-item.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
import useUpdateItem, { UseUpdateItem } from '@commerce/cart/use-update-item'
|
||||
|
||||
export default useUpdateItem as UseUpdateItem<any>
|
||||
|
||||
export const handler: MutationHook<any> = {
|
||||
fetchOptions: {
|
||||
query: '',
|
||||
},
|
||||
async fetcher({ input, options, fetch }) {},
|
||||
useHook:
|
||||
({ fetch }) =>
|
||||
() => {
|
||||
return async function addItem() {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
}
|
6
framework/local/commerce.config.json
Normal file
6
framework/local/commerce.config.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"provider": "local",
|
||||
"features": {
|
||||
"wishlist": false
|
||||
}
|
||||
}
|
1
framework/local/customer/index.ts
Normal file
1
framework/local/customer/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as useCustomer } from './use-customer'
|
15
framework/local/customer/use-customer.tsx
Normal file
15
framework/local/customer/use-customer.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
||||
|
||||
export default useCustomer as UseCustomer<typeof handler>
|
||||
export const handler: SWRHook<any> = {
|
||||
fetchOptions: {
|
||||
query: '',
|
||||
},
|
||||
async fetcher({ input, options, fetch }) {},
|
||||
useHook: () => () => {
|
||||
return async function addItem() {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
}
|
235
framework/local/data.json
Normal file
235
framework/local/data.json
Normal file
@@ -0,0 +1,235 @@
|
||||
{
|
||||
"products": [
|
||||
{
|
||||
"id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjA=",
|
||||
"name": "New Short Sleeve T-Shirt",
|
||||
"vendor": "Next.js",
|
||||
"path": "/new-short-sleeve-t-shirt",
|
||||
"slug": "new-short-sleeve-t-shirt",
|
||||
"price": { "value": 25, "currencyCode": "USD" },
|
||||
"descriptionHtml": "<p><span>Show off your love for Next.js and Vercel with this unique, </span><strong>limited edition</strong><span> t-shirt. This design is part of a limited run, numbered drop at the June 2021 Next.js Conf. It features a unique, handcrafted triangle design. Get it while supplies last – only 200 of these shirts will be made! </span><strong>All proceeds will be donated to charity.</strong></p>",
|
||||
"images": [
|
||||
{
|
||||
"url": "/assets/drop-shirt-0.png",
|
||||
"altText": "Shirt",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
},
|
||||
{
|
||||
"url": "/assets/drop-shirt-1.png",
|
||||
"altText": "Shirt",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
},
|
||||
{
|
||||
"url": "/assets/drop-shirt-2.png",
|
||||
"altText": "Shirt",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
}
|
||||
],
|
||||
"variants": [
|
||||
{
|
||||
"id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjAss=",
|
||||
"options": [
|
||||
{
|
||||
"__typename": "MultipleChoiceOption",
|
||||
"id": "asd",
|
||||
"displayName": "Size",
|
||||
"values": [
|
||||
{
|
||||
"label": "XL"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"options": [
|
||||
{
|
||||
"id": "option-color",
|
||||
"displayName": "Color",
|
||||
"values": [
|
||||
{
|
||||
"label": "color",
|
||||
"hexColors": ["#222"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "option-size",
|
||||
"displayName": "Size",
|
||||
"values": [
|
||||
{
|
||||
"label": "S"
|
||||
},
|
||||
{
|
||||
"label": "M"
|
||||
},
|
||||
{
|
||||
"label": "L"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "Z2lkOi8vc2hvcGlmeS9Qcm9ksdWN0LzU0NDczMjUwMjQ0MjA=",
|
||||
"name": "Lightweight Jacket",
|
||||
"vendor": "Next.js",
|
||||
"path": "/lightweight-jacket",
|
||||
"slug": "lightweight-jacket",
|
||||
"price": { "value": 249.99, "currencyCode": "USD" },
|
||||
"descriptionHtml": "<p><span>Show off your love for Next.js and Vercel with this unique, </span><strong>limited edition</strong><span> t-shirt. This design is part of a limited run, numbered drop at the June 2021 Next.js Conf. It features a unique, handcrafted triangle design. Get it while supplies last – only 200 of these shirts will be made! </span><strong>All proceeds will be donated to charity.</strong></p>",
|
||||
"images": [
|
||||
{
|
||||
"url": "/assets/lightweight-jacket-0.png",
|
||||
"altText": "Lightweight Jacket",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
},
|
||||
{
|
||||
"url": "/assets/lightweight-jacket-1.png",
|
||||
"altText": "Lightweight Jacket",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
},
|
||||
{
|
||||
"url": "/assets/lightweight-jacket-2.png",
|
||||
"altText": "Lightweight Jacket",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
}
|
||||
],
|
||||
"variants": [
|
||||
{
|
||||
"id": "Z2lkOid8vc2hvcGlmeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjAss=",
|
||||
"options": [
|
||||
{
|
||||
"__typename": "MultipleChoiceOption",
|
||||
"id": "asd",
|
||||
"displayName": "Size",
|
||||
"values": [
|
||||
{
|
||||
"label": "XL"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"options": [
|
||||
{
|
||||
"id": "option-color",
|
||||
"displayName": "Color",
|
||||
"values": [
|
||||
{
|
||||
"label": "color",
|
||||
"hexColors": ["#222"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "option-size",
|
||||
"displayName": "Size",
|
||||
"values": [
|
||||
{
|
||||
"label": "S"
|
||||
},
|
||||
{
|
||||
"label": "M"
|
||||
},
|
||||
{
|
||||
"label": "L"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "Z2lkOis8vc2hvcGlmsddeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjA=",
|
||||
"name": "Shirt",
|
||||
"vendor": "Next.js",
|
||||
"path": "/shirt",
|
||||
"slug": "shirt",
|
||||
"price": { "value": 25, "currencyCode": "USD" },
|
||||
"descriptionHtml": "<p><span>Show off your love for Next.js and Vercel with this unique, </span><strong>limited edition</strong><span> t-shirt. This design is part of a limited run, numbered drop at the June 2021 Next.js Conf. It features a unique, handcrafted triangle design. Get it while supplies last – only 200 of these shirts will be made! </span><strong>All proceeds will be donated to charity.</strong></p>",
|
||||
"images": [
|
||||
{
|
||||
"url": "/assets/t-shirt-0.png",
|
||||
"altText": "Shirt",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
},
|
||||
{
|
||||
"url": "/assets/t-shirt-1.png",
|
||||
"altText": "Shirt",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
},
|
||||
{
|
||||
"url": "/assets/t-shirt-2.png",
|
||||
"altText": "Shirt",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
},
|
||||
{
|
||||
"url": "/assets/t-shirt-3.png",
|
||||
"altText": "Shirt",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
},
|
||||
{
|
||||
"url": "/assets/t-shirt-4.png",
|
||||
"altText": "Shirt",
|
||||
"width": 1000,
|
||||
"height": 1000
|
||||
}
|
||||
],
|
||||
"variants": [
|
||||
{
|
||||
"id": "Z2lkOi8vc2hvcGlmeS9Qcms9kdWN0LzU0NDczMjUwMjQ0MjAss=",
|
||||
"options": [
|
||||
{
|
||||
"__typename": "MultipleChoiceOption",
|
||||
"id": "asd",
|
||||
"displayName": "Size",
|
||||
"values": [
|
||||
{
|
||||
"label": "XL"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"options": [
|
||||
{
|
||||
"id": "option-color",
|
||||
"displayName": "Color",
|
||||
"values": [
|
||||
{
|
||||
"label": "color",
|
||||
"hexColors": ["#222"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "option-size",
|
||||
"displayName": "Size",
|
||||
"values": [
|
||||
{
|
||||
"label": "S"
|
||||
},
|
||||
{
|
||||
"label": "M"
|
||||
},
|
||||
{
|
||||
"label": "L"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
11
framework/local/fetcher.ts
Normal file
11
framework/local/fetcher.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Fetcher } from '@commerce/utils/types'
|
||||
|
||||
export const fetcher: Fetcher = async () => {
|
||||
console.log('FETCHER')
|
||||
const res = await fetch('./data.json')
|
||||
if (res.ok) {
|
||||
const { data } = await res.json()
|
||||
return data
|
||||
}
|
||||
throw res
|
||||
}
|
32
framework/local/index.tsx
Normal file
32
framework/local/index.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as React from 'react'
|
||||
import { ReactNode } from 'react'
|
||||
import { localProvider } from './provider'
|
||||
import {
|
||||
CommerceConfig,
|
||||
CommerceProvider as CoreCommerceProvider,
|
||||
useCommerce as useCoreCommerce,
|
||||
} from '@commerce'
|
||||
|
||||
export const localConfig: CommerceConfig = {
|
||||
locale: 'en-us',
|
||||
cartCookie: 'session',
|
||||
}
|
||||
|
||||
export function CommerceProvider({
|
||||
children,
|
||||
...config
|
||||
}: {
|
||||
children?: ReactNode
|
||||
locale: string
|
||||
} & Partial<CommerceConfig>) {
|
||||
return (
|
||||
<CoreCommerceProvider
|
||||
provider={localProvider}
|
||||
config={{ ...localConfig, ...config }}
|
||||
>
|
||||
{children}
|
||||
</CoreCommerceProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useCommerce = () => useCoreCommerce()
|
8
framework/local/next.config.js
Normal file
8
framework/local/next.config.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const commerce = require('./commerce.config.json')
|
||||
|
||||
module.exports = {
|
||||
commerce,
|
||||
images: {
|
||||
domains: ['localhost'],
|
||||
},
|
||||
}
|
2
framework/local/product/index.ts
Normal file
2
framework/local/product/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default as usePrice } from './use-price'
|
||||
export { default as useSearch } from './use-search'
|
2
framework/local/product/use-price.tsx
Normal file
2
framework/local/product/use-price.tsx
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from '@commerce/product/use-price'
|
||||
export { default } from '@commerce/product/use-price'
|
17
framework/local/product/use-search.tsx
Normal file
17
framework/local/product/use-search.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
||||
export default useSearch as UseSearch<typeof handler>
|
||||
|
||||
export const handler: SWRHook<any> = {
|
||||
fetchOptions: {
|
||||
query: '',
|
||||
},
|
||||
async fetcher({ input, options, fetch }) {},
|
||||
useHook: () => () => {
|
||||
return {
|
||||
data: {
|
||||
products: [],
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
21
framework/local/provider.ts
Normal file
21
framework/local/provider.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { fetcher } from './fetcher'
|
||||
import { handler as useCart } from './cart/use-cart'
|
||||
import { handler as useAddItem } from './cart/use-add-item'
|
||||
import { handler as useUpdateItem } from './cart/use-update-item'
|
||||
import { handler as useRemoveItem } from './cart/use-remove-item'
|
||||
import { handler as useCustomer } from './customer/use-customer'
|
||||
import { handler as useSearch } from './product/use-search'
|
||||
import { handler as useLogin } from './auth/use-login'
|
||||
import { handler as useLogout } from './auth/use-logout'
|
||||
import { handler as useSignup } from './auth/use-signup'
|
||||
|
||||
export type Provider = typeof localProvider
|
||||
export const localProvider = {
|
||||
locale: 'en-us',
|
||||
cartCookie: 'session',
|
||||
fetcher: fetcher,
|
||||
cart: { useCart, useAddItem, useUpdateItem, useRemoveItem },
|
||||
customer: { useCustomer },
|
||||
products: { useSearch },
|
||||
auth: { useLogin, useLogout, useSignup },
|
||||
}
|
13
framework/local/wishlist/use-add-item.tsx
Normal file
13
framework/local/wishlist/use-add-item.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { useCallback } from 'react'
|
||||
|
||||
export function emptyHook() {
|
||||
const useEmptyHook = async (options = {}) => {
|
||||
return useCallback(async function () {
|
||||
return Promise.resolve()
|
||||
}, [])
|
||||
}
|
||||
|
||||
return useEmptyHook
|
||||
}
|
||||
|
||||
export default emptyHook
|
17
framework/local/wishlist/use-remove-item.tsx
Normal file
17
framework/local/wishlist/use-remove-item.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useCallback } from 'react'
|
||||
|
||||
type Options = {
|
||||
includeProducts?: boolean
|
||||
}
|
||||
|
||||
export function emptyHook(options?: Options) {
|
||||
const useEmptyHook = async ({ id }: { id: string | number }) => {
|
||||
return useCallback(async function () {
|
||||
return Promise.resolve()
|
||||
}, [])
|
||||
}
|
||||
|
||||
return useEmptyHook
|
||||
}
|
||||
|
||||
export default emptyHook
|
43
framework/local/wishlist/use-wishlist.tsx
Normal file
43
framework/local/wishlist/use-wishlist.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import { HookFetcher } from '@commerce/utils/types'
|
||||
import type { Product } from '@commerce/types/product'
|
||||
|
||||
const defaultOpts = {}
|
||||
|
||||
export type Wishlist = {
|
||||
items: [
|
||||
{
|
||||
product_id: number
|
||||
variant_id: number
|
||||
id: number
|
||||
product: Product
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
export interface UseWishlistOptions {
|
||||
includeProducts?: boolean
|
||||
}
|
||||
|
||||
export interface UseWishlistInput extends UseWishlistOptions {
|
||||
customerId?: number
|
||||
}
|
||||
|
||||
export const fetcher: HookFetcher<Wishlist | null, UseWishlistInput> = () => {
|
||||
return null
|
||||
}
|
||||
|
||||
export function extendHook(
|
||||
customFetcher: typeof fetcher,
|
||||
// swrOptions?: SwrOptions<Wishlist | null, UseWishlistInput>
|
||||
swrOptions?: any
|
||||
) {
|
||||
const useWishlist = ({ includeProducts }: UseWishlistOptions = {}) => {
|
||||
return { data: null }
|
||||
}
|
||||
|
||||
useWishlist.extend = extendHook
|
||||
|
||||
return useWishlist
|
||||
}
|
||||
|
||||
export default extendHook(fetcher)
|
Reference in New Issue
Block a user