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[]
|
pages?: Page[]
|
||||||
commerceFeatures: Record<string, boolean>
|
commerceFeatures: Record<string, boolean>
|
||||||
}
|
}
|
||||||
|
categories: any[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const Layout: FC<Props> = ({
|
const Layout: FC<Props> = ({
|
||||||
|
@ -5,7 +5,7 @@ import { Searchbar, UserNav } from '@components/common'
|
|||||||
import NavbarRoot from './NavbarRoot'
|
import NavbarRoot from './NavbarRoot'
|
||||||
import s from './Navbar.module.css'
|
import s from './Navbar.module.css'
|
||||||
|
|
||||||
const Navbar: FC = () => (
|
const Navbar: FC = ({ categories }: any) => (
|
||||||
<NavbarRoot>
|
<NavbarRoot>
|
||||||
<Container>
|
<Container>
|
||||||
<div className="relative flex flex-row justify-between py-4 align-center md:py-6">
|
<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">
|
<Link href="/search">
|
||||||
<a className={s.link}>All</a>
|
<a className={s.link}>All</a>
|
||||||
</Link>
|
</Link>
|
||||||
<Link href="/search?q=clothes">
|
{/* <Link href="/search?q=clothes">
|
||||||
<a className={s.link}>Clothes</a>
|
<a className={s.link}>Clothes</a>
|
||||||
</Link>
|
</Link>
|
||||||
<Link href="/search?q=accessories">
|
<Link href="/search?q=accessories">
|
||||||
@ -27,7 +27,7 @@ const Navbar: FC = () => (
|
|||||||
</Link>
|
</Link>
|
||||||
<Link href="/search?q=shoes">
|
<Link href="/search?q=shoes">
|
||||||
<a className={s.link}>Shoes</a>
|
<a className={s.link}>Shoes</a>
|
||||||
</Link>
|
</Link> */}
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { Product } from '@commerce/types'
|
|
||||||
import { normalizeProduct } from '../../../lib/normalize'
|
import { normalizeProduct } from '../../../lib/normalize'
|
||||||
import getAllProducts from '../../../product/get-all-products'
|
|
||||||
import type { ProductsHandlers } from '../products'
|
import type { ProductsHandlers } from '../products'
|
||||||
|
|
||||||
const SORT: { [key: string]: string | undefined } = {
|
const SORT: { [key: string]: string | undefined } = {
|
||||||
@ -22,7 +20,9 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
|
|||||||
}
|
}
|
||||||
let sort = {}
|
let sort = {}
|
||||||
|
|
||||||
if (search) filter['$text'] = { $search: search }
|
if (search) {
|
||||||
|
filter['$text'] = { $search: search }
|
||||||
|
}
|
||||||
|
|
||||||
if (category) {
|
if (category) {
|
||||||
const cat: any = await config.storeApiFetch('/v2/category', {
|
const cat: any = await config.storeApiFetch('/v2/category', {
|
||||||
@ -44,13 +44,29 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
|
|||||||
const productIds: string[] = cat.productsList
|
const productIds: string[] = cat.productsList
|
||||||
.filter((p: any) => p.checked)
|
.filter((p: any) => p.checked)
|
||||||
.map((p: any) => p.id)
|
.map((p: any) => p.id)
|
||||||
filter = {
|
if (filter['$and']) {
|
||||||
$and: [
|
filter['$and'].push({
|
||||||
filter,
|
_id: { $in: productIds },
|
||||||
{
|
})
|
||||||
_id: { $in: productIds },
|
} else {
|
||||||
},
|
filter = {
|
||||||
],
|
$and: [
|
||||||
|
filter,
|
||||||
|
{
|
||||||
|
_id: { $in: productIds },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (brand) {
|
||||||
|
if (filter['$and']) {
|
||||||
|
filter['$and'].push({ 'trademark.code': brand })
|
||||||
|
} else {
|
||||||
|
filter = {
|
||||||
|
$and: [filter, { 'trademark.code': brand }],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,8 +77,6 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
|
|||||||
if (sortValue && direction) {
|
if (sortValue && direction) {
|
||||||
switch (sortValue) {
|
switch (sortValue) {
|
||||||
case 'latest':
|
case 'latest':
|
||||||
// 'desc'
|
|
||||||
console.log(`sort by ${sortValue} not implemented`)
|
|
||||||
case 'trending':
|
case 'trending':
|
||||||
// 'desc'
|
// 'desc'
|
||||||
console.log(`sort by ${sortValue} not implemented`)
|
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', {
|
const { datas } = await config.storeApiFetch('/v2/products', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -14,7 +14,6 @@ const checkoutApi: AquilacmsApiHandler<any> = async (req, res, config) => {
|
|||||||
const { cookies } = req
|
const { cookies } = req
|
||||||
const cartId = cookies[config.cartCookie]
|
const cartId = cookies[config.cartCookie]
|
||||||
const token = cookies[config.customerCookie]
|
const token = cookies[config.customerCookie]
|
||||||
console.log(config.customerCookie, cookies)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!cartId) {
|
if (!cartId) {
|
||||||
@ -22,9 +21,15 @@ const checkoutApi: AquilacmsApiHandler<any> = async (req, res, config) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!token)
|
||||||
|
return res.status(401).json({
|
||||||
|
data: null,
|
||||||
|
errors: [{ message: 'You need to be logged in to continue' }],
|
||||||
|
})
|
||||||
|
|
||||||
if (fullCheckout) {
|
if (fullCheckout) {
|
||||||
const { data } = await config.storeApiFetch(
|
const { data } = await config.storeApiFetch(
|
||||||
`/v/carts/${cartId}/redirect_urls`,
|
`/v3/carts/${cartId}/redirect_urls`,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ const signup: SignupHandlers['signup'] = async ({
|
|||||||
lastName: Joi.string().min(1),
|
lastName: Joi.string().min(1),
|
||||||
email: Joi.string().email({ tlds: false }),
|
email: Joi.string().email({ tlds: false }),
|
||||||
password: Joi.string().pattern(
|
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
|
preview?: boolean
|
||||||
} = {}): Promise<GetAllPagesResult> {
|
} = {}): Promise<GetAllPagesResult> {
|
||||||
config = getConfig(config)
|
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(
|
const { datas }: { datas: AquilacmsStatic[] } = await config.storeApiFetch(
|
||||||
'/v2/statics',
|
'/v2/statics',
|
||||||
{
|
{
|
||||||
|
@ -23,34 +23,57 @@ async function getSiteInfo({
|
|||||||
config?: AquilacmsConfig
|
config?: AquilacmsConfig
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
} = {}): Promise<GetSiteInfoResult> {
|
} = {}): Promise<GetSiteInfoResult> {
|
||||||
// TODO:
|
|
||||||
config = getConfig(config)
|
config = getConfig(config)
|
||||||
const { datas } = await config.storeApiFetch('/v2/categories', {
|
const [p1, p2]: { datas: any[]; count: number }[] = await Promise.all([
|
||||||
method: 'POST',
|
config.storeApiFetch('/v2/categories', {
|
||||||
body: JSON.stringify({
|
method: 'POST',
|
||||||
lang: 'en',
|
body: JSON.stringify({
|
||||||
PostBody: {
|
lang: 'en',
|
||||||
filter: {
|
PostBody: {
|
||||||
action: 'catalog',
|
filter: {
|
||||||
|
action: 'catalog',
|
||||||
|
},
|
||||||
|
limit: 10,
|
||||||
|
page: 1,
|
||||||
|
structure: {
|
||||||
|
code: 1,
|
||||||
|
slug: 1,
|
||||||
|
name: 1,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
limit: 10,
|
}),
|
||||||
page: 1,
|
|
||||||
structure: {
|
|
||||||
code: 1,
|
|
||||||
slug: 1,
|
|
||||||
name: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
})
|
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 {
|
return {
|
||||||
categories: datas.map((c: any) => ({
|
categories: categories.map((c: any) => ({
|
||||||
path: c.slug['en'],
|
path: c.slug['en'],
|
||||||
entityId: c._id,
|
entityId: c._id,
|
||||||
name: c.name,
|
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 (search) url.searchParams.set('search', search)
|
||||||
if (categoryId) url.searchParams.set('category', String(categoryId))
|
if (categoryId) url.searchParams.set('category', String(categoryId))
|
||||||
if (Number.isInteger(brandId))
|
if (brandId) url.searchParams.set('brand', String(brandId))
|
||||||
url.searchParams.set('brand', String(brandId))
|
|
||||||
if (sort) url.searchParams.set('sort', sort)
|
if (sort) url.searchParams.set('sort', sort)
|
||||||
|
|
||||||
return fetch({
|
return fetch({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user