diff --git a/components/table/article-table.tsx b/components/table/article-table.tsx index 107ab0d..a482dde 100644 --- a/components/table/article-table.tsx +++ b/components/table/article-table.tsx @@ -43,23 +43,28 @@ import withReactContent from "sweetalert2-react-content"; const columns = [ { name: "No", uid: "no" }, { name: "Judul", uid: "title" }, - { name: "Kategori", uid: "categoryName" }, + { name: "Kategori", uid: "category" }, { name: "Tanggal Unggah", uid: "createdAt" }, { name: "Kreator", uid: "createdByName" }, - { name: "Aksi", uid: "actions" }, ]; +interface Category { + id: number; + title: string; +} + type ArticleData = Article & { no: number; createdAt: string; + categories: Category[]; }; export default function ArticleTable() { const MySwal = withReactContent(Swal); const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); - const [article, setArticle] = useState([]); + const [article, setArticle] = useState([]); const [showData, setShowData] = useState("10"); const [search, setSearch] = useState(""); const [categories, setCategoies] = useState([]); @@ -96,7 +101,6 @@ export default function ArticleTable() { }; const res = await getListArticle(req); getTableNumber(parseInt(showData), res.data?.data); - console.log("res.data?.data", res.data); setTotalPage(res?.data?.meta?.totalPage); } @@ -109,7 +113,6 @@ export default function ArticleTable() { value.no = startIndex + iterate; return value; }); - console.log("daata", data); setArticle(newData); } }; @@ -142,74 +145,84 @@ export default function ArticleTable() { }); }; - const renderCell = useCallback((article: ArticleData, columnKey: Key) => { - const cellValue = article[columnKey as keyof ArticleData]; - const statusColorMap: Record = { - active: "primary", - cancel: "danger", - pending: "success", - }; + const renderCell = useCallback( + (article: any, columnKey: Key) => { + const cellValue = article[columnKey as keyof any]; + const statusColorMap: Record = { + active: "primary", + cancel: "danger", + pending: "success", + }; - switch (columnKey) { - case "status": - return ( - -
- {cellValue} + switch (columnKey) { + case "status": + return ( + +
+ {article.status} +
+
+ ); + case "createdAt": + return

{convertDateFormat(article.createdAt)}

; + case "category": + return ( +

+ {article?.categories?.map((list: any) => list.title).join(", ") + + " "} +

+ ); + + case "actions": + return ( +
+ + + + + + + + + Detail + + + + + + Edit + + + handleDelete(article.id)} + > + + Delete + + +
- - ); - case "createdAt": - return

{convertDateFormat(article.createdAt)}

; + ); - case "actions": - return ( -
- - - - - - - - - Detail - - - - - - Edit - - - handleDelete(article.id)} - > - - Delete - - - -
- ); - - default: - return cellValue; - } - }, []); + default: + return cellValue; + } + }, + [article] + ); let typingTimer: NodeJS.Timeout; const doneTypingInterval = 1500; @@ -333,7 +346,7 @@ export default function ArticleTable() { emptyContent={"No data to display."} loadingContent={} > - {(item) => ( + {(item: any) => ( {(columnKey) => ( {renderCell(item, columnKey)}