mirror of
https://github.com/DerTyp7/explainegy-nextjs.git
synced 2025-10-30 13:17:13 +01:00
refactor
This commit is contained in:
31
components/CategoryControl.tsx
Normal file
31
components/CategoryControl.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from "react";
|
||||
import { apiUrl } from "@/global";
|
||||
import urlJoin from "url-join";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function CategoryControl({ categoryId }: { categoryId: string }) {
|
||||
const router = useRouter();
|
||||
async function deleteCategory() {
|
||||
await fetch(urlJoin(apiUrl, `categories/${categoryId}`), { method: "DELETE" })
|
||||
.then((response) => response.json())
|
||||
.then((result) => {
|
||||
console.log(result);
|
||||
});
|
||||
router.push("/articles");
|
||||
}
|
||||
|
||||
function editCategory() {
|
||||
router.push("/admin/editor/category/" + categoryId);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button className="danger" onClick={deleteCategory}>
|
||||
Delete
|
||||
</button>
|
||||
<button className="warning" onClick={editCategory}>
|
||||
Edit
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user