diff --git a/components/table/advertise/advertise-table.tsx b/components/table/advertise/advertise-table.tsx
index c9b2a35..0c08e91 100644
--- a/components/table/advertise/advertise-table.tsx
+++ b/components/table/advertise/advertise-table.tsx
@@ -32,6 +32,8 @@ import {
ModalFooter,
ModalHeader,
Pagination,
+ Radio,
+ RadioGroup,
Select,
SelectItem,
Spinner,
@@ -55,12 +57,18 @@ import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content";
import { useDropzone } from "react-dropzone";
import Image from "next/image";
+import {
+ createAdvertiseById,
+ editAdvertise,
+ getAdvertise,
+} from "@/service/advertisement";
const columns = [
{ name: "No", uid: "no" },
{ name: "Judul", uid: "title" },
- { name: "Deskripsi", uid: "descriptions" },
- { name: "Link", uid: "url" },
+ { name: "Deskripsi", uid: "description" },
+ { name: "Penempatan", uid: "placement" },
+ { name: "Link", uid: "redirectLink" },
{ name: "Aksi", uid: "actions" },
];
@@ -74,8 +82,8 @@ const createArticleSchema = z.object({
title: z.string().min(2, {
message: "Judul harus diisi",
}),
- url: z.string().min(2, {
- message: "Link harus diisi",
+ url: z.string().min(1, {
+ message: "Url harus diisi",
}),
description: z.string().min(2, {
message: "Deskripsi harus diisi",
@@ -92,14 +100,9 @@ export default function AdvertiseTable(props: { triggerRefresh: boolean }) {
const [article, setArticle] = useState
([]);
const [showData, setShowData] = useState("10");
const [search, setSearch] = useState("");
- const [categories, setCategoies] = useState([]);
- const [selectedCategories, setSelectedCategories] = useState([]);
- const [startDateValue, setStartDateValue] = useState({
- startDate: null,
- endDate: null,
- });
- const [isHeader, setIsHeader] = useState(false);
+ const [placement, setPlacement] = useState("banner");
+ const [refresh, setRefresh] = useState(false);
const [files, setFiles] = useState([]);
@@ -127,23 +130,7 @@ export default function AdvertiseTable(props: { triggerRefresh: boolean }) {
useEffect(() => {
initState();
- }, [
- page,
- showData,
- startDateValue,
- selectedCategories,
- props.triggerRefresh,
- ]);
-
- useEffect(() => {
- getCategories();
- }, []);
-
- async function getCategories() {
- const res = await getArticleByCategory();
- const data = res?.data?.data;
- setCategoies(data);
- }
+ }, [page, showData, props.triggerRefresh, refresh]);
const handleRemoveFile = (file: File) => {
const uploadedFiles = files;
@@ -156,14 +143,11 @@ export default function AdvertiseTable(props: { triggerRefresh: boolean }) {
limit: showData,
page: page,
search: search,
- startDate:
- startDateValue.startDate === null ? "" : startDateValue.startDate,
- endDate: startDateValue.endDate === null ? "" : startDateValue.endDate,
- category: Array.from(selectedCategories).join(","),
+
sort: "desc",
sortBy: "created_at",
};
- const res = await getListArticle(req);
+ const res = await getAdvertise(req);
getTableNumber(parseInt(showData), res.data?.data);
setTotalPage(res?.data?.meta?.totalPage);
}
@@ -183,12 +167,12 @@ export default function AdvertiseTable(props: { triggerRefresh: boolean }) {
async function doDelete(id: any) {
// loading();
- const resDelete = await deleteArticle(id);
+ // const resDelete = await deleteArticle(id);
- if (resDelete?.error) {
- error(resDelete.message);
- return false;
- }
+ // if (resDelete?.error) {
+ // error(resDelete.message);
+ // return false;
+ // }
close();
success("Berhasil Hapus");
initState();
@@ -212,32 +196,38 @@ export default function AdvertiseTable(props: { triggerRefresh: boolean }) {
const onSubmit = async (values: z.infer) => {
loading();
const formData = {
+ id: Number(values.id),
title: values.title,
description: values.description,
- isHeader: isHeader,
- url: values.url,
+ placement: placement,
+ redirectLink: values.url,
};
- console.log("dataas", formData);
+ const res = await editAdvertise(formData);
+ if (res?.error) {
+ error(res?.message);
+ return false;
+ }
close();
- // setRefresh(!refresh);
- // MySwal.fire({
- // title: "Sukses",
- // icon: "success",
- // confirmButtonColor: "#3085d6",
- // confirmButtonText: "OK",
- // }).then((result) => {
- // if (result.isConfirmed) {
- // }
- // });
+ MySwal.fire({
+ title: "Sukses",
+ icon: "success",
+ confirmButtonColor: "#3085d6",
+ confirmButtonText: "OK",
+ }).then((result) => {
+ if (result.isConfirmed) {
+ setRefresh(!refresh);
+ }
+ });
};
const openModal = async (id: number) => {
- // const res = await getCategoryById(Number(id));
- // const data = res?.data?.data;
- // setValue("id", String(data?.id));
- // setValue("title", data?.title);
- // setValue("description", data?.description);
- // setValue("url", data?.url);
+ const res = await createAdvertiseById(Number(id));
+ const data = res?.data?.data;
+ setValue("id", String(data?.id));
+ setValue("title", data?.title);
+ setValue("description", data?.description);
+ setValue("url", data?.redirectLink);
+ setPlacement(data?.placement);
// setValue("file", data?.thumbnailUrl);
onOpen();
@@ -248,17 +238,20 @@ export default function AdvertiseTable(props: { triggerRefresh: boolean }) {
const cellValue = advertise[columnKey as keyof any];
switch (columnKey) {
- case "url":
- return (
+ case "redirectLink":
+ return cellValue.includes("https") ? (
- https://www.google.com/
+ {cellValue}
+ ) : (
+ {cellValue}
);
-
+ case "placement":
+ return {cellValue}
;
case "actions":
return (
@@ -303,7 +296,7 @@ export default function AdvertiseTable(props: { triggerRefresh: boolean }) {
return cellValue;
}
},
- [article]
+ [article, props.triggerRefresh, refresh]
);
let typingTimer: NodeJS.Timeout;
@@ -520,14 +513,17 @@ export default function AdvertiseTable(props: { triggerRefresh: boolean }) {
)}
- Header
- Penempatan
+
- {isHeader ? "Ya" : "Tidak"}
-
+ Banner
+ Jumbotron
+
Simpan
diff --git a/components/table/article-table.tsx b/components/table/article-table.tsx
index f00e704..d58f72c 100644
--- a/components/table/article-table.tsx
+++ b/components/table/article-table.tsx
@@ -1,13 +1,14 @@
"use client";
import {
BannerIcon,
+ CopyIcon,
CreateIconIon,
DeleteIcon,
DotsYIcon,
EyeIconMdi,
SearchIcon,
} from "@/components/icons";
-import { error, success } from "@/config/swal";
+import { error, success, successToast } from "@/config/swal";
import {
deleteArticle,
getArticleByCategory,
@@ -158,6 +159,20 @@ export default function ArticleTable() {
console.log("vbanner", id, status);
};
+ const copyUrlArticle = async (id: number, slug: string) => {
+ const url =
+ `${window.location.protocol}//${window.location.host}` +
+ "/news/detail/" +
+ `${id}-${slug}`;
+ try {
+ await navigator.clipboard.writeText(url);
+ successToast("Success", "Article Copy to Clipboard");
+ setTimeout(() => {}, 1500);
+ } catch (err) {
+ ("Failed to copy!");
+ }
+ };
+
const renderCell = useCallback(
(article: any, columnKey: Key) => {
const cellValue = article[columnKey as keyof any];
@@ -199,6 +214,13 @@ export default function ArticleTable() {
+ copyUrlArticle(article.id, article.slug)}
+ >
+
+ Copy Url Article
+
diff --git a/public/props-1.png b/public/props-1.png
deleted file mode 100644
index 8b868ef..0000000
Binary files a/public/props-1.png and /dev/null differ
diff --git a/public/props-2.png b/public/props-2.png
deleted file mode 100644
index 50c7b3c..0000000
Binary files a/public/props-2.png and /dev/null differ
diff --git a/public/props-3.png b/public/props-3.png
deleted file mode 100644
index 09a76e7..0000000
Binary files a/public/props-3.png and /dev/null differ
diff --git a/public/sample-banner-2.png b/public/sample-banner-2.png
new file mode 100644
index 0000000..3ecfb06
Binary files /dev/null and b/public/sample-banner-2.png differ
diff --git a/public/sample-banner-3.jpg b/public/sample-banner-3.jpg
new file mode 100644
index 0000000..e3587d5
Binary files /dev/null and b/public/sample-banner-3.jpg differ
diff --git a/public/sample-banner.png b/public/sample-banner.png
new file mode 100644
index 0000000..8d2bfc3
Binary files /dev/null and b/public/sample-banner.png differ
diff --git a/service/advertisement.ts b/service/advertisement.ts
new file mode 100644
index 0000000..21f9cb3
--- /dev/null
+++ b/service/advertisement.ts
@@ -0,0 +1,44 @@
+import {
+ httpDeleteInterceptor,
+ httpGet,
+ httpPost,
+ httpPut,
+} from "./http-config/axios-base-service";
+import Cookies from "js-cookie";
+
+const token = Cookies.get("access_token");
+
+export async function createAdvertise(data: any) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization: `Bearer ${token}`,
+ };
+ const pathUrl = `/advertisement`;
+ return await httpPost(pathUrl, headers, data);
+}
+
+export async function getAdvertise(data: any) {
+ const headers = {
+ "content-type": "application/json",
+ };
+ const pathUrl = `/advertisement?page=${data?.page || 1}&limit=${
+ data?.limit || ""
+ }&placement=${data?.placement || ""}`;
+ return await httpGet(pathUrl, headers);
+}
+
+export async function createAdvertiseById(id: number) {
+ const headers = {
+ "content-type": "application/json",
+ };
+ const pathUrl = `/advertisement/${id}`;
+ return await httpGet(pathUrl, headers);
+}
+
+export async function editAdvertise(data: any) {
+ const headers = {
+ "content-type": "application/json",
+ };
+ const pathUrl = `/advertisement/${data?.id}`;
+ return await httpPut(pathUrl, headers, data);
+}