This commit is contained in:
Janis
2023-02-08 20:56:22 +01:00
parent 97d8de1a44
commit 730f33879b
17 changed files with 794 additions and 452 deletions

View File

@@ -2,8 +2,11 @@ import React from "react";
import { apiUrl } from "@/global";
import urlJoin from "url-join";
import { useRouter } from "next/navigation";
import { useSession } from "next-auth/react";
export default function CategoryControl({ categoryId }: { categoryId: string }) {
const { data: session } = useSession();
const router = useRouter();
async function deleteCategory() {
await fetch(urlJoin(apiUrl, `categories/${categoryId}`), { method: "DELETE" })
@@ -18,14 +21,18 @@ export default function CategoryControl({ categoryId }: { categoryId: string })
router.push("/admin/editor/category/" + categoryId);
}
return (
<div>
<button className="danger" onClick={deleteCategory}>
Delete
</button>
<button className="warning" onClick={editCategory}>
Edit
</button>
</div>
);
if (session) {
return (
<div>
<button className="danger" onClick={deleteCategory}>
Delete
</button>
<button className="warning" onClick={editCategory}>
Edit
</button>
</div>
);
} else {
return <></>;
}
}