fix:startdate, end date, categoryIds, createdByIds
This commit is contained in:
parent
b38b72f708
commit
686fa7bc95
|
|
@ -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 {
|
||||||
|
|
@ -54,6 +55,9 @@ 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 { 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" },
|
||||||
|
|
@ -90,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);
|
||||||
|
|
@ -97,13 +102,18 @@ 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 [selectedCategories, setSelectedCategories] = useState<string>("");
|
const [users, setUsers] = 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({
|
const [articleDate, setArticleDate] = useState<{
|
||||||
|
startDate: any;
|
||||||
|
endDate: any;
|
||||||
|
}>({
|
||||||
startDate: parseDate(
|
startDate: parseDate(
|
||||||
convertDateFormatNoTimeV2(
|
convertDateFormatNoTimeV2(
|
||||||
new Date(new Date().setDate(new Date().getDate() - 7))
|
new Date(new Date().setDate(new Date().getDate() - 7))
|
||||||
|
|
@ -114,16 +124,46 @@ export default function ArticleTable() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initState();
|
initState();
|
||||||
}, [page, showData, startDateValue, selectedCategories, articleDate]);
|
}, [
|
||||||
|
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) => {
|
const onSelectionChange = (id: Key | null) => {
|
||||||
|
|
@ -131,21 +171,41 @@ export default function ArticleTable() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDate = (data: any) => {
|
const getDate = (data: any) => {
|
||||||
|
if (data === null) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
return `${data.year}-${data.month < 10 ? `0${data.month}` : data.month}-${
|
return `${data.year}-${data.month < 10 ? `0${data.month}` : data.month}-${
|
||||||
data.day < 10 ? `0${data.day}` : data.day
|
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", selectedCategories);
|
console.log("test", getIds(selectedCategories));
|
||||||
const req = {
|
const req = {
|
||||||
limit: showData,
|
limit: showData,
|
||||||
page: page,
|
page: page,
|
||||||
search: search,
|
search: search,
|
||||||
startDate: getDate(articleDate.startDate),
|
startDate: getDate(articleDate.startDate),
|
||||||
endDate: getDate(articleDate.endDate),
|
endDate: getDate(articleDate.endDate),
|
||||||
category: selectedCategories,
|
categoryIds: getIds(selectedCategories),
|
||||||
|
createdByIds: getIds(selectedUsers),
|
||||||
sort: "desc",
|
sort: "desc",
|
||||||
sortBy: "created_at",
|
sortBy: "created_at",
|
||||||
};
|
};
|
||||||
|
|
@ -414,45 +474,72 @@ 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>
|
||||||
|
<ReactSelect
|
||||||
<Autocomplete
|
className="basic-single text-black z-50"
|
||||||
className="w-full"
|
classNames={{
|
||||||
defaultItems={categories}
|
control: (state: any) =>
|
||||||
label=""
|
"!rounded-lg bg-white !border-1 !border-gray-200 dark:!border-stone-500",
|
||||||
labelPlacement="outside"
|
}}
|
||||||
variant="bordered"
|
classNamePrefix="select"
|
||||||
inputProps={{ classNames: { inputWrapper: "border-1" } }}
|
onChange={setSelectedCategories}
|
||||||
onSelectionChange={onSelectionChange}
|
closeMenuOnSelect={false}
|
||||||
>
|
components={animatedComponents}
|
||||||
{(item: any) => (
|
isClearable={true}
|
||||||
<AutocompleteItem key={item.id}>
|
isSearchable={true}
|
||||||
{item.title}
|
isMulti={true}
|
||||||
</AutocompleteItem>
|
placeholder="Kategori..."
|
||||||
)}
|
name="sub-module"
|
||||||
</Autocomplete>
|
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",
|
||||||
|
// }),
|
||||||
|
// }}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{username?.includes("mabes") && (
|
{username?.includes("mabes") && (
|
||||||
<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">Author</p>
|
<p className="font-semibold text-sm">Author</p>
|
||||||
|
|
||||||
<Autocomplete
|
<ReactSelect
|
||||||
className="w-full"
|
className="basic-single text-black z-50"
|
||||||
inputProps={{ classNames: { inputWrapper: "border-1" } }}
|
classNames={{
|
||||||
defaultItems={categories}
|
control: (state: any) =>
|
||||||
label=""
|
"!rounded-lg bg-white !border-1 !border-gray-200 dark:!border-stone-500",
|
||||||
labelPlacement="outside"
|
}}
|
||||||
variant="bordered"
|
classNamePrefix="select"
|
||||||
onSelectionChange={onSelectionChange}
|
onChange={setSelectedUsers}
|
||||||
>
|
closeMenuOnSelect={false}
|
||||||
{(item: any) => (
|
components={animatedComponents}
|
||||||
<AutocompleteItem key={item.id}>
|
isClearable={true}
|
||||||
{item.title}
|
isSearchable={true}
|
||||||
</AutocompleteItem>
|
isMulti={true}
|
||||||
)}
|
placeholder="Kategori..."
|
||||||
</Autocomplete>
|
name="sub-module"
|
||||||
|
options={users}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex flex-col gap-1 w-full lg:w-[120px]">
|
<div className="flex flex-col gap-1 w-full lg:w-[140px]">
|
||||||
<p className="font-semibold text-sm">Start Date</p>
|
<p className="font-semibold text-sm">Start Date</p>
|
||||||
|
|
||||||
<Popover
|
<Popover
|
||||||
|
|
@ -460,9 +547,25 @@ export default function ArticleTable() {
|
||||||
classNames={{ content: ["!bg-transparent", "p-0"] }}
|
classNames={{ content: ["!bg-transparent", "p-0"] }}
|
||||||
>
|
>
|
||||||
<PopoverTrigger>
|
<PopoverTrigger>
|
||||||
<a className="cursor-pointer border-1 px-2 py-2 rounded-xl">
|
<div className="flex flex-row gap-1 items-center cursor-pointer border-1 px-2 py-2 rounded-xl">
|
||||||
{convertDateFormatNoTime(articleDate.startDate)}
|
<a className=" w-[120px]">
|
||||||
|
{articleDate.startDate
|
||||||
|
? convertDateFormatNoTime(articleDate.startDate)
|
||||||
|
: "-"}
|
||||||
</a>
|
</a>
|
||||||
|
{articleDate.startDate && (
|
||||||
|
<a
|
||||||
|
onClick={() =>
|
||||||
|
setArticleDate({
|
||||||
|
startDate: null,
|
||||||
|
endDate: articleDate.endDate,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<TimesIcon size={16} />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="bg-transparent">
|
<PopoverContent className="bg-transparent">
|
||||||
<Calendar
|
<Calendar
|
||||||
|
|
@ -486,9 +589,25 @@ export default function ArticleTable() {
|
||||||
classNames={{ content: ["!bg-transparent", "p-0"] }}
|
classNames={{ content: ["!bg-transparent", "p-0"] }}
|
||||||
>
|
>
|
||||||
<PopoverTrigger>
|
<PopoverTrigger>
|
||||||
<a className="cursor-pointer border-1 px-2 py-2 rounded-xl">
|
<div className="flex flex-row gap-1 items-center cursor-pointer border-1 px-2 py-2 rounded-xl">
|
||||||
{convertDateFormatNoTime(articleDate.endDate)}
|
<a className=" w-[120px]">
|
||||||
|
{articleDate.endDate
|
||||||
|
? convertDateFormatNoTime(articleDate.endDate)
|
||||||
|
: "-"}
|
||||||
</a>
|
</a>
|
||||||
|
{articleDate.endDate && (
|
||||||
|
<a
|
||||||
|
onClick={() =>
|
||||||
|
setArticleDate({
|
||||||
|
endDate: null,
|
||||||
|
startDate: articleDate.startDate,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<TimesIcon size={16} />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="bg-transparent">
|
<PopoverContent className="bg-transparent">
|
||||||
<Calendar
|
<Calendar
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,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,7 +35,9 @@ export async function getListArticle(props: PaginationRequest) {
|
||||||
endDate || ""
|
endDate || ""
|
||||||
}&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
|
}&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
|
||||||
sort || "asc"
|
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