diff --git a/components/table/article-table.tsx b/components/table/article-table.tsx
index d58f72c..5f87d3c 100644
--- a/components/table/article-table.tsx
+++ b/components/table/article-table.tsx
@@ -8,7 +8,7 @@ import {
EyeIconMdi,
SearchIcon,
} from "@/components/icons";
-import { error, success, successToast } from "@/config/swal";
+import { close, error, loading, success, successToast } from "@/config/swal";
import {
deleteArticle,
getArticleByCategory,
@@ -53,6 +53,15 @@ const columns = [
{ name: "Status", uid: "isPublish" },
{ name: "Aksi", uid: "actions" },
];
+const columnsOtherRole = [
+ { name: "No", uid: "no" },
+ { name: "Judul", uid: "title" },
+ { name: "Kategori", uid: "category" },
+ { name: "Tanggal Unggah", uid: "createdAt" },
+ { name: "Kreator", uid: "createdByName" },
+ { name: "Status", uid: "isPublish" },
+ { name: "Aksi", uid: "actions" },
+];
interface Category {
id: number;
@@ -68,13 +77,14 @@ type ArticleData = Article & {
export default function ArticleTable() {
const MySwal = withReactContent(Swal);
const username = Cookies.get("username");
+ const userId = Cookies.get("uie");
const [page, setPage] = useState(1);
const [totalPage, setTotalPage] = useState(1);
const [article, setArticle] = useState
([]);
const [showData, setShowData] = useState("10");
const [search, setSearch] = useState("");
- const [categories, setCategoies] = useState([]);
+ const [categories, setCategories] = useState([]);
const [selectedCategories, setSelectedCategories] = useState([]);
const [startDateValue, setStartDateValue] = useState({
startDate: null,
@@ -92,27 +102,29 @@ export default function ArticleTable() {
async function getCategories() {
const res = await getArticleByCategory();
const data = res?.data?.data;
- setCategoies(data);
+ setCategories(data);
}
async function initState() {
+ loading();
const req = {
limit: showData,
page: page,
search: search,
- startDate:
- startDateValue.startDate === null ? "" : startDateValue.startDate,
- endDate: startDateValue.endDate === null ? "" : startDateValue.endDate,
- category: Array.from(selectedCategories).join(","),
+ // startDate:
+ // startDateValue.startDate === null ? "" : startDateValue.startDate,
+ // endDate: startDateValue.endDate === null ? "" : startDateValue.endDate,
+ categorySlug: Array.from(selectedCategories).join(","),
sort: "desc",
sortBy: "created_at",
};
const res = await getListArticle(req);
- getTableNumber(parseInt(showData), res.data?.data);
+ await getTableNumber(parseInt(showData), res.data?.data);
setTotalPage(res?.data?.meta?.totalPage);
+ close();
}
- const getTableNumber = (limit: number, data: Article[]) => {
+ const getTableNumber = async (limit: number, data: Article[]) => {
if (data) {
const startIndex = limit * (page - 1);
let iterate = 0;
@@ -227,11 +239,22 @@ export default function ArticleTable() {
Detail
-
-
-
- Edit
-
+
+ {(username === "admin-mabes" ||
+ Number(userId) === article.createdById) && (
+
+
+ Edit
+
+ )}
handleDelete(article.id)}
+ className={
+ username === "admin-mabes" ||
+ Number(userId) === article.createdById
+ ? ""
+ : "hidden"
+ }
>
-
- Delete
+ {(username === "admin-mabes" ||
+ Number(userId) === article.createdById) && (
+ <>
+ {" "}
+
+ Delete
+ >
+ )}
@@ -269,7 +304,7 @@ export default function ArticleTable() {
return cellValue;
}
},
- [article]
+ [article, page]
);
let typingTimer: NodeJS.Timeout;
@@ -285,6 +320,7 @@ export default function ArticleTable() {
};
async function doneTyping() {
+ setPage(1);
initState();
}
@@ -346,7 +382,7 @@ export default function ArticleTable() {
variant="bordered"
labelPlacement="outside"
placeholder="Kategori"
- selectionMode="multiple"
+ selectionMode="single"
selectedKeys={selectedCategories}
className="w-full"
items={categories}
@@ -358,13 +394,13 @@ export default function ArticleTable() {
key={item.props?.value}
className="text-black dark:text-white text-xs"
>
- {item.textValue},
+ {item.textValue}
));
}}
>
{categories?.map((category: any) => (
-
+
{category?.title}
))}
@@ -390,7 +426,9 @@ export default function ArticleTable() {
"min-h-[50px] bg-transpararent text-black dark:text-white ",
}}
>
-
+
{(column) => (
{column.name}
)}
diff --git a/components/table/suggestions/suggestions-table.tsx b/components/table/suggestions/suggestions-table.tsx
index ceca897..10dcb55 100644
--- a/components/table/suggestions/suggestions-table.tsx
+++ b/components/table/suggestions/suggestions-table.tsx
@@ -66,6 +66,7 @@ import {
getFeedbacks,
getFeedbacksById,
} from "@/service/feedbacks";
+import * as XLSX from "xlsx";
const columns = [
{ name: "No", uid: "no" },
@@ -301,6 +302,51 @@ export default function SuggestionsTable() {
);
const [typeDate, setTypeDate] = useState("monthly");
+ const doExport = async () => {
+ const res = await getFeedbacks({ limit: showData, search: search });
+ if (res?.data?.data) {
+ exportRecap(res?.data?.data);
+ }
+ };
+
+ const exportRecap = (data: any) => {
+ let temp: any = [];
+ let no = 0;
+
+ const worksheet = XLSX.utils.json_to_sheet([]);
+
+ data.map((list: any) => {
+ no += 1;
+ const now = [
+ no,
+ list.commentFromName,
+ list.commentFromEmail,
+ list.message,
+ ];
+ temp.push(now);
+ });
+
+ XLSX.utils.sheet_add_aoa(
+ worksheet,
+ [["No", "Nama", "Email", "Kritik & Saran"]],
+ {
+ origin: "A1",
+ }
+ );
+ XLSX.utils.sheet_add_json(worksheet, temp, {
+ origin: "A2",
+ skipHeader: true,
+ });
+
+ worksheet["!cols"] = [{ wch: 7 }, { wch: 24 }, { wch: 24 }, { wch: 48 }];
+
+ const workbook = XLSX.utils.book_new();
+
+ XLSX.utils.book_append_sheet(workbook, worksheet, "ethic");
+
+ XLSX.writeFile(workbook, `Kritik Saran.xlsx`);
+ };
+
return (
<>
@@ -399,7 +445,7 @@ export default function SuggestionsTable() {
-
diff --git a/components/table/tabel-emajalah-polri.tsx b/components/table/tabel-emajalah-polri.tsx
index afc75e4..04d8354 100644
--- a/components/table/tabel-emajalah-polri.tsx
+++ b/components/table/tabel-emajalah-polri.tsx
@@ -102,167 +102,122 @@ export default function ListEnewsPolri() {
}
return (
-
-
-
-
-
- Beranda
-
-
-
E-Majalah Polri
-
-
- {/*
- E-majalah Polri
-
*/}
-
-
setSearch(e.target.value)}
- startContent={
-
- }
- endContent={
-
- Cari
-
- }
- />
- {/*
*/}
-
-
- Tanggal Publikasi
-
-
setStartDateValue(e)}
- inputClassName="z-50 w-full text-sm bg-white border-1 border-gray-200 px-2 py-[6px] rounded-xl h-[40px] text-black"
- />
-
-
-
-
-
+
+
+
+ Beranda
+
+
+
E-Majalah Polri
+
+
+
+
setSearch(e.target.value)}
+ startContent={
+
+ }
+ endContent={
+
-
- {(column) => (
-
- {column.label}
-
- )}
-
-
- {(item: any) => (
-
-
-
- {item.title}
-
-
-
-
-
-
-
-
- )}
-
-
-
-
+ Cari
+
+ }
+ />
+
+
+
+ Tanggal Publikasi
+
+ {/*
setStartDateValue(e)}
+ inputClassName="z-50 w-full text-sm bg-white border-1 border-gray-200 px-2 py-[6px] rounded-xl h-[40px] text-black"
+ /> */}
+
+
+
+
+
+ {(column) => (
+
+ {column.label}
+
+ )}
+
+
+ {(item: any) => (
+
+
+
+ {item.title}
+
+
+
+
+
+
+
+
+ )}
+
+
+
-
-
-
);
}
diff --git a/components/ui/social-media/polri-tv.tsx b/components/ui/social-media/polri-tv.tsx
index 7cf73ef..a0ee879 100644
--- a/components/ui/social-media/polri-tv.tsx
+++ b/components/ui/social-media/polri-tv.tsx
@@ -16,14 +16,10 @@ const PolriTvWidget = () => {
}, []);
return (
-
-
-
+
);
};
diff --git a/config/site.ts b/config/site.ts
index 55f6e7a..d3822a2 100644
--- a/config/site.ts
+++ b/config/site.ts
@@ -143,6 +143,10 @@ export const siteConfig = {
label: "UU & Peraturan",
href: "https://sisdivkum.id/library/peraturan-kepolisian",
},
+ {
+ label: "E-Magazine",
+ href: "/e-majalah-polri/daftar-majalah",
+ },
],
},
// {
diff --git a/service/activity-log.ts b/service/activity-log.ts
index 287d862..903a240 100644
--- a/service/activity-log.ts
+++ b/service/activity-log.ts
@@ -1,10 +1,5 @@
import { PaginationRequest } from "@/types/globals";
-import {
- httpDeleteInterceptor,
- httpGet,
- httpPost,
- httpPut,
-} from "./http-config/axios-base-service";
+import { httpGet, httpPost, httpPut } from "./http-config/axios-base-service";
export async function saveActivity(data: any, token?: string) {
const headers = token
diff --git a/service/advertisement.ts b/service/advertisement.ts
index 21f9cb3..0669a81 100644
--- a/service/advertisement.ts
+++ b/service/advertisement.ts
@@ -1,9 +1,4 @@
-import {
- httpDeleteInterceptor,
- httpGet,
- httpPost,
- httpPut,
-} from "./http-config/axios-base-service";
+import { httpGet, httpPost, httpPut } from "./http-config/axios-base-service";
import Cookies from "js-cookie";
const token = Cookies.get("access_token");
diff --git a/service/article.ts b/service/article.ts
index deb0910..e966da4 100644
--- a/service/article.ts
+++ b/service/article.ts
@@ -19,6 +19,7 @@ export async function getListArticle(props: PaginationRequest) {
category,
sortBy,
sort,
+ categorySlug,
} = props;
const headers = {
"content-type": "application/json",
@@ -30,7 +31,7 @@ export async function getListArticle(props: PaginationRequest) {
endDate || ""
}&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
sort || "asc"
- }`,
+ }&category=${categorySlug || ""}`,
headers
);
}
@@ -85,7 +86,10 @@ export async function getArticleById(id: any) {
}
export async function deleteArticle(id: string) {
- return await httpDeleteInterceptor(`articles/${id}`);
+ const headers = {
+ "content-type": "application/json",
+ };
+ return await httpDeleteInterceptor(`articles/${id}`, headers);
}
export async function getArticleByCategory() {
@@ -121,7 +125,10 @@ export async function uploadArticleThumbnail(id: string, data: any) {
}
export async function deleteArticleFiles(id: number) {
- return await httpDeleteInterceptor(`article-files/${id}`);
+ const headers = {
+ "content-type": "multipart/form-data",
+ };
+ return await httpDeleteInterceptor(`article-files/${id}`, headers);
}
export async function getUserLevelDataStat(startDate: string, endDate: string) {
diff --git a/service/comment.ts b/service/comment.ts
index 5fddfd5..7ac40ff 100644
--- a/service/comment.ts
+++ b/service/comment.ts
@@ -19,7 +19,10 @@ export async function getComments(data: any) {
}
export async function deleteComment(id: number) {
- return await httpDeleteInterceptor(`/article-comments/${id}`);
+ const headers = {
+ "content-type": "application/json",
+ };
+ return await httpDeleteInterceptor(`/article-comments/${id}`, headers);
}
export async function getCommentById(id: number) {
diff --git a/service/feedbacks.ts b/service/feedbacks.ts
index 4b81eb2..d4e541e 100644
--- a/service/feedbacks.ts
+++ b/service/feedbacks.ts
@@ -34,5 +34,8 @@ export async function getFeedbacksById(id: number) {
return await httpGet(pathUrl, headers);
}
export async function deleteFeedback(id: number) {
- return await httpDeleteInterceptor(`/feedbacks/${id}`);
+ const headers = {
+ "content-type": "application/json",
+ };
+ return await httpDeleteInterceptor(`/feedbacks/${id}`, headers);
}
diff --git a/service/http-config/axios-base-service.ts b/service/http-config/axios-base-service.ts
index 5b938c9..e798141 100644
--- a/service/http-config/axios-base-service.ts
+++ b/service/http-config/axios-base-service.ts
@@ -2,114 +2,113 @@ import axiosBaseInstance from "./http-base-service";
import mediahubBaseInstance from "./mediahub-base-service";
export async function httpPost(pathUrl: any, headers: any, data?: any) {
- const response = await axiosBaseInstance
- .post(pathUrl, data, { headers })
- .catch(function (error: any) {
- console.log(error);
- return error.response;
- });
- console.log("Response base svc : ", response);
- if (response?.status == 200 || response?.status == 201) {
- return {
- error: false,
- message: "success",
- data: response?.data,
- };
- } else {
- return {
- error: true,
- message: response?.data?.message || response?.data || null,
- data: null,
- };
- }
+ const response = await axiosBaseInstance
+ .post(pathUrl, data, { headers })
+ .catch(function (error: any) {
+ console.log(error);
+ return error.response;
+ });
+ console.log("Response base svc : ", response);
+ if (response?.status == 200 || response?.status == 201) {
+ return {
+ error: false,
+ message: "success",
+ data: response?.data,
+ };
+ } else {
+ return {
+ error: true,
+ message: response?.data?.message || response?.data || null,
+ data: null,
+ };
+ }
}
export async function httpGet(pathUrl: any, headers: any) {
- const response = await axiosBaseInstance
- .get(pathUrl, { headers })
- .catch(function (error: any) {
- console.log(error);
- return error.response;
- });
- console.log("Response base svc : ", response);
- if (response?.status == 200 || response?.status == 201) {
- return {
- error: false,
- message: "success",
- data: response?.data,
- };
- } else {
- return {
- error: true,
- message: response?.data?.message || response?.data || null,
- data: null,
- };
- }
+ const response = await axiosBaseInstance
+ .get(pathUrl, { headers })
+ .catch(function (error: any) {
+ console.log(error);
+ return error.response;
+ });
+ console.log("Response base svc : ", response);
+ if (response?.status == 200 || response?.status == 201) {
+ return {
+ error: false,
+ message: "success",
+ data: response?.data,
+ };
+ } else {
+ return {
+ error: true,
+ message: response?.data?.message || response?.data || null,
+ data: null,
+ };
+ }
}
export async function httpPut(pathUrl: any, headers: any, data?: any) {
- const response = await axiosBaseInstance
- .put(pathUrl, data, { headers })
- .catch(function (error: any) {
- console.log(error);
- return error.response;
- });
- console.log("Response base svc : ", response);
- if (response?.status == 200 || response?.status == 201) {
- return {
- error: false,
- message: "success",
- data: response?.data,
- };
- } else {
- return {
- error: true,
- message: response?.data?.message || response?.data || null,
- data: null,
- };
- }
+ const response = await axiosBaseInstance
+ .put(pathUrl, data, { headers })
+ .catch(function (error: any) {
+ console.log(error);
+ return error.response;
+ });
+ console.log("Response base svc : ", response);
+ if (response?.status == 200 || response?.status == 201) {
+ return {
+ error: false,
+ message: "success",
+ data: response?.data,
+ };
+ } else {
+ return {
+ error: true,
+ message: response?.data?.message || response?.data || null,
+ data: null,
+ };
+ }
}
-export async function httpDeleteInterceptor(pathUrl: any) {
- const response = await axiosBaseInstance
- .delete(pathUrl)
- .catch((error) => error.response);
- console.log("Response interceptor : ", response);
- if (response?.status == 200 || response?.status == 201) {
- return {
- error: false,
- message: "success",
- data: response?.data,
- };
- } else {
- return {
- error: true,
- message: response?.data?.message || response?.data || null,
- data: null,
- };
- }
+export async function httpDeleteInterceptor(pathUrl: any, headers: any) {
+ const response = await axiosBaseInstance
+ .delete(pathUrl, headers)
+ .catch((error) => error.response);
+ console.log("Response interceptor : ", response);
+ if (response?.status == 200 || response?.status == 201) {
+ return {
+ error: false,
+ message: "success",
+ data: response?.data,
+ };
+ } else {
+ return {
+ error: true,
+ message: response?.data?.message || response?.data || null,
+ data: null,
+ };
+ }
}
-
export async function mediahubGet(pathUrl: any, headers: any) {
- const response = await mediahubBaseInstance
- .get(pathUrl, { headers })
- .catch(function (error: any) {
- console.log(error);
- return error.response;
- });
- console.log("Response base svc : ", response);
- if (response?.status == 200 || response?.status == 201) {
- return {
- error: false,
- message: "success",
- data: response?.data,
- };
- } else {
- return {
- error: true,
- message: response?.data?.message || response?.data || null,
- data: null,
- };
- }
+ const response = await mediahubBaseInstance
+ .get(pathUrl, { headers })
+ .catch(function (error: any) {
+ console.log(error);
+ return error.response;
+ });
+ console.log("Response base svc : ", response);
+ if (response?.status == 200 || response?.status == 201) {
+ return {
+ error: false,
+ message: "success",
+ data: response?.data,
+ };
+ } else {
+ return {
+ error: true,
+ message: response?.data?.message || response?.data || null,
+ data: null,
+ };
+ }
}
diff --git a/service/magazine.tsx b/service/magazine.tsx
index 9fd2666..9c76d36 100644
--- a/service/magazine.tsx
+++ b/service/magazine.tsx
@@ -47,7 +47,10 @@ export async function getMagazineById(id: string) {
}
export async function deleteMagazine(id: string) {
- return await httpDeleteInterceptor(`magazines/${id}`);
+ const headers = {
+ "content-type": "application/json",
+ };
+ return await httpDeleteInterceptor(`magazines/${id}`, headers);
}
export async function uploadMagazineFile(id: string, data: any) {
@@ -65,5 +68,8 @@ export async function uploadMagazineThumbnail(id: string, data: any) {
}
export async function deleteMagazineFiles(id: number) {
- return await httpDeleteInterceptor(`magazine-files/${id}`);
+ const headers = {
+ "content-type": "multipart/form-data",
+ };
+ return await httpDeleteInterceptor(`magazine-files/${id}`, headers);
}
diff --git a/service/master-categories.tsx b/service/master-categories.tsx
index b73acbe..9efd3ec 100644
--- a/service/master-categories.tsx
+++ b/service/master-categories.tsx
@@ -33,7 +33,10 @@ export async function getCategoryById(id: number) {
}
export async function deleteCategory(id: number) {
- return await httpDeleteInterceptor(`article-categories/${id}`);
+ const headers = {
+ "content-type": "application/json",
+ };
+ return await httpDeleteInterceptor(`article-categories/${id}`, headers);
}
export async function uploadCategoryThumbnail(id: string, data: any) {
diff --git a/service/master-user-role.ts b/service/master-user-role.ts
index d075533..eda2837 100644
--- a/service/master-user-role.ts
+++ b/service/master-user-role.ts
@@ -35,5 +35,8 @@ export async function getMasterUserRoleById(id: any) {
}
export async function deleteMasterUserRole(id: string) {
- return await httpDeleteInterceptor(`/user-roles/${id}`);
+ const headers = {
+ "content-type": "application/json",
+ };
+ return await httpDeleteInterceptor(`/user-roles/${id}`, headers);
}
diff --git a/service/master-user.ts b/service/master-user.ts
index 63ce107..925f7e0 100644
--- a/service/master-user.ts
+++ b/service/master-user.ts
@@ -39,7 +39,10 @@ export async function editMasterUsers(data: any, id: string) {
}
export async function deleteMasterUser(id: string) {
- return await httpDeleteInterceptor(`/users/${id}`);
+ const headers = {
+ "content-type": "application/json",
+ };
+ return await httpDeleteInterceptor(`/users/${id}`, headers);
}
export async function postSignIn(data: any) {
@@ -132,5 +135,8 @@ export async function getArticleComment(id: string) {
}
export async function deleteArticleComment(id: number) {
- return await httpDeleteInterceptor(`/article-comments/${id}`);
+ const headers = {
+ "content-type": "application/json",
+ };
+ return await httpDeleteInterceptor(`/article-comments/${id}`, headers);
}
diff --git a/types/globals.tsx b/types/globals.tsx
index 092d25f..9b5dff5 100644
--- a/types/globals.tsx
+++ b/types/globals.tsx
@@ -65,4 +65,5 @@ export type PaginationRequest = {
category?: string;
sortBy?: string;
sort?: string;
+ categorySlug?: string;
};