Non-admin navigate categories
parent
ad53c4d8f4
commit
04f9546522
@ -0,0 +1,20 @@
|
||||
import React from 'react'
|
||||
import Link from 'next/link'
|
||||
|
||||
import styles from '../card/style.module.css'
|
||||
|
||||
export default function CategoryCard({category}) {
|
||||
const count = category.items ? category.items.length : category.item_count
|
||||
|
||||
return (
|
||||
<div className={styles.card} style={{display: 'inline-block', maxWidth: 300, margin: 16}}>
|
||||
<h3><Link href={`/store/category/${category.urlslug}`}><a>{category.name}</a></Link></h3>
|
||||
<div className={styles['card-text']} style={{textAlign: 'center'}}>{category.description}</div>
|
||||
<ul className={styles['card-details']}>
|
||||
<li className={styles['number-in-stock']}>
|
||||
{count} item{count !== 1 ? 's' : ''}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
import Head from 'next/head'
|
||||
|
||||
import CategoryCard from '~/components/categoryCard'
|
||||
import styles from './category/style.module.css'
|
||||
|
||||
Categories.getInitialProps = async ({ctx}) => {
|
||||
const {data: categories} = await ctx.axios.get('/api/categories')
|
||||
return {categories}
|
||||
}
|
||||
|
||||
export default function Categories({categories: allCategories}) {
|
||||
const topCategories = allCategories.filter(cat => !cat.parent)
|
||||
return (
|
||||
<>
|
||||
<Head><title>Categories</title></Head>
|
||||
<h2>Categories</h2>
|
||||
{topCategories.length > 0 && <div className={styles.childCategories}>
|
||||
{topCategories.map(category => (
|
||||
<CategoryCard category={category}/>
|
||||
))}
|
||||
</div>}
|
||||
</>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue