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: _categories}) { const [categories, setCategories] = useState(_categories) const remove = uuid => async ev => { if(ev) ev.preventDefault() const {data: categories} = await axios.delete(`/api/categories/${uuid}`) setCategories(categories) } return ( <> 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 )} ]} rows={categories} /> ) } async function remove(category){ // Placeholder for when we have delete in the API }