diff --git a/app/admin/articles/editor/[articleId]/page.tsx b/app/admin/articles/editor/[articleId]/page.tsx
index db12810..1ae4e26 100644
--- a/app/admin/articles/editor/[articleId]/page.tsx
+++ b/app/admin/articles/editor/[articleId]/page.tsx
@@ -74,7 +74,6 @@ export default function AdminArticlesEditorPage({ params }: { params: { articleI
async function updateArticle() {
console.log("Update article");
const payload: UpdateArticle = {
- id: params.articleId,
title: titleRef.current.value,
introduction: introductionRef.current.value,
markdown: markdown,
@@ -83,7 +82,7 @@ export default function AdminArticlesEditorPage({ params }: { params: { articleI
};
console.log(payload);
- await fetch("/api/articles/", {
+ await fetch(`/api/articles/${params.articleId.toString()}`, {
method: "PUT",
headers: {
Accept: "application/json",
diff --git a/app/admin/categories/editor/[categoryId]/page.tsx b/app/admin/categories/editor/[categoryId]/page.tsx
index 9435edb..21e0aa6 100644
--- a/app/admin/categories/editor/[categoryId]/page.tsx
+++ b/app/admin/categories/editor/[categoryId]/page.tsx
@@ -44,7 +44,6 @@ export default function AdminCategoriesEditor({ params }: { params: { categoryId
async function updateCategory() {
console.log("Update category");
const payload: UpdateCategory = {
- id: params.categoryId,
title: titleRef.current.value,
color: colorRef.current.value,
svg: {
@@ -54,7 +53,7 @@ export default function AdminCategoriesEditor({ params }: { params: { categoryId
};
console.log(payload);
- await fetch("/api/categories/", {
+ await fetch(`/api/categories/${params.categoryId.toString()}`, {
method: "PUT",
headers: {
Accept: "application/json",
diff --git a/app/layout.tsx b/app/layout.tsx
index 1e2e2d5..c5c21dc 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -5,6 +5,8 @@ import Link from "next/link";
import Footer from "../components/Footer";
import Nav from "../components/Nav";
import { FetchManager } from "../manager/fetchManager";
+import AdminNav from "../components/AdminNav";
+import AdminControl from "../components/AdminControl";
export default async function RootLayout({ children }: { children: React.ReactNode }) {
return (
@@ -12,11 +14,10 @@ export default async function RootLayout({ children }: { children: React.ReactNo
-
- Admin
-
{children}
diff --git a/components/AdminControl.tsx b/components/AdminControl.tsx
new file mode 100644
index 0000000..eed3f3f
--- /dev/null
+++ b/components/AdminControl.tsx
@@ -0,0 +1,11 @@
+import React from "react";
+import styles from "../styles/modules/AdminControl.module.scss";
+
+export default function AdminControl() {
+ return (
+
+
+
+
+ );
+}
diff --git a/components/AdminNav.tsx b/components/AdminNav.tsx
new file mode 100644
index 0000000..c09f891
--- /dev/null
+++ b/components/AdminNav.tsx
@@ -0,0 +1,15 @@
+import React from "react";
+import Link from "next/link";
+import styles from "../styles/modules/AdminNav.module.scss";
+
+function AdminNav() {
+ return (
+
+ Admin
+ New article
+ New category
+
+ );
+}
+
+export default AdminNav;
diff --git a/package-lock.json b/package-lock.json
index a318fed..674dd6c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,7 +9,7 @@
"version": "0.2.0",
"dependencies": {
"@next/font": "13.0.7",
- "@prisma/client": "^4.8.0",
+ "@prisma/client": "^4.9.0",
"@types/express": "^4.17.15",
"@types/marked": "^4.0.8",
"@types/react": "18.0.26",
@@ -42,7 +42,7 @@
"@fec/remark-a11y-emoji": "^3.1.0",
"@types/node": "^18.11.17",
"@types/prismjs": "^1.26.0",
- "prisma": "^4.8.0"
+ "prisma": "^4.9.0"
}
},
"node_modules/@ampproject/remapping": {
diff --git a/package.json b/package.json
index 607519e..d729e6c 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,7 @@
},
"dependencies": {
"@next/font": "13.0.7",
- "@prisma/client": "^4.8.0",
+ "@prisma/client": "^4.9.0",
"@types/express": "^4.17.15",
"@types/marked": "^4.0.8",
"@types/react": "18.0.26",
@@ -46,6 +46,6 @@
"@fec/remark-a11y-emoji": "^3.1.0",
"@types/node": "^18.11.17",
"@types/prismjs": "^1.26.0",
- "prisma": "^4.8.0"
+ "prisma": "^4.9.0"
}
}
diff --git a/pages/api/articles/[articleId].ts b/pages/api/articles/[articleId].ts
index fb6833b..6c37332 100644
--- a/pages/api/articles/[articleId].ts
+++ b/pages/api/articles/[articleId].ts
@@ -35,6 +35,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
res.status(500).json(error);
});
} else if (req.method == "PUT") {//* PUT
+ console.log("PUT")
const data: UpdateArticle = req.body;
if (!isValidText(data.title)) {
@@ -53,22 +54,23 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
const newArticle: Prisma.ArticleUncheckedUpdateInput = {
- title: data.title,
- name: formatTextToUrlName(data.title),
- introduction: data.introduction,
+ title: data.title ?? undefined,
+ name: formatTextToUrlName(data.title) ?? undefined,
+ introduction: data.introduction ?? undefined,
- categoryId: data.categoryId.toString(),
- contentTable: data.contentTable,
- markdown: data.markdown,
- imageId: data.imageId.toString(),
+ categoryId: data.categoryId?.toString() ?? undefined,
+ contentTable: data.contentTable ?? undefined,
+ markdown: data.markdown ?? undefined,
+ imageId: data.imageId?.toString() ?? undefined,
}
-
+ console.log(newArticle)
await prisma.article.update({ data: newArticle, where: { id: articleId }, include: { category: true } })
.then(
(data) => {
res.json({ success: true, data: data });
},
(errorReason) => {
+ console.log(errorReason)
if (errorReason.code === "P2002") {
res.json({ target: errorReason.meta.target[0], error: "Already exists" });
}
diff --git a/pages/api/articles/index.ts b/pages/api/articles/index.ts
index 0088085..6bd756a 100644
--- a/pages/api/articles/index.ts
+++ b/pages/api/articles/index.ts
@@ -72,6 +72,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
data.name = formatTextToUrlName(data.title);
+ data.categoryId = data.categoryId.toString();
+
prisma.article
.create({ data: data, include: { category: true } })
.then(
diff --git a/pages/api/articles/name/[articleName].ts b/pages/api/articles/name/[articleName].ts
index e1836c5..012260e 100644
--- a/pages/api/articles/name/[articleName].ts
+++ b/pages/api/articles/name/[articleName].ts
@@ -22,7 +22,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
code: "404",
message: "No article with this name found!",
};
- res.status(404).send(JSON.stringify(error));
+ res.status(404).json(error);
}
})
.catch((err) => {
@@ -31,6 +31,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
code: "500",
message: err,
};
- res.status(500).send(JSON.stringify(error));
+ res.status(500).json(error);
});
}
diff --git a/styles/buttons.scss b/styles/buttons.scss
index 4ed7714..2a5b756 100644
--- a/styles/buttons.scss
+++ b/styles/buttons.scss
@@ -17,8 +17,8 @@ button {
border-color: var(--color-accent);
}
- &.error {
- border-color: var(--color-error);
+ &.danger {
+ border-color: var(--color-danger);
}
&.success {
border-color: var(--color-success);
diff --git a/styles/modules/AdminControl.module.scss b/styles/modules/AdminControl.module.scss
new file mode 100644
index 0000000..9815ec5
--- /dev/null
+++ b/styles/modules/AdminControl.module.scss
@@ -0,0 +1,12 @@
+@import "../variables.scss";
+
+.adminControl {
+ border-bottom: 2px solid var(--color-danger);
+ padding: 10px;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ column-gap: 50px;
+ margin-top: -10px;
+ margin-bottom: 10px;
+}
diff --git a/styles/modules/AdminNav.module.scss b/styles/modules/AdminNav.module.scss
new file mode 100644
index 0000000..2be9ddf
--- /dev/null
+++ b/styles/modules/AdminNav.module.scss
@@ -0,0 +1,12 @@
+@import "../variables.scss";
+
+.adminNav {
+ border-top: 2px solid var(--color-danger);
+ padding: 10px;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ column-gap: 50px;
+ margin-top: -10px;
+ margin-bottom: 10px;
+}
diff --git a/styles/variables_colors.scss b/styles/variables_colors.scss
index 9cf9007..8bebef5 100644
--- a/styles/variables_colors.scss
+++ b/styles/variables_colors.scss
@@ -11,7 +11,7 @@
--color-font-muted: #929292;
--color-shadow-nav: #00000033;
- --color-error: #cf000f;
+ --color-danger: #cf000f;
--color-success: #009944;
--color-info: #63c0df;
--color-warning: #f0541e;