import React, {useState} from 'react'
import router from 'next/router'
import Link from 'next/link'
import axios from 'axios'
import {Button} from '@rmwc/button'
import ActionBar from '~/components/admin/actionBar'
import Table from '~/components/table'
CategoryList.getInitialProps = async ({ctx}) => {
const {data: categories} = await ctx.axios.get('/api/categories')
return {categories}
}
export default function CategoryList({categories}) {
console.log(categories)
return (
<>
router.push('/admin/categories/new')}>Create New category
category.name},
{name: 'Items', extractor: category => category.items?.length || '0'},
{name: 'URL Slug', extractor: category => {category.urlslug} },
{name: 'Parent', extractor: category => category.parent?.name || '(none)'},
{name: 'Description', extractor: category => {category.description}
},
{name: 'Actions', extractor: category => (
Edit
{/* Delete not available in API yet */}
{/* Delete */}
)}
]}
// Map in an id property so the table can use array.map
rows={categories}
/>
>
)
}
async function remove(category){
// Placeholder for when we have delete in the API
}