mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 21:21:21 +00:00
fix: signup password validation
feat: add search by brands (WIP)
This commit is contained in:
parent
15d740e85f
commit
164db10e08
@ -43,6 +43,7 @@ interface Props {
|
||||
pages?: Page[]
|
||||
commerceFeatures: Record<string, boolean>
|
||||
}
|
||||
categories: any[]
|
||||
}
|
||||
|
||||
const Layout: FC<Props> = ({
|
||||
|
@ -5,7 +5,7 @@ import { Searchbar, UserNav } from '@components/common'
|
||||
import NavbarRoot from './NavbarRoot'
|
||||
import s from './Navbar.module.css'
|
||||
|
||||
const Navbar: FC = () => (
|
||||
const Navbar: FC = ({ categories }: any) => (
|
||||
<NavbarRoot>
|
||||
<Container>
|
||||
<div className="relative flex flex-row justify-between py-4 align-center md:py-6">
|
||||
@ -19,7 +19,7 @@ const Navbar: FC = () => (
|
||||
<Link href="/search">
|
||||
<a className={s.link}>All</a>
|
||||
</Link>
|
||||
<Link href="/search?q=clothes">
|
||||
{/* <Link href="/search?q=clothes">
|
||||
<a className={s.link}>Clothes</a>
|
||||
</Link>
|
||||
<Link href="/search?q=accessories">
|
||||
@ -27,7 +27,7 @@ const Navbar: FC = () => (
|
||||
</Link>
|
||||
<Link href="/search?q=shoes">
|
||||
<a className={s.link}>Shoes</a>
|
||||
</Link>
|
||||
</Link> */}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
import { Product } from '@commerce/types'
|
||||
import { normalizeProduct } from '../../../lib/normalize'
|
||||
import getAllProducts from '../../../product/get-all-products'
|
||||
import type { ProductsHandlers } from '../products'
|
||||
|
||||
const SORT: { [key: string]: string | undefined } = {
|
||||
@ -22,7 +20,9 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
|
||||
}
|
||||
let sort = {}
|
||||
|
||||
if (search) filter['$text'] = { $search: search }
|
||||
if (search) {
|
||||
filter['$text'] = { $search: search }
|
||||
}
|
||||
|
||||
if (category) {
|
||||
const cat: any = await config.storeApiFetch('/v2/category', {
|
||||
@ -44,6 +44,11 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
|
||||
const productIds: string[] = cat.productsList
|
||||
.filter((p: any) => p.checked)
|
||||
.map((p: any) => p.id)
|
||||
if (filter['$and']) {
|
||||
filter['$and'].push({
|
||||
_id: { $in: productIds },
|
||||
})
|
||||
} else {
|
||||
filter = {
|
||||
$and: [
|
||||
filter,
|
||||
@ -53,6 +58,17 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (brand) {
|
||||
if (filter['$and']) {
|
||||
filter['$and'].push({ 'trademark.code': brand })
|
||||
} else {
|
||||
filter = {
|
||||
$and: [filter, { 'trademark.code': brand }],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sortParam) {
|
||||
const [_sort, direction] = sortParam.split('-')
|
||||
@ -61,8 +77,6 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
|
||||
if (sortValue && direction) {
|
||||
switch (sortValue) {
|
||||
case 'latest':
|
||||
// 'desc'
|
||||
console.log(`sort by ${sortValue} not implemented`)
|
||||
case 'trending':
|
||||
// 'desc'
|
||||
console.log(`sort by ${sortValue} not implemented`)
|
||||
@ -72,23 +86,6 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
lang: 'en',
|
||||
PostBody: {
|
||||
filter,
|
||||
structure: {
|
||||
canonical: 1,
|
||||
reviews: 1,
|
||||
stock: 1,
|
||||
universe: 1,
|
||||
},
|
||||
sort,
|
||||
page: 1,
|
||||
limit: LIMIT,
|
||||
},
|
||||
})
|
||||
)
|
||||
const { datas } = await config.storeApiFetch('/v2/products', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
@ -14,7 +14,6 @@ const checkoutApi: AquilacmsApiHandler<any> = async (req, res, config) => {
|
||||
const { cookies } = req
|
||||
const cartId = cookies[config.cartCookie]
|
||||
const token = cookies[config.customerCookie]
|
||||
console.log(config.customerCookie, cookies)
|
||||
|
||||
try {
|
||||
if (!cartId) {
|
||||
@ -22,9 +21,15 @@ const checkoutApi: AquilacmsApiHandler<any> = async (req, res, config) => {
|
||||
return
|
||||
}
|
||||
|
||||
if (!token)
|
||||
return res.status(401).json({
|
||||
data: null,
|
||||
errors: [{ message: 'You need to be logged in to continue' }],
|
||||
})
|
||||
|
||||
if (fullCheckout) {
|
||||
const { data } = await config.storeApiFetch(
|
||||
`/v/carts/${cartId}/redirect_urls`,
|
||||
`/v3/carts/${cartId}/redirect_urls`,
|
||||
{
|
||||
method: 'POST',
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ const signup: SignupHandlers['signup'] = async ({
|
||||
lastName: Joi.string().min(1),
|
||||
email: Joi.string().email({ tlds: false }),
|
||||
password: Joi.string().pattern(
|
||||
new RegExp('^(?=.*d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^wd:])([^s]){6,}$')
|
||||
new RegExp(/^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\d\s:])([^\s]){6,}$/)
|
||||
),
|
||||
})
|
||||
|
||||
|
@ -33,20 +33,6 @@ async function getAllPages({
|
||||
preview?: boolean
|
||||
} = {}): Promise<GetAllPagesResult> {
|
||||
config = getConfig(config)
|
||||
// const { datas } = await config.storeApiFetch('/v2/categories', {
|
||||
// method: 'POST',
|
||||
// body: JSON.stringify({
|
||||
// lang: 'en',
|
||||
// PostBody: {
|
||||
// filter: {
|
||||
// action: 'page',
|
||||
// },
|
||||
// limit: 10,
|
||||
// page: 1,
|
||||
// },
|
||||
// }),
|
||||
// })
|
||||
|
||||
const { datas }: { datas: AquilacmsStatic[] } = await config.storeApiFetch(
|
||||
'/v2/statics',
|
||||
{
|
||||
|
@ -23,9 +23,9 @@ async function getSiteInfo({
|
||||
config?: AquilacmsConfig
|
||||
preview?: boolean
|
||||
} = {}): Promise<GetSiteInfoResult> {
|
||||
// TODO:
|
||||
config = getConfig(config)
|
||||
const { datas } = await config.storeApiFetch('/v2/categories', {
|
||||
const [p1, p2]: { datas: any[]; count: number }[] = await Promise.all([
|
||||
config.storeApiFetch('/v2/categories', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
lang: 'en',
|
||||
@ -42,15 +42,38 @@ async function getSiteInfo({
|
||||
},
|
||||
},
|
||||
}),
|
||||
})
|
||||
}),
|
||||
config.storeApiFetch('/v2/trademarks', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
PostBody: {
|
||||
limit: 10,
|
||||
structure: {
|
||||
_id: 1,
|
||||
name: 1,
|
||||
code: 1,
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
])
|
||||
|
||||
const categories = p1.datas
|
||||
const brands = p2.datas
|
||||
|
||||
return {
|
||||
categories: datas.map((c: any) => ({
|
||||
categories: categories.map((c: any) => ({
|
||||
path: c.slug['en'],
|
||||
entityId: c._id,
|
||||
name: c.name,
|
||||
})),
|
||||
brands: [],
|
||||
brands: brands.map((b: any) => ({
|
||||
node: {
|
||||
entityId: b._id,
|
||||
path: `brands/${b.code}`,
|
||||
name: b.name,
|
||||
},
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,7 @@ export const handler: SWRHook<
|
||||
|
||||
if (search) url.searchParams.set('search', search)
|
||||
if (categoryId) url.searchParams.set('category', String(categoryId))
|
||||
if (Number.isInteger(brandId))
|
||||
url.searchParams.set('brand', String(brandId))
|
||||
if (brandId) url.searchParams.set('brand', String(brandId))
|
||||
if (sort) url.searchParams.set('sort', sort)
|
||||
|
||||
return fetch({
|
||||
|
Loading…
x
Reference in New Issue
Block a user