diff --git a/components/page/detail-news.tsx b/components/page/detail-news.tsx
index fef2e25..8be8c04 100644
--- a/components/page/detail-news.tsx
+++ b/components/page/detail-news.tsx
@@ -159,6 +159,10 @@ export default function DetailNews(props: { data: any; listArticle: any }) {
{data?.files?.length > 0 && (
([]);
+ const [users, setUsers] = useState([]);
const [selectedCategories, setSelectedCategories] = useState([]);
+ const [selectedUsers, setSelectedUsers] = useState([]);
const [startDateValue, setStartDateValue] = useState({
startDate: null,
endDate: null,
});
+ const [articleDate, setArticleDate] = useState<{
+ startDate: any;
+ endDate: any;
+ }>({
+ startDate: parseDate(
+ convertDateFormatNoTimeV2(
+ new Date(new Date().setDate(new Date().getDate() - 7))
+ )
+ ),
+ endDate: parseDate(convertDateFormatNoTimeV2(new Date())),
+ });
+
useEffect(() => {
initState();
- }, [page, showData, startDateValue, selectedCategories]);
+ }, [
+ page,
+ showData,
+ startDateValue,
+ selectedCategories,
+ articleDate,
+ selectedUsers,
+ ]);
useEffect(() => {
getCategories();
+ getUsers();
}, []);
+ const setupList = (data: any, type: string) => {
+ const temp = [];
+ for (const element of data) {
+ temp.push({
+ id: element.id,
+ label: element.title || element.fullname,
+ value: element.id,
+ });
+ }
+ if (type === "users") {
+ setUsers(temp);
+ }
+
+ if (type === "category") {
+ setCategories(temp);
+ }
+ };
+
+ async function getUsers() {
+ const res = await listMasterUsers({ page: page, limit: -1 });
+ setupList(res?.data?.data, "users");
+ }
+
async function getCategories() {
const res = await getArticleByCategory();
- const data = res?.data?.data;
- setCategories(data);
+ setupList(res?.data?.data, "category");
}
+ const onSelectionChange = (id: Key | null) => {
+ setSelectedCategories(String(id));
+ };
+
+ const getDate = (data: any) => {
+ if (data === null) {
+ return "";
+ } else {
+ return `${data.year}-${data.month < 10 ? `0${data.month}` : data.month}-${
+ data.day < 10 ? `0${data.day}` : data.day
+ }`;
+ }
+ };
+
+ const getIds = (data: { id: number; label: string; value: number }[]) => {
+ let temp = "";
+ if (data) {
+ for (let i = 0; i < data.length; i++) {
+ if (i == 0) {
+ temp = String(data[i].id);
+ } else {
+ temp = temp + `,${data[i].id}`;
+ }
+ }
+ }
+
+ return temp;
+ };
+
async function initState() {
loading();
+ console.log("test", getIds(selectedCategories));
const req = {
limit: showData,
page: page,
search: search,
- // startDate:
- // startDateValue.startDate === null ? "" : startDateValue.startDate,
- // endDate: startDateValue.endDate === null ? "" : startDateValue.endDate,
- categorySlug: Array.from(selectedCategories).join(","),
+ startDate: getDate(articleDate.startDate),
+ endDate: getDate(articleDate.endDate),
+ categoryIds: getIds(selectedCategories),
+ createdByIds: getIds(selectedUsers),
sort: "desc",
sortBy: "created_at",
};
@@ -248,13 +338,13 @@ export default function ArticleTable() {
- {(username === "admin-mabes" ||
+ {(username?.includes("mabes") ||
Number(userId) === article.createdById) && (
@@ -267,9 +357,9 @@ export default function ArticleTable() {
onPress={() =>
handleBanner(article?.id, !article?.isBanner)
}
- className={username === "admin-mabes" ? "" : "hidden"}
+ className={username?.includes("mabes") ? "" : "hidden"}
>
- {username === "admin-mabes" && (
+ {username?.includes("mabes") && (
<>
{article?.isBanner
@@ -282,13 +372,13 @@ export default function ArticleTable() {
key="delete"
onPress={() => handleDelete(article.id)}
className={
- username === "admin-mabes" ||
+ username?.includes("mabes") ||
Number(userId) === article.createdById
? ""
: "hidden"
}
>
- {(username === "admin-mabes" ||
+ {(username?.includes("mabes") ||
Number(userId) === article.createdById) && (
<>
{" "}
@@ -330,6 +420,15 @@ export default function ArticleTable() {
initState();
}
+ const [hasMounted, setHasMounted] = useState(false);
+
+ useEffect(() => {
+ setHasMounted(true);
+ }, []);
+
+ // Render
+ if (!hasMounted) return null;
+
return (
<>
@@ -375,44 +474,155 @@ export default function ArticleTable() {
Kategori
-
-
- {/*
-
Tanggal
-
setStartDateValue(e)}
- inputClassName="z-50 w-full text-sm bg-transparent border-1 border-gray-200 px-2 py-[6px] rounded-xl h-[40px] text-gray-600 dark:text-gray-300"
+ classNamePrefix="select"
+ onChange={setSelectedCategories}
+ closeMenuOnSelect={false}
+ components={animatedComponents}
+ isClearable={true}
+ isSearchable={true}
+ isMulti={true}
+ placeholder="Kategori..."
+ name="sub-module"
+ options={categories}
+ // styles={{
+ // control: (base) => ({
+ // ...base,
+ // width: "100%",
+ // overflowX: "auto",
+ // }),
+ // valueContainer: (base) => ({
+ // ...base,
+ // display: "flex",
+ // flexWrap: "nowrap",
+ // overflowX: "auto",
+ // whiteSpace: "nowrap",
+ // gap: "4px",
+ // }),
+ // multiValue: (base) => ({
+ // ...base,
+ // whiteSpace: "nowrap",
+ // flexShrink: 0,
+ // }),
+ // multiValueLabel: (base) => ({
+ // ...base,
+ // whiteSpace: "nowrap",
+ // }),
+ // }}
/>
- */}
+
+ {username?.includes("mabes") && (
+
+
Author
+
+
+ "!rounded-lg bg-white !border-1 !border-gray-200 dark:!border-stone-500",
+ }}
+ classNamePrefix="select"
+ onChange={setSelectedUsers}
+ closeMenuOnSelect={false}
+ components={animatedComponents}
+ isClearable={true}
+ isSearchable={true}
+ isMulti={true}
+ placeholder="Kategori..."
+ name="sub-module"
+ options={users}
+ />
+
+ )}
+
+
Start Date
+
+
+
+
+
+
+
+ setArticleDate({
+ startDate: e,
+ endDate: articleDate.endDate,
+ })
+ }
+ maxValue={articleDate.endDate}
+ />
+
+
+
+
+
End Date
+
+
+
+
+
+
+
+ setArticleDate({
+ startDate: articleDate.startDate,
+ endDate: e,
+ })
+ }
+ minValue={articleDate.startDate}
+ />
+
+
+
{(column) => (
{column.name}
diff --git a/services/article.ts b/services/article.ts
index 16d48dd..51ac766 100644
--- a/services/article.ts
+++ b/services/article.ts
@@ -23,6 +23,8 @@ export async function getListArticle(props: PaginationRequest) {
sort,
categorySlug,
isBanner,
+ categoryIds,
+ createdByIds,
} = props;
const headers = {
"content-type": "application/json",
@@ -33,8 +35,10 @@ export async function getListArticle(props: PaginationRequest) {
}&title=${search}&startDate=${startDate || ""}&endDate=${
endDate || ""
}&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
- sort || "desc"
- }&category=${categorySlug || ""}&isBanner=${isBanner || ""}`,
+ sort || "asc"
+ }&category=${categorySlug || ""}&isBanner=${isBanner || ""}&categoryIds=${
+ categoryIds || ""
+ }&createdByIds=${createdByIds || ""}`,
headers
);
}
diff --git a/types/globals.tsx b/types/globals.tsx
index ec13d3e..c7e8eb4 100644
--- a/types/globals.tsx
+++ b/types/globals.tsx
@@ -67,4 +67,6 @@ export type PaginationRequest = {
sort?: string;
categorySlug?: string;
isBanner?: boolean;
+ categoryIds?: string;
+ createdByIds?: string;
};