import React, { useState } from 'react' import { router, useForm, usePage } from '@inertiajs/react' import StudioLayout from '../../Layouts/StudioLayout' import Checkbox from '../../components/ui/Checkbox' function replacePattern(pattern, token, value) { return String(pattern || '').replace(token, String(value)) } export default function StudioNewsTaxonomies() { const { props } = usePage() const [categories, setCategories] = useState(Array.isArray(props.categories) ? props.categories : []) const [tags, setTags] = useState(Array.isArray(props.tags) ? props.tags : []) const categoryForm = useForm({ name: '', slug: '', description: '', position: 0, is_active: true }) const tagForm = useForm({ name: '', slug: '' }) const updateCategory = (index, field, value) => { setCategories((current) => current.map((item, itemIndex) => (itemIndex === index ? { ...item, [field]: value } : item))) } const updateTag = (index, field, value) => { setTags((current) => current.map((item, itemIndex) => (itemIndex === index ? { ...item, [field]: value } : item))) } const saveCategory = (category) => { router.patch(replacePattern(props.updateCategoryUrlPattern, '__CATEGORY__', category.id), category, { preserveScroll: true }) } const saveTag = (tag) => { router.patch(replacePattern(props.updateTagUrlPattern, '__TAG__', tag.id), tag, { preserveScroll: true }) } return (
Categories Tags Back to newsroom

Categories

Stable editorial buckets for the newsroom.

{categories.length} total
{ event.preventDefault(); categoryForm.post(props.storeCategoryUrl) }} className="mt-5 grid gap-3">
categoryForm.setData('name', event.target.value)} placeholder="Category name" className="rounded-2xl border border-white/10 bg-black/20 px-4 py-3 text-white outline-none" /> categoryForm.setData('slug', event.target.value)} placeholder="optional slug" className="rounded-2xl border border-white/10 bg-black/20 px-4 py-3 text-white outline-none" />