merge restructure
This commit is contained in:
commit
79724453f1
|
|
@ -159,6 +159,10 @@ export default function DetailNews(props: { data: any; listArticle: any }) {
|
||||||
<div className="flex justify-center my-2 lg:my-5">
|
<div className="flex justify-center my-2 lg:my-5">
|
||||||
{data?.files?.length > 0 && (
|
{data?.files?.length > 0 && (
|
||||||
<Image
|
<Image
|
||||||
|
classNames={{
|
||||||
|
wrapper: "!w-full !max-w-full",
|
||||||
|
img: "!w-full",
|
||||||
|
}}
|
||||||
alt="Main Image"
|
alt="Main Image"
|
||||||
src={data?.files[imageNow]?.file_url}
|
src={data?.files[imageNow]?.file_url}
|
||||||
className="object-cover w-[100%] rounded-md"
|
className="object-cover w-[100%] rounded-md"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {
|
||||||
DotsYIcon,
|
DotsYIcon,
|
||||||
EyeIconMdi,
|
EyeIconMdi,
|
||||||
SearchIcon,
|
SearchIcon,
|
||||||
|
TimesIcon,
|
||||||
} from "@/components/icons";
|
} from "@/components/icons";
|
||||||
import { close, error, loading, success, successToast } from "@/config/swal";
|
import { close, error, loading, success, successToast } from "@/config/swal";
|
||||||
import {
|
import {
|
||||||
|
|
@ -16,9 +17,16 @@ import {
|
||||||
updateIsBannerArticle,
|
updateIsBannerArticle,
|
||||||
} from "@/services/article";
|
} from "@/services/article";
|
||||||
import { Article } from "@/types/globals";
|
import { Article } from "@/types/globals";
|
||||||
import { convertDateFormat } from "@/utils/global";
|
import {
|
||||||
|
convertDateFormat,
|
||||||
|
convertDateFormatNoTime,
|
||||||
|
convertDateFormatNoTimeV2,
|
||||||
|
} from "@/utils/global";
|
||||||
import { Button } from "@heroui/button";
|
import { Button } from "@heroui/button";
|
||||||
import {
|
import {
|
||||||
|
Autocomplete,
|
||||||
|
AutocompleteItem,
|
||||||
|
Calendar,
|
||||||
Chip,
|
Chip,
|
||||||
ChipProps,
|
ChipProps,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
|
|
@ -27,6 +35,9 @@ import {
|
||||||
DropdownTrigger,
|
DropdownTrigger,
|
||||||
Input,
|
Input,
|
||||||
Pagination,
|
Pagination,
|
||||||
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverTrigger,
|
||||||
Select,
|
Select,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
Spinner,
|
Spinner,
|
||||||
|
|
@ -43,6 +54,10 @@ import Datepicker from "react-tailwindcss-datepicker";
|
||||||
import Swal from "sweetalert2";
|
import Swal from "sweetalert2";
|
||||||
import withReactContent from "sweetalert2-react-content";
|
import withReactContent from "sweetalert2-react-content";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
import { parseDate } from "@internationalized/date";
|
||||||
|
import { listMasterUsers } from "@/services/master-user";
|
||||||
|
import ReactSelect from "react-select";
|
||||||
|
import makeAnimated from "react-select/animated";
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{ name: "No", uid: "no" },
|
{ name: "No", uid: "no" },
|
||||||
|
|
@ -79,6 +94,7 @@ export default function ArticleTable() {
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
const username = Cookies.get("username");
|
const username = Cookies.get("username");
|
||||||
const userId = Cookies.get("uie");
|
const userId = Cookies.get("uie");
|
||||||
|
const animatedComponents = makeAnimated();
|
||||||
|
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const [totalPage, setTotalPage] = useState(1);
|
const [totalPage, setTotalPage] = useState(1);
|
||||||
|
|
@ -86,36 +102,110 @@ export default function ArticleTable() {
|
||||||
const [showData, setShowData] = useState("10");
|
const [showData, setShowData] = useState("10");
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [categories, setCategories] = useState<any>([]);
|
const [categories, setCategories] = useState<any>([]);
|
||||||
|
const [users, setUsers] = useState<any>([]);
|
||||||
const [selectedCategories, setSelectedCategories] = useState<any>([]);
|
const [selectedCategories, setSelectedCategories] = useState<any>([]);
|
||||||
|
const [selectedUsers, setSelectedUsers] = useState<any>([]);
|
||||||
const [startDateValue, setStartDateValue] = useState({
|
const [startDateValue, setStartDateValue] = useState({
|
||||||
startDate: null,
|
startDate: null,
|
||||||
endDate: 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(() => {
|
useEffect(() => {
|
||||||
initState();
|
initState();
|
||||||
}, [page, showData, startDateValue, selectedCategories]);
|
}, [
|
||||||
|
page,
|
||||||
|
showData,
|
||||||
|
startDateValue,
|
||||||
|
selectedCategories,
|
||||||
|
articleDate,
|
||||||
|
selectedUsers,
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getCategories();
|
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() {
|
async function getCategories() {
|
||||||
const res = await getArticleByCategory();
|
const res = await getArticleByCategory();
|
||||||
const data = res?.data?.data;
|
setupList(res?.data?.data, "category");
|
||||||
setCategories(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
async function initState() {
|
||||||
loading();
|
loading();
|
||||||
|
console.log("test", getIds(selectedCategories));
|
||||||
const req = {
|
const req = {
|
||||||
limit: showData,
|
limit: showData,
|
||||||
page: page,
|
page: page,
|
||||||
search: search,
|
search: search,
|
||||||
// startDate:
|
startDate: getDate(articleDate.startDate),
|
||||||
// startDateValue.startDate === null ? "" : startDateValue.startDate,
|
endDate: getDate(articleDate.endDate),
|
||||||
// endDate: startDateValue.endDate === null ? "" : startDateValue.endDate,
|
categoryIds: getIds(selectedCategories),
|
||||||
categorySlug: Array.from(selectedCategories).join(","),
|
createdByIds: getIds(selectedUsers),
|
||||||
sort: "desc",
|
sort: "desc",
|
||||||
sortBy: "created_at",
|
sortBy: "created_at",
|
||||||
};
|
};
|
||||||
|
|
@ -248,13 +338,13 @@ export default function ArticleTable() {
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
key="edit"
|
key="edit"
|
||||||
className={
|
className={
|
||||||
username === "admin-mabes" ||
|
username?.includes("mabes") ||
|
||||||
Number(userId) === article.createdById
|
Number(userId) === article.createdById
|
||||||
? ""
|
? ""
|
||||||
: "hidden"
|
: "hidden"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{(username === "admin-mabes" ||
|
{(username?.includes("mabes") ||
|
||||||
Number(userId) === article.createdById) && (
|
Number(userId) === article.createdById) && (
|
||||||
<Link href={`/admin/article/edit/${article.id}`}>
|
<Link href={`/admin/article/edit/${article.id}`}>
|
||||||
<CreateIconIon className="inline mr-2 mb-1" />
|
<CreateIconIon className="inline mr-2 mb-1" />
|
||||||
|
|
@ -267,9 +357,9 @@ export default function ArticleTable() {
|
||||||
onPress={() =>
|
onPress={() =>
|
||||||
handleBanner(article?.id, !article?.isBanner)
|
handleBanner(article?.id, !article?.isBanner)
|
||||||
}
|
}
|
||||||
className={username === "admin-mabes" ? "" : "hidden"}
|
className={username?.includes("mabes") ? "" : "hidden"}
|
||||||
>
|
>
|
||||||
{username === "admin-mabes" && (
|
{username?.includes("mabes") && (
|
||||||
<>
|
<>
|
||||||
<BannerIcon size={24} className="inline mr-2 mb-1" />
|
<BannerIcon size={24} className="inline mr-2 mb-1" />
|
||||||
{article?.isBanner
|
{article?.isBanner
|
||||||
|
|
@ -282,13 +372,13 @@ export default function ArticleTable() {
|
||||||
key="delete"
|
key="delete"
|
||||||
onPress={() => handleDelete(article.id)}
|
onPress={() => handleDelete(article.id)}
|
||||||
className={
|
className={
|
||||||
username === "admin-mabes" ||
|
username?.includes("mabes") ||
|
||||||
Number(userId) === article.createdById
|
Number(userId) === article.createdById
|
||||||
? ""
|
? ""
|
||||||
: "hidden"
|
: "hidden"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{(username === "admin-mabes" ||
|
{(username?.includes("mabes") ||
|
||||||
Number(userId) === article.createdById) && (
|
Number(userId) === article.createdById) && (
|
||||||
<>
|
<>
|
||||||
{" "}
|
{" "}
|
||||||
|
|
@ -330,6 +420,15 @@ export default function ArticleTable() {
|
||||||
initState();
|
initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [hasMounted, setHasMounted] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setHasMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Render
|
||||||
|
if (!hasMounted) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="py-3">
|
<div className="py-3">
|
||||||
|
|
@ -375,44 +474,155 @@ export default function ArticleTable() {
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-1 w-full lg:w-[230px]">
|
<div className="flex flex-col gap-1 w-full lg:w-[230px]">
|
||||||
<p className="font-semibold text-sm">Kategori</p>
|
<p className="font-semibold text-sm">Kategori</p>
|
||||||
<Select
|
<ReactSelect
|
||||||
label=""
|
className="basic-single text-black z-50"
|
||||||
variant="bordered"
|
classNames={{
|
||||||
labelPlacement="outside"
|
control: (state: any) =>
|
||||||
placeholder="Kategori"
|
"!rounded-lg bg-white !border-1 !border-gray-200 dark:!border-stone-500",
|
||||||
selectionMode="single"
|
|
||||||
selectedKeys={selectedCategories}
|
|
||||||
className="w-full"
|
|
||||||
items={categories}
|
|
||||||
classNames={{ trigger: "border-1" }}
|
|
||||||
onSelectionChange={setSelectedCategories}
|
|
||||||
renderValue={(items) => {
|
|
||||||
return items.map((item) => (
|
|
||||||
<span
|
|
||||||
key={item.props?.value}
|
|
||||||
className="text-black dark:text-white text-xs"
|
|
||||||
>
|
|
||||||
{item.textValue}
|
|
||||||
</span>
|
|
||||||
));
|
|
||||||
}}
|
}}
|
||||||
>
|
classNamePrefix="select"
|
||||||
{categories?.map((category: any) => (
|
onChange={setSelectedCategories}
|
||||||
<SelectItem key={category?.slug}>
|
closeMenuOnSelect={false}
|
||||||
{category?.title}
|
components={animatedComponents}
|
||||||
</SelectItem>
|
isClearable={true}
|
||||||
))}
|
isSearchable={true}
|
||||||
</Select>
|
isMulti={true}
|
||||||
</div>
|
placeholder="Kategori..."
|
||||||
{/* <div className="flex flex-col gap-1 w-full lg:w-[240px]">
|
name="sub-module"
|
||||||
<p className="font-semibold text-sm">Tanggal</p>
|
options={categories}
|
||||||
<Datepicker
|
// styles={{
|
||||||
value={startDateValue}
|
// control: (base) => ({
|
||||||
displayFormat="DD/MM/YYYY"
|
// ...base,
|
||||||
onChange={(e: any) => setStartDateValue(e)}
|
// width: "100%",
|
||||||
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"
|
// 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",
|
||||||
|
// }),
|
||||||
|
// }}
|
||||||
/>
|
/>
|
||||||
</div> */}
|
</div>
|
||||||
|
{username?.includes("mabes") && (
|
||||||
|
<div className="flex flex-col gap-1 w-full lg:w-[230px]">
|
||||||
|
<p className="font-semibold text-sm">Author</p>
|
||||||
|
|
||||||
|
<ReactSelect
|
||||||
|
className="basic-single text-black z-50"
|
||||||
|
classNames={{
|
||||||
|
control: (state: any) =>
|
||||||
|
"!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}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="flex flex-col gap-1 w-full lg:w-[140px]">
|
||||||
|
<p className="font-semibold text-sm">Start Date</p>
|
||||||
|
|
||||||
|
<Popover
|
||||||
|
placement="bottom"
|
||||||
|
classNames={{ content: ["!bg-transparent", "p-0"] }}
|
||||||
|
>
|
||||||
|
<PopoverTrigger>
|
||||||
|
<div className="flex flex-row gap-1 items-center cursor-pointer border-1 px-2 py-2 rounded-xl">
|
||||||
|
<a className=" w-[120px]">
|
||||||
|
{articleDate.startDate
|
||||||
|
? convertDateFormatNoTime(articleDate.startDate)
|
||||||
|
: "-"}
|
||||||
|
</a>
|
||||||
|
{articleDate.startDate && (
|
||||||
|
<a
|
||||||
|
onClick={() =>
|
||||||
|
setArticleDate({
|
||||||
|
startDate: null,
|
||||||
|
endDate: articleDate.endDate,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<TimesIcon size={16} />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="bg-transparent">
|
||||||
|
<Calendar
|
||||||
|
value={articleDate.startDate}
|
||||||
|
onChange={(e) =>
|
||||||
|
setArticleDate({
|
||||||
|
startDate: e,
|
||||||
|
endDate: articleDate.endDate,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
maxValue={articleDate.endDate}
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-1 w-full lg:w-[120px]">
|
||||||
|
<p className="font-semibold text-sm">End Date</p>
|
||||||
|
|
||||||
|
<Popover
|
||||||
|
placement="bottom"
|
||||||
|
classNames={{ content: ["!bg-transparent", "p-0"] }}
|
||||||
|
>
|
||||||
|
<PopoverTrigger>
|
||||||
|
<div className="flex flex-row gap-1 items-center cursor-pointer border-1 px-2 py-2 rounded-xl">
|
||||||
|
<a className=" w-[120px]">
|
||||||
|
{articleDate.endDate
|
||||||
|
? convertDateFormatNoTime(articleDate.endDate)
|
||||||
|
: "-"}
|
||||||
|
</a>
|
||||||
|
{articleDate.endDate && (
|
||||||
|
<a
|
||||||
|
onClick={() =>
|
||||||
|
setArticleDate({
|
||||||
|
endDate: null,
|
||||||
|
startDate: articleDate.startDate,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<TimesIcon size={16} />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="bg-transparent">
|
||||||
|
<Calendar
|
||||||
|
value={articleDate.endDate}
|
||||||
|
onChange={(e) =>
|
||||||
|
setArticleDate({
|
||||||
|
startDate: articleDate.startDate,
|
||||||
|
endDate: e,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
minValue={articleDate.startDate}
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Table
|
<Table
|
||||||
aria-label="micro issue table"
|
aria-label="micro issue table"
|
||||||
|
|
@ -425,7 +635,7 @@ export default function ArticleTable() {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TableHeader
|
<TableHeader
|
||||||
columns={username === "admin-mabes" ? columns : columnsOtherRole}
|
columns={username?.includes("mabes") ? columns : columnsOtherRole}
|
||||||
>
|
>
|
||||||
{(column) => (
|
{(column) => (
|
||||||
<TableColumn key={column.uid}>{column.name}</TableColumn>
|
<TableColumn key={column.uid}>{column.name}</TableColumn>
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ export async function getListArticle(props: PaginationRequest) {
|
||||||
sort,
|
sort,
|
||||||
categorySlug,
|
categorySlug,
|
||||||
isBanner,
|
isBanner,
|
||||||
|
categoryIds,
|
||||||
|
createdByIds,
|
||||||
} = props;
|
} = props;
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
|
@ -33,8 +35,10 @@ export async function getListArticle(props: PaginationRequest) {
|
||||||
}&title=${search}&startDate=${startDate || ""}&endDate=${
|
}&title=${search}&startDate=${startDate || ""}&endDate=${
|
||||||
endDate || ""
|
endDate || ""
|
||||||
}&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
|
}&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
|
||||||
sort || "desc"
|
sort || "asc"
|
||||||
}&category=${categorySlug || ""}&isBanner=${isBanner || ""}`,
|
}&category=${categorySlug || ""}&isBanner=${isBanner || ""}&categoryIds=${
|
||||||
|
categoryIds || ""
|
||||||
|
}&createdByIds=${createdByIds || ""}`,
|
||||||
headers
|
headers
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,4 +67,6 @@ export type PaginationRequest = {
|
||||||
sort?: string;
|
sort?: string;
|
||||||
categorySlug?: string;
|
categorySlug?: string;
|
||||||
isBanner?: boolean;
|
isBanner?: boolean;
|
||||||
|
categoryIds?: string;
|
||||||
|
createdByIds?: string;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue