update
This commit is contained in:
parent
89eccf57c1
commit
0d44e0e4c0
|
|
@ -7,6 +7,7 @@ import { close, loading } from "@/config/swal";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
import { CommentIcon } from "../icons/sidebar-icon";
|
import { CommentIcon } from "../icons/sidebar-icon";
|
||||||
import { Link2, MailIcon } from "lucide-react";
|
import { Link2, MailIcon } from "lucide-react";
|
||||||
|
import { getAdvertise } from "@/service/advertisement";
|
||||||
|
|
||||||
type TabKey = "trending" | "comments" | "latest";
|
type TabKey = "trending" | "comments" | "latest";
|
||||||
|
|
||||||
|
|
@ -33,6 +34,15 @@ interface CategoryType {
|
||||||
value: number;
|
value: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Advertise = {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
placement: string;
|
||||||
|
contentFileUrl: string;
|
||||||
|
redirectLink: string;
|
||||||
|
};
|
||||||
|
|
||||||
export default function DetailContent() {
|
export default function DetailContent() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const id = params?.id;
|
const id = params?.id;
|
||||||
|
|
@ -68,6 +78,36 @@ export default function DetailContent() {
|
||||||
{ id: "latest", label: "Latest" },
|
{ id: "latest", label: "Latest" },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const [bannerAd, setBannerAd] = useState<Advertise | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
initStateAdver();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function initStateAdver() {
|
||||||
|
const req = {
|
||||||
|
limit: 100,
|
||||||
|
page: 1,
|
||||||
|
sort: "desc",
|
||||||
|
sortBy: "created_at",
|
||||||
|
isPublish: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await getAdvertise(req);
|
||||||
|
const data: Advertise[] = res?.data?.data || [1];
|
||||||
|
|
||||||
|
// filter iklan dengan placement = "banner"
|
||||||
|
const banner = data.find((ad) => ad.placement === "banner");
|
||||||
|
|
||||||
|
if (banner) {
|
||||||
|
setBannerAd(banner);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error fetching advertisement:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initState();
|
initState();
|
||||||
}, [page, showData, startDateValue, selectedCategories]);
|
}, [page, showData, startDateValue, selectedCategories]);
|
||||||
|
|
@ -184,7 +224,8 @@ export default function DetailContent() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span className="text-[#31942E] font-medium">
|
<span className="text-[#31942E] font-medium">
|
||||||
{articleDetail?.createdByName}
|
{articleDetail?.customCreatorName ||
|
||||||
|
articleDetail?.createdByName}
|
||||||
</span>
|
</span>
|
||||||
<span>-</span>
|
<span>-</span>
|
||||||
<span>
|
<span>
|
||||||
|
|
@ -382,7 +423,8 @@ export default function DetailContent() {
|
||||||
{/* Info Author */}
|
{/* Info Author */}
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<h3 className="text-lg font-semibold text-gray-800">
|
<h3 className="text-lg font-semibold text-gray-800">
|
||||||
{articleDetail?.createdByName}
|
{articleDetail?.customCreatorName ||
|
||||||
|
articleDetail?.createdByName}
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<div className="mt-2 flex items-center gap-4 flex-wrap">
|
<div className="mt-2 flex items-center gap-4 flex-wrap">
|
||||||
|
|
@ -424,12 +466,32 @@ export default function DetailContent() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="relative mb-2 h-[120px] overflow-hidden flex items-center border my-8">
|
<div className="relative mb-2 h-[120px] overflow-hidden flex items-center border my-8">
|
||||||
<Image
|
{bannerAd ? (
|
||||||
src={"/image-kolom.png"}
|
<a
|
||||||
alt="Berita Utama"
|
href={bannerAd.redirectLink}
|
||||||
fill
|
target="_blank"
|
||||||
className="object-contain"
|
rel="noopener noreferrer"
|
||||||
/>
|
className="block w-full"
|
||||||
|
>
|
||||||
|
<div className="relative w-full h-[350px] flex justify-center">
|
||||||
|
<Image
|
||||||
|
src={bannerAd.contentFileUrl}
|
||||||
|
alt={bannerAd.title || "Iklan Banner"}
|
||||||
|
width={1200} // ukuran dasar untuk responsive
|
||||||
|
height={350}
|
||||||
|
className="object-cover w-full h-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<Image
|
||||||
|
src="/image-kolom.png"
|
||||||
|
alt="Berita Utama"
|
||||||
|
width={1200}
|
||||||
|
height={188}
|
||||||
|
className="object-contain w-full h-[188px]"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-10">
|
<div className="mt-10">
|
||||||
<h2 className="text-2xl font-bold mb-2">Tinggalkan Balasan</h2>
|
<h2 className="text-2xl font-bold mb-2">Tinggalkan Balasan</h2>
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import { CloudUploadIcon, TimesIcon } from "@/components/icons";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import ReactSelect from "react-select";
|
import ReactSelect from "react-select";
|
||||||
import makeAnimated from "react-select/animated";
|
import makeAnimated from "react-select/animated";
|
||||||
import { htmlToString } from "@/utils/global";
|
import { convertDateFormatNoTime, htmlToString } from "@/utils/global";
|
||||||
import { close, error, loading, successToast } from "@/config/swal";
|
import { close, error, loading, successToast } from "@/config/swal";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
@ -44,6 +44,13 @@ import GenerateSingleArticleForm from "./generate-ai-single-form";
|
||||||
import GenerateContentRewriteForm from "./generate-ai-content-rewrite-form";
|
import GenerateContentRewriteForm from "./generate-ai-content-rewrite-form";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import {
|
||||||
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverTrigger,
|
||||||
|
} from "@/components/ui/popover";
|
||||||
|
import { Calendar } from "@/components/ui/calendar";
|
||||||
|
import DatePicker from "react-datepicker";
|
||||||
|
|
||||||
const CustomEditor = dynamic(
|
const CustomEditor = dynamic(
|
||||||
() => {
|
() => {
|
||||||
|
|
@ -82,6 +89,9 @@ const createArticleSchema = z.object({
|
||||||
title: z.string().min(2, {
|
title: z.string().min(2, {
|
||||||
message: "Judul harus diisi",
|
message: "Judul harus diisi",
|
||||||
}),
|
}),
|
||||||
|
customCreatorName: z.string().min(2, {
|
||||||
|
message: "Judul harus diisi",
|
||||||
|
}),
|
||||||
slug: z.string().min(2, {
|
slug: z.string().min(2, {
|
||||||
message: "Slug harus diisi",
|
message: "Slug harus diisi",
|
||||||
}),
|
}),
|
||||||
|
|
@ -94,6 +104,7 @@ const createArticleSchema = z.object({
|
||||||
tags: z.array(z.string()).nonempty({
|
tags: z.array(z.string()).nonempty({
|
||||||
message: "Minimal 1 tag",
|
message: "Minimal 1 tag",
|
||||||
}),
|
}),
|
||||||
|
source: z.enum(["internal", "external"]).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function CreateArticleForm() {
|
export default function CreateArticleForm() {
|
||||||
|
|
@ -117,8 +128,8 @@ export default function CreateArticleForm() {
|
||||||
"publish"
|
"publish"
|
||||||
);
|
);
|
||||||
const [isScheduled, setIsScheduled] = useState(false);
|
const [isScheduled, setIsScheduled] = useState(false);
|
||||||
|
const [startDateValue, setStartDateValue] = useState<Date | undefined>();
|
||||||
const [startDateValue, setStartDateValue] = useState<any>(null);
|
const [startTimeValue, setStartTimeValue] = useState<string>("");
|
||||||
|
|
||||||
const { getRootProps, getInputProps } = useDropzone({
|
const { getRootProps, getInputProps } = useDropzone({
|
||||||
onDrop: (acceptedFiles) => {
|
onDrop: (acceptedFiles) => {
|
||||||
|
|
@ -225,6 +236,8 @@ export default function CreateArticleForm() {
|
||||||
const request = {
|
const request = {
|
||||||
id: diseData?.id,
|
id: diseData?.id,
|
||||||
title: values.title,
|
title: values.title,
|
||||||
|
customCreatorName: values.customCreatorName,
|
||||||
|
source: values.source,
|
||||||
articleBody: removeImgTags(values.description),
|
articleBody: removeImgTags(values.description),
|
||||||
metaDescription: diseData?.metaDescription,
|
metaDescription: diseData?.metaDescription,
|
||||||
metaTitle: diseData?.metaTitle,
|
metaTitle: diseData?.metaTitle,
|
||||||
|
|
@ -280,6 +293,8 @@ export default function CreateArticleForm() {
|
||||||
title: values.title,
|
title: values.title,
|
||||||
typeId: 1,
|
typeId: 1,
|
||||||
slug: values.slug,
|
slug: values.slug,
|
||||||
|
customCreatorName: values.customCreatorName,
|
||||||
|
source: values.source,
|
||||||
categoryIds: values.category.map((a) => a.id).join(","),
|
categoryIds: values.category.map((a) => a.id).join(","),
|
||||||
tags: values.tags.join(","),
|
tags: values.tags.join(","),
|
||||||
description: htmlToString(removeImgTags(values.description)),
|
description: htmlToString(removeImgTags(values.description)),
|
||||||
|
|
@ -324,12 +339,34 @@ export default function CreateArticleForm() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status === "scheduled") {
|
if (status === "scheduled" && startDateValue) {
|
||||||
|
// ambil waktu, default 00:00 jika belum diisi
|
||||||
|
const [hours, minutes] = startTimeValue
|
||||||
|
? startTimeValue.split(":").map(Number)
|
||||||
|
: [0, 0];
|
||||||
|
|
||||||
|
// gabungkan tanggal + waktu
|
||||||
|
const combinedDate = new Date(startDateValue);
|
||||||
|
combinedDate.setHours(hours, minutes, 0, 0);
|
||||||
|
|
||||||
|
// format: 2025-10-08 14:30:00
|
||||||
|
const formattedDateTime = `${combinedDate.getFullYear()}-${String(
|
||||||
|
combinedDate.getMonth() + 1
|
||||||
|
).padStart(2, "0")}-${String(combinedDate.getDate()).padStart(
|
||||||
|
2,
|
||||||
|
"0"
|
||||||
|
)} ${String(combinedDate.getHours()).padStart(2, "0")}:${String(
|
||||||
|
combinedDate.getMinutes()
|
||||||
|
).padStart(2, "0")}:00`;
|
||||||
|
|
||||||
const request = {
|
const request = {
|
||||||
id: articleId,
|
id: articleId,
|
||||||
date: `${startDateValue?.year}-${startDateValue?.month}-${startDateValue?.day}`,
|
date: formattedDateTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("📤 Sending schedule request:", request);
|
||||||
const res = await createArticleSchedule(request);
|
const res = await createArticleSchedule(request);
|
||||||
|
console.log("✅ Schedule response:", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
close();
|
close();
|
||||||
|
|
@ -524,13 +561,21 @@ export default function CreateArticleForm() {
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="single">Single Article</SelectItem>
|
<SelectItem value="single">Single Article</SelectItem>
|
||||||
<SelectItem value="rewrite">Content Rewrite</SelectItem>
|
{/* <SelectItem value="rewrite">Content Rewrite</SelectItem> */}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
{selectedWritingType === "single" ? (
|
{selectedWritingType === "single" ? (
|
||||||
<GenerateSingleArticleForm
|
<GenerateSingleArticleForm
|
||||||
content={(data) => {
|
content={(data) => {
|
||||||
setDiseData(data);
|
setDiseData(data);
|
||||||
|
// setValue("title", data?.title ?? "", {
|
||||||
|
// shouldValidate: true,
|
||||||
|
// shouldDirty: true,
|
||||||
|
// });
|
||||||
|
// setValue("slug", generateSlug(data?.title ?? ""), {
|
||||||
|
// shouldValidate: true,
|
||||||
|
// shouldDirty: true,
|
||||||
|
// });
|
||||||
setValue(
|
setValue(
|
||||||
"description",
|
"description",
|
||||||
data?.articleBody ? data?.articleBody : ""
|
data?.articleBody ? data?.articleBody : ""
|
||||||
|
|
@ -651,7 +696,38 @@ export default function CreateArticleForm() {
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
<p className="text-sm">Kreator</p>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="customCreatorName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<Input
|
||||||
|
id="customCreatorName"
|
||||||
|
type="text"
|
||||||
|
placeholder="Masukkan judul artikel"
|
||||||
|
className="w-full border rounded-lg dark:border-gray-400"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="mt-2">
|
||||||
|
<p className="text-sm">Tipe Kreator</p>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="source"
|
||||||
|
render={({ field }) => (
|
||||||
|
<Select onValueChange={field.onChange} value={field.value}>
|
||||||
|
<SelectTrigger className="w-full border rounded-lg text-sm dark:border-gray-400">
|
||||||
|
<SelectValue placeholder="Pilih tipe kreator" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="internal">Internal</SelectItem>
|
||||||
|
<SelectItem value="external">External</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<p className="text-sm mt-3">Kategori</p>
|
<p className="text-sm mt-3">Kategori</p>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
|
|
@ -664,7 +740,10 @@ export default function CreateArticleForm() {
|
||||||
"!rounded-lg bg-white !border-1 !border-gray-200 dark:!border-stone-500",
|
"!rounded-lg bg-white !border-1 !border-gray-200 dark:!border-stone-500",
|
||||||
}}
|
}}
|
||||||
classNamePrefix="select"
|
classNamePrefix="select"
|
||||||
onChange={onChange}
|
value={value}
|
||||||
|
onChange={(selected) => {
|
||||||
|
onChange(selected);
|
||||||
|
}}
|
||||||
closeMenuOnSelect={false}
|
closeMenuOnSelect={false}
|
||||||
components={animatedComponents}
|
components={animatedComponents}
|
||||||
isClearable={true}
|
isClearable={true}
|
||||||
|
|
@ -683,60 +762,7 @@ export default function CreateArticleForm() {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<p className="text-sm">Tags</p>
|
<p className="text-sm">Tags</p>
|
||||||
{/* <Controller
|
|
||||||
control={control}
|
|
||||||
name="tags"
|
|
||||||
render={({ field: { onChange, value } }) => (
|
|
||||||
<Textarea
|
|
||||||
type="text"
|
|
||||||
id="tags"
|
|
||||||
placeholder=""
|
|
||||||
label=""
|
|
||||||
value={tag}
|
|
||||||
onValueChange={setTag}
|
|
||||||
startContent={
|
|
||||||
<div className="flex flex-wrap gap-1">
|
|
||||||
{value.map((item, index) => (
|
|
||||||
<Chip
|
|
||||||
color="primary"
|
|
||||||
key={index}
|
|
||||||
className=""
|
|
||||||
onClose={() => {
|
|
||||||
const filteredTags = value.filter((tag) => tag !== item);
|
|
||||||
if (filteredTags.length === 0) {
|
|
||||||
setError("tags", {
|
|
||||||
type: "manual",
|
|
||||||
message: "Tags tidak boleh kosong",
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
clearErrors("tags");
|
|
||||||
setValue("tags", filteredTags as [string, ...string[]]);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{item}
|
|
||||||
</Chip>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
onKeyDown={(e) => {
|
|
||||||
if (e.key === "Enter") {
|
|
||||||
if (tag.trim() !== "") {
|
|
||||||
setValue("tags", [...value, tag.trim()]);
|
|
||||||
setTag("");
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
labelPlacement="outside"
|
|
||||||
className="w-full h-fit"
|
|
||||||
classNames={{
|
|
||||||
inputWrapper: ["border-1 rounded-lg", "dark:group-data-[focused=false]:bg-transparent !border-1 dark:!border-gray-400"],
|
|
||||||
}}
|
|
||||||
variant="bordered"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/> */}
|
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="tags"
|
name="tags"
|
||||||
|
|
@ -815,32 +841,49 @@ export default function CreateArticleForm() {
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* {isScheduled && (
|
{isScheduled && (
|
||||||
<div className="flex flex-col lg:flex-row gap-3">
|
<div className="flex flex-col lg:flex-row gap-3 mt-2">
|
||||||
<div className="w-full lg:w-[140px] flex flex-col gal-2 ">
|
{/* Pilih tanggal */}
|
||||||
|
<div className="w-full lg:w-[140px] flex flex-col gap-2">
|
||||||
<p className="text-sm">Tanggal</p>
|
<p className="text-sm">Tanggal</p>
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger>
|
<PopoverTrigger>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className="w-full !h-[30px] lg:h-[40px] border-1 rounded-lg text-black"
|
className="w-full !h-[37px] lg:h-[37px] border-1 rounded-lg text-black"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
>
|
>
|
||||||
{startDateValue
|
{startDateValue
|
||||||
? convertDateFormatNoTime(startDateValue)
|
? startDateValue.toISOString().split("T")[0]
|
||||||
: "-"}
|
: "-"}
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="bg-transparent p-0">
|
<PopoverContent className="bg-transparent p-0">
|
||||||
<Calendar
|
<DatePicker
|
||||||
selected={startDateValue}
|
selected={startDateValue}
|
||||||
onSelect={setStartDateValue}
|
onChange={(date) =>
|
||||||
|
setStartDateValue(date ?? undefined)
|
||||||
|
}
|
||||||
|
dateFormat="yyyy-MM-dd"
|
||||||
|
className="w-full border rounded-lg px-2 py-1 text-black cursor-pointer h-[150px]"
|
||||||
|
placeholderText="Pilih tanggal"
|
||||||
/>
|
/>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Pilih waktu */}
|
||||||
|
<div className="w-full lg:w-[140px] flex flex-col gap-2">
|
||||||
|
<p className="text-sm">Waktu</p>
|
||||||
|
<input
|
||||||
|
type="time"
|
||||||
|
value={startTimeValue}
|
||||||
|
onChange={(e) => setStartTimeValue(e.target.value)}
|
||||||
|
className="w-full border rounded-lg px-2 py-[6px] text-black"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)} */}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,13 @@ import {
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
|
|
||||||
const ViewEditor = dynamic(
|
const ViewEditor = dynamic(
|
||||||
() => {
|
() => {
|
||||||
|
|
@ -81,6 +88,9 @@ const createArticleSchema = z.object({
|
||||||
title: z.string().min(2, {
|
title: z.string().min(2, {
|
||||||
message: "Judul harus diisi",
|
message: "Judul harus diisi",
|
||||||
}),
|
}),
|
||||||
|
customCreatorName: z.string().min(2, {
|
||||||
|
message: "Judul harus diisi",
|
||||||
|
}),
|
||||||
slug: z.string().min(2, {
|
slug: z.string().min(2, {
|
||||||
message: "Slug harus diisi",
|
message: "Slug harus diisi",
|
||||||
}),
|
}),
|
||||||
|
|
@ -92,7 +102,8 @@ const createArticleSchema = z.object({
|
||||||
}),
|
}),
|
||||||
tags: z.array(z.string()).nonempty({
|
tags: z.array(z.string()).nonempty({
|
||||||
message: "Minimal 1 tag",
|
message: "Minimal 1 tag",
|
||||||
}), // Array berisi string
|
}),
|
||||||
|
source: z.enum(["internal", "external"]).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
interface DiseData {
|
interface DiseData {
|
||||||
|
|
@ -179,7 +190,9 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
|
||||||
const data = res.data?.data;
|
const data = res.data?.data;
|
||||||
setDetailData(data);
|
setDetailData(data);
|
||||||
setValue("title", data?.title);
|
setValue("title", data?.title);
|
||||||
|
setValue("customCreatorName", data?.customCreatorName);
|
||||||
setValue("slug", data?.slug);
|
setValue("slug", data?.slug);
|
||||||
|
setValue("source", data?.source);
|
||||||
setValue("description", data?.htmlDescription);
|
setValue("description", data?.htmlDescription);
|
||||||
setValue("tags", data?.tags ? data.tags.split(",") : []);
|
setValue("tags", data?.tags ? data.tags.split(",") : []);
|
||||||
setThumbnail(data?.thumbnailUrl);
|
setThumbnail(data?.thumbnailUrl);
|
||||||
|
|
@ -549,7 +562,7 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<p className="text-sm mt-3">Deskripsi</p>
|
<p className="text-sm mt-3">Deskripsi</p>
|
||||||
<Controller
|
{/* <Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="description"
|
name="description"
|
||||||
render={({ field: { onChange, value } }) =>
|
render={({ field: { onChange, value } }) =>
|
||||||
|
|
@ -572,8 +585,17 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
|
||||||
<p className="text-red-400 text-sm mb-3">
|
<p className="text-red-400 text-sm mb-3">
|
||||||
{errors.description?.message}
|
{errors.description?.message}
|
||||||
</p>
|
</p>
|
||||||
|
)} */}
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="description"
|
||||||
|
render={({ field }) => (
|
||||||
|
<CustomEditor onChange={field.onChange} initialData={field.value} />
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{errors.description?.message && (
|
||||||
|
<p className="text-red-400 text-sm">{errors.description.message}</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<p className="text-sm mt-3">File Media</p>
|
<p className="text-sm mt-3">File Media</p>
|
||||||
{!isDetail && (
|
{!isDetail && (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
|
@ -672,6 +694,7 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
type="button"
|
||||||
className=" border-none rounded-full"
|
className=" border-none rounded-full"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
color="danger"
|
color="danger"
|
||||||
|
|
@ -773,6 +796,43 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
<p className="text-sm">Kreator</p>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="customCreatorName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<Input
|
||||||
|
id="customCreatorName"
|
||||||
|
type="text"
|
||||||
|
placeholder="Masukkan Kreator artikel"
|
||||||
|
readOnly={isDetail}
|
||||||
|
className="w-full border rounded-lg dark:border-gray-400"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="mt-2">
|
||||||
|
<p className="text-sm">Tipe Kreator</p>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="source"
|
||||||
|
render={({ field }) => (
|
||||||
|
<Select
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
value={field.value}
|
||||||
|
disabled={isDetail}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-full border rounded-lg text-sm dark:border-gray-400">
|
||||||
|
<SelectValue placeholder="Pilih tipe kreator" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="internal">Internal</SelectItem>
|
||||||
|
<SelectItem value="external">External</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<p className="text-sm mt-3">Kategori</p>
|
<p className="text-sm mt-3">Kategori</p>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
|
|
@ -943,14 +1003,11 @@ export default function EditArticleForm(props: { isDetail: boolean }) {
|
||||||
Simpan
|
Simpan
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{isDetail &&
|
{detailData?.isPublish === false && (
|
||||||
detailData?.isPublish === false &&
|
<Button type="button" color="primary" onClick={doPublish}>
|
||||||
detailData?.statusId !== 1 &&
|
Publish
|
||||||
Number(userId) === detailData?.createdById && (
|
</Button>
|
||||||
<Button type="button" color="primary" onClick={doPublish}>
|
)}
|
||||||
Publish
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{/* {!isDetail && (
|
{/* {!isDetail && (
|
||||||
<Button color="success" type="button">
|
<Button color="success" type="button">
|
||||||
<p className="text-white">Draft</p>
|
<p className="text-white">Draft</p>
|
||||||
|
|
|
||||||
|
|
@ -76,16 +76,15 @@ interface DiseData {
|
||||||
export default function GenerateSingleArticleForm(props: {
|
export default function GenerateSingleArticleForm(props: {
|
||||||
content: (data: DiseData) => void;
|
content: (data: DiseData) => void;
|
||||||
}) {
|
}) {
|
||||||
const [selectedWritingSyle, setSelectedWritingStyle] =
|
const [selectedWritingSyle, setSelectedWritingStyle] = useState("");
|
||||||
useState("Informational");
|
const [selectedArticleSize, setSelectedArticleSize] = useState("");
|
||||||
const [selectedArticleSize, setSelectedArticleSize] = useState("News");
|
const [selectedLanguage, setSelectedLanguage] = useState("");
|
||||||
const [selectedLanguage, setSelectedLanguage] = useState("id");
|
|
||||||
const [mainKeyword, setMainKeyword] = useState("");
|
const [mainKeyword, setMainKeyword] = useState("");
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const [additionalKeyword, setAdditionalKeyword] = useState("");
|
const [additionalKeyword, setAdditionalKeyword] = useState("");
|
||||||
const [articleIds, setArticleIds] = useState<number[]>([]);
|
const [articleIds, setArticleIds] = useState<number[]>([]);
|
||||||
const [selectedId, setSelectedId] = useState<number>();
|
const [selectedId, setSelectedId] = useState<number>();
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const generateAll = async (keyword: string | undefined) => {
|
const generateAll = async (keyword: string | undefined) => {
|
||||||
if (keyword) {
|
if (keyword) {
|
||||||
|
|
@ -271,11 +270,11 @@ export default function GenerateSingleArticleForm(props: {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-full border border-gray-300 dark:border-gray-400 rounded-lg text-black">
|
<SelectTrigger className="w-full border border-gray-300 dark:border-gray-400 rounded-lg text-black">
|
||||||
<SelectValue placeholder="Writing Style" />
|
<SelectValue placeholder="Article Size" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{articleSize.map((style) => (
|
{articleSize.map((style) => (
|
||||||
<SelectItem key={style.name} value={style.name}>
|
<SelectItem key={style.name} value={style.value}>
|
||||||
{style.name}
|
{style.name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
|
|
@ -307,7 +306,7 @@ export default function GenerateSingleArticleForm(props: {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-full border border-gray-300 dark:border-gray-400 rounded-lg text-black">
|
<SelectTrigger className="w-full border border-gray-300 dark:border-gray-400 rounded-lg text-black">
|
||||||
<SelectValue placeholder="Bahasa" />
|
<SelectValue placeholder="Language" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="id">Indonesia</SelectItem>
|
<SelectItem value="id">Indonesia</SelectItem>
|
||||||
|
|
@ -319,6 +318,7 @@ export default function GenerateSingleArticleForm(props: {
|
||||||
<div className="flex flex-row gap-2 items-center">
|
<div className="flex flex-row gap-2 items-center">
|
||||||
<p className="text-sm">Main Keyword</p>
|
<p className="text-sm">Main Keyword</p>
|
||||||
<Button
|
<Button
|
||||||
|
type="button"
|
||||||
variant="default"
|
variant="default"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => generateAll(mainKeyword)}
|
onClick={() => generateAll(mainKeyword)}
|
||||||
|
|
@ -350,6 +350,7 @@ export default function GenerateSingleArticleForm(props: {
|
||||||
<div className="flex flex-row gap-2 items-center mt-3">
|
<div className="flex flex-row gap-2 items-center mt-3">
|
||||||
<p className="text-sm">Title</p>
|
<p className="text-sm">Title</p>
|
||||||
<Button
|
<Button
|
||||||
|
type="button"
|
||||||
variant="default"
|
variant="default"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => generateTitle(mainKeyword)}
|
onClick={() => generateTitle(mainKeyword)}
|
||||||
|
|
@ -373,6 +374,7 @@ export default function GenerateSingleArticleForm(props: {
|
||||||
<div className="flex flex-row gap-2 items-center mt-2">
|
<div className="flex flex-row gap-2 items-center mt-2">
|
||||||
<p className="text-sm">Additional Keyword</p>
|
<p className="text-sm">Additional Keyword</p>
|
||||||
<Button
|
<Button
|
||||||
|
type="button"
|
||||||
className="text-sm"
|
className="text-sm"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => generateKeywords(mainKeyword)}
|
onClick={() => generateKeywords(mainKeyword)}
|
||||||
|
|
@ -417,6 +419,7 @@ export default function GenerateSingleArticleForm(props: {
|
||||||
<div className="flex flex-row gap-1 mt-2">
|
<div className="flex flex-row gap-1 mt-2">
|
||||||
{articleIds.map((id, index) => (
|
{articleIds.map((id, index) => (
|
||||||
<Button
|
<Button
|
||||||
|
type="button"
|
||||||
key={id}
|
key={id}
|
||||||
onClick={() => setSelectedId(id)}
|
onClick={() => setSelectedId(id)}
|
||||||
disabled={isLoading && selectedId === id}
|
disabled={isLoading && selectedId === id}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { getAdvertise } from "@/service/advertisement";
|
||||||
import { getListArticle } from "@/service/article";
|
import { getListArticle } from "@/service/article";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
@ -22,6 +23,15 @@ type Article = {
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type Advertise = {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
placement: string;
|
||||||
|
contentFileUrl: string;
|
||||||
|
redirectLink: string;
|
||||||
|
};
|
||||||
|
|
||||||
export default function News() {
|
export default function News() {
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const [totalPage, setTotalPage] = useState(1);
|
const [totalPage, setTotalPage] = useState(1);
|
||||||
|
|
@ -34,6 +44,36 @@ export default function News() {
|
||||||
endDate: null,
|
endDate: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [bannerAd, setBannerAd] = useState<Advertise | null>(null);
|
||||||
|
const [bannerImageAd, setBannerImageAd] = useState<Advertise | null>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
initStateAdver();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function initStateAdver() {
|
||||||
|
const req = {
|
||||||
|
limit: 100,
|
||||||
|
page: 1,
|
||||||
|
sort: "desc",
|
||||||
|
sortBy: "created_at",
|
||||||
|
isPublish: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await getAdvertise(req);
|
||||||
|
const data: Advertise[] = res?.data?.data || [];
|
||||||
|
|
||||||
|
// ambil iklan placement jumbotron
|
||||||
|
const jumbotron = data.find((ad) => ad.placement === "jumbotron");
|
||||||
|
if (jumbotron) setBannerAd(jumbotron);
|
||||||
|
|
||||||
|
// ambil iklan placement banner
|
||||||
|
const banner = data.find((ad) => ad.placement === "banner");
|
||||||
|
if (banner) setBannerImageAd(banner);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error fetching advertisement:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initState();
|
initState();
|
||||||
}, [page, showData, startDateValue, selectedCategories]);
|
}, [page, showData, startDateValue, selectedCategories]);
|
||||||
|
|
@ -137,40 +177,96 @@ export default function News() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="relative my-5 max-w-full h-[125px] overflow-hidden flex items-center mx-auto border">
|
<div className="relative my-5 max-w-full h-[125px] overflow-hidden flex items-center mx-auto border">
|
||||||
<Image
|
{bannerImageAd ? (
|
||||||
src="/image-kolom.png"
|
<a
|
||||||
alt="Berita Utama"
|
href={bannerImageAd.redirectLink}
|
||||||
fill
|
target="_blank"
|
||||||
className="object-cover"
|
rel="noopener noreferrer"
|
||||||
/>
|
className="w-full h-full relative"
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
src={bannerImageAd.contentFileUrl}
|
||||||
|
alt={bannerImageAd.title || "Iklan Banner"}
|
||||||
|
fill
|
||||||
|
className="object-cover"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<Image
|
||||||
|
src="/image-kolom.png"
|
||||||
|
alt="Banner Default"
|
||||||
|
fill
|
||||||
|
className="object-cover"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right: Sidebar */}
|
{/* Right: Sidebar */}
|
||||||
<aside className="w-full lg:w-[340px]">
|
<aside className="w-full lg:w-[340px]">
|
||||||
<div className="relative w-[1111px] max-w-full h-[400px] overflow-hidden flex items-center mx-auto border my-6 rounded">
|
<div className="relative w-[1111px] max-w-full h-[400px] overflow-hidden flex items-center mx-auto border my-6 rounded">
|
||||||
|
{bannerAd ? (
|
||||||
|
<a
|
||||||
|
href={bannerAd.redirectLink}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="block w-full"
|
||||||
|
>
|
||||||
|
<div className="relative w-full h-[350px] flex justify-center">
|
||||||
|
<Image
|
||||||
|
src={bannerAd.contentFileUrl}
|
||||||
|
alt={bannerAd.title || "Iklan Banner"}
|
||||||
|
width={1200} // ukuran dasar untuk responsive
|
||||||
|
height={350}
|
||||||
|
className="object-cover w-full h-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<Image
|
||||||
|
src="/kolom.png"
|
||||||
|
alt="Berita Utama"
|
||||||
|
width={1200}
|
||||||
|
height={188}
|
||||||
|
className="object-contain w-full h-[188px]"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{/* <div className="relative w-[1111px] max-w-full h-[400px] overflow-hidden flex items-center mx-auto border my-6 rounded">
|
||||||
<Image
|
<Image
|
||||||
src="/xtweet.png"
|
src="/xtweet.png"
|
||||||
alt="Berita Utama"
|
alt="Berita Utama"
|
||||||
fill
|
fill
|
||||||
className="object-contain rounded"
|
className="object-contain rounded"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div> */}
|
||||||
<div className="relative w-[1111px] max-w-full h-[400px] overflow-hidden flex items-center mx-auto border my-6 rounded">
|
|
||||||
<Image
|
|
||||||
src="/xtweet.png"
|
|
||||||
alt="Berita Utama"
|
|
||||||
fill
|
|
||||||
className="object-contain rounded"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="relative w-[1111px] max-w-full h-[300px] overflow-hidden flex items-center mx-auto border my-6 rounded">
|
<div className="relative w-[1111px] max-w-full h-[300px] overflow-hidden flex items-center mx-auto border my-6 rounded">
|
||||||
<Image
|
{bannerAd ? (
|
||||||
src="/kolom.png"
|
<a
|
||||||
alt="Berita Utama"
|
href={bannerAd.redirectLink}
|
||||||
fill
|
target="_blank"
|
||||||
className="object-contain rounded"
|
rel="noopener noreferrer"
|
||||||
/>
|
className="block w-full"
|
||||||
|
>
|
||||||
|
<div className="relative w-full h-[350px] flex justify-center">
|
||||||
|
<Image
|
||||||
|
src={bannerAd.contentFileUrl}
|
||||||
|
alt={bannerAd.title || "Iklan Banner"}
|
||||||
|
width={1200} // ukuran dasar untuk responsive
|
||||||
|
height={350}
|
||||||
|
className="object-cover w-full h-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<Image
|
||||||
|
src="/kolom.png"
|
||||||
|
alt="Berita Utama"
|
||||||
|
width={1200}
|
||||||
|
height={188}
|
||||||
|
className="object-contain w-full h-[188px]"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { getAdvertise } from "@/service/advertisement";
|
||||||
import { getListArticle } from "@/service/article";
|
import { getListArticle } from "@/service/article";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
@ -24,6 +25,15 @@ type NewsColumnProps = {
|
||||||
items: Article[];
|
items: Article[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type Advertise = {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
placement: string;
|
||||||
|
contentFileUrl: string;
|
||||||
|
redirectLink: string;
|
||||||
|
};
|
||||||
|
|
||||||
function NewsColumn({ title, color, items }: NewsColumnProps) {
|
function NewsColumn({ title, color, items }: NewsColumnProps) {
|
||||||
return (
|
return (
|
||||||
<div className="bg-transparent p-4">
|
<div className="bg-transparent p-4">
|
||||||
|
|
@ -98,6 +108,36 @@ export default function Opini() {
|
||||||
endDate: null,
|
endDate: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [bannerAd, setBannerAd] = useState<Advertise | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
initStateAdver();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function initStateAdver() {
|
||||||
|
const req = {
|
||||||
|
limit: 100,
|
||||||
|
page: 1,
|
||||||
|
sort: "desc",
|
||||||
|
sortBy: "created_at",
|
||||||
|
isPublish: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await getAdvertise(req);
|
||||||
|
const data: Advertise[] = res?.data?.data || [1];
|
||||||
|
|
||||||
|
// filter iklan dengan placement = "banner"
|
||||||
|
const banner = data.find((ad) => ad.placement === "banner");
|
||||||
|
|
||||||
|
if (banner) {
|
||||||
|
setBannerAd(banner);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error fetching advertisement:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function groupArticlesByCategory(articles: Article[]) {
|
function groupArticlesByCategory(articles: Article[]) {
|
||||||
const categoryMap: { [title: string]: Article[] } = {};
|
const categoryMap: { [title: string]: Article[] } = {};
|
||||||
|
|
||||||
|
|
@ -154,12 +194,32 @@ export default function Opini() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="relative my-5 max-w-full h-[125px] overflow-hidden flex items-center mx-auto border">
|
<div className="relative my-5 max-w-full h-[125px] overflow-hidden flex items-center mx-auto border">
|
||||||
<Image
|
{bannerAd ? (
|
||||||
src="/image-kolom.png"
|
<a
|
||||||
alt="Berita Utama"
|
href={bannerAd.redirectLink}
|
||||||
fill
|
target="_blank"
|
||||||
className="object-cover"
|
rel="noopener noreferrer"
|
||||||
/>
|
className="block w-full"
|
||||||
|
>
|
||||||
|
<div className="relative w-full h-[350px] flex justify-center">
|
||||||
|
<Image
|
||||||
|
src={bannerAd.contentFileUrl}
|
||||||
|
alt={bannerAd.title || "Iklan Banner"}
|
||||||
|
width={1200} // ukuran dasar untuk responsive
|
||||||
|
height={350}
|
||||||
|
className="object-cover w-full h-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<Image
|
||||||
|
src="/image-kolom.png"
|
||||||
|
alt="Berita Utama"
|
||||||
|
width={1200}
|
||||||
|
height={188}
|
||||||
|
className="object-contain w-full h-[188px]"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,12 @@ import {
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { Article } from "@/types/globals";
|
||||||
|
import {
|
||||||
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverTrigger,
|
||||||
|
} from "@/components/ui/popover";
|
||||||
import {
|
import {
|
||||||
getListArticle,
|
getListArticle,
|
||||||
getStatisticSummary,
|
getStatisticSummary,
|
||||||
|
|
@ -23,12 +29,14 @@ import {
|
||||||
convertDateFormatNoTime,
|
convertDateFormatNoTime,
|
||||||
textEllipsis,
|
textEllipsis,
|
||||||
} from "@/utils/global";
|
} from "@/utils/global";
|
||||||
|
import DatePicker from "react-datepicker";
|
||||||
import "react-datepicker/dist/react-datepicker.css";
|
import "react-datepicker/dist/react-datepicker.css";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Calendar } from "@/components/ui/calendar";
|
||||||
import ApexChartColumn from "@/components/main/dashboard/chart/column-chart";
|
import ApexChartColumn from "@/components/main/dashboard/chart/column-chart";
|
||||||
import CustomPagination from "@/components/layout/custom-pagination";
|
import CustomPagination from "@/components/layout/custom-pagination";
|
||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
import { Article } from "@/types/globals";
|
|
||||||
|
|
||||||
type ArticleData = Article & {
|
type ArticleData = Article & {
|
||||||
no: number;
|
no: number;
|
||||||
|
|
@ -98,7 +106,7 @@ export default function DashboardContainer() {
|
||||||
|
|
||||||
async function initState() {
|
async function initState() {
|
||||||
const req = {
|
const req = {
|
||||||
limit: "4",
|
limit: "5",
|
||||||
page: page,
|
page: page,
|
||||||
search: "",
|
search: "",
|
||||||
};
|
};
|
||||||
|
|
@ -349,11 +357,11 @@ export default function DashboardContainer() {
|
||||||
<h3 className="text-lg font-semibold text-slate-800">
|
<h3 className="text-lg font-semibold text-slate-800">
|
||||||
Recent Articles
|
Recent Articles
|
||||||
</h3>
|
</h3>
|
||||||
<Link href="/admin/article/create">
|
{/* <Link href="/admin/article/create">
|
||||||
<Button className="bg-gradient-to-r from-blue-500 to-purple-500 hover:from-blue-600 hover:to-purple-600 text-white shadow-lg">
|
<Button className="bg-gradient-to-r from-blue-500 to-purple-500 hover:from-blue-600 hover:to-purple-600 text-white shadow-lg">
|
||||||
Create Article
|
Create Article
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link> */}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-4 max-h-96 overflow-y-auto scrollbar-thin">
|
<div className="space-y-4 max-h-96 overflow-y-auto scrollbar-thin">
|
||||||
|
|
@ -366,7 +374,7 @@ export default function DashboardContainer() {
|
||||||
>
|
>
|
||||||
<Image
|
<Image
|
||||||
alt="thumbnail"
|
alt="thumbnail"
|
||||||
src={list?.thumbnailUrl || `/default-image.jpg`}
|
src={list?.thumbnailUrl || `/no-image.jpg`}
|
||||||
width={80}
|
width={80}
|
||||||
height={80}
|
height={80}
|
||||||
className="h-20 w-20 object-cover rounded-lg shadow-sm flex-shrink-0"
|
className="h-20 w-20 object-cover rounded-lg shadow-sm flex-shrink-0"
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
} 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 { Article } from "@/types/globals";
|
import { Article } from "@/types/globals";
|
||||||
import { convertDateFormat } from "@/utils/global";
|
import { convertDateFormat, formatDate } from "@/utils/global";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Key, useCallback, useEffect, useState } from "react";
|
import { Key, useCallback, useEffect, useState } from "react";
|
||||||
import Swal from "sweetalert2";
|
import Swal from "sweetalert2";
|
||||||
|
|
@ -54,7 +54,7 @@ const columns = [
|
||||||
{ name: "Banner", uid: "isBanner" },
|
{ name: "Banner", uid: "isBanner" },
|
||||||
{ name: "Kategori", uid: "category" },
|
{ name: "Kategori", uid: "category" },
|
||||||
{ name: "Tanggal Unggah", uid: "createdAt" },
|
{ name: "Tanggal Unggah", uid: "createdAt" },
|
||||||
{ name: "Kreator", uid: "createdByName" },
|
{ name: "Kreator", uid: "customCreatorName" },
|
||||||
{ name: "Status", uid: "isPublish" },
|
{ name: "Status", uid: "isPublish" },
|
||||||
{ name: "Aksi", uid: "actions" },
|
{ name: "Aksi", uid: "actions" },
|
||||||
];
|
];
|
||||||
|
|
@ -64,7 +64,7 @@ const columnsOtherRole = [
|
||||||
{ name: "Source", uid: "source" },
|
{ name: "Source", uid: "source" },
|
||||||
{ name: "Kategori", uid: "category" },
|
{ name: "Kategori", uid: "category" },
|
||||||
{ name: "Tanggal Unggah", uid: "createdAt" },
|
{ name: "Tanggal Unggah", uid: "createdAt" },
|
||||||
{ name: "Kreator", uid: "createdByName" },
|
{ name: "Kreator", uid: "customCreatorName" },
|
||||||
{ name: "Status", uid: "isPublish" },
|
{ name: "Status", uid: "isPublish" },
|
||||||
{ name: "Aksi", uid: "actions" },
|
{ name: "Aksi", uid: "actions" },
|
||||||
];
|
];
|
||||||
|
|
@ -86,6 +86,7 @@ export default function ArticleTable() {
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [categories, setCategories] = useState<any>([]);
|
const [categories, setCategories] = useState<any>([]);
|
||||||
const [selectedCategories, setSelectedCategories] = useState<any>("");
|
const [selectedCategories, setSelectedCategories] = useState<any>("");
|
||||||
|
const [selectedCategoryId, setSelectedCategoryId] = useState<any>("");
|
||||||
const [selectedSource, setSelectedSource] = useState<any>("");
|
const [selectedSource, setSelectedSource] = useState<any>("");
|
||||||
const [selectedStatus, setSelectedStatus] = useState<string>("");
|
const [selectedStatus, setSelectedStatus] = useState<string>("");
|
||||||
const [dateRange, setDateRange] = useState<any>({
|
const [dateRange, setDateRange] = useState<any>({
|
||||||
|
|
@ -111,7 +112,7 @@ export default function ArticleTable() {
|
||||||
page,
|
page,
|
||||||
showData,
|
showData,
|
||||||
search,
|
search,
|
||||||
selectedCategories,
|
selectedCategoryId,
|
||||||
selectedSource,
|
selectedSource,
|
||||||
dateRange,
|
dateRange,
|
||||||
selectedStatus,
|
selectedStatus,
|
||||||
|
|
@ -123,16 +124,12 @@ export default function ArticleTable() {
|
||||||
limit: showData,
|
limit: showData,
|
||||||
page: page,
|
page: page,
|
||||||
search: search,
|
search: search,
|
||||||
category: selectedCategories || "",
|
category: selectedCategoryId || "",
|
||||||
source: selectedSource || "",
|
source: selectedSource || "",
|
||||||
isPublish:
|
isPublish:
|
||||||
selectedStatus !== "" ? selectedStatus === "publish" : undefined,
|
selectedStatus !== "" ? selectedStatus === "publish" : undefined,
|
||||||
startDate: dateRange.startDate
|
startDate: formatDate(dateRange.startDate),
|
||||||
? new Date(dateRange.startDate).toISOString()
|
endDate: formatDate(dateRange.endDate),
|
||||||
: "",
|
|
||||||
endDate: dateRange.endDate
|
|
||||||
? new Date(dateRange.endDate).toISOString()
|
|
||||||
: "",
|
|
||||||
sort: "desc",
|
sort: "desc",
|
||||||
sortBy: "created_at",
|
sortBy: "created_at",
|
||||||
};
|
};
|
||||||
|
|
@ -221,6 +218,15 @@ export default function ArticleTable() {
|
||||||
const cellValue = article[columnKey as keyof any];
|
const cellValue = article[columnKey as keyof any];
|
||||||
|
|
||||||
switch (columnKey) {
|
switch (columnKey) {
|
||||||
|
case "customCreatorName":
|
||||||
|
return (
|
||||||
|
<p>
|
||||||
|
{article.customCreatorName &&
|
||||||
|
article.customCreatorName.trim() !== ""
|
||||||
|
? article.customCreatorName
|
||||||
|
: article.createdByName}
|
||||||
|
</p>
|
||||||
|
);
|
||||||
case "isPublish":
|
case "isPublish":
|
||||||
return (
|
return (
|
||||||
// <Chip
|
// <Chip
|
||||||
|
|
@ -367,8 +373,8 @@ export default function ArticleTable() {
|
||||||
<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
|
<Select
|
||||||
value={selectedCategories}
|
value={selectedCategoryId}
|
||||||
onValueChange={(value) => setSelectedCategories(value)}
|
onValueChange={(value) => setSelectedCategoryId(value)} // simpan ID
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-full text-sm border">
|
<SelectTrigger className="w-full text-sm border">
|
||||||
<SelectValue placeholder="Kategori" />
|
<SelectValue placeholder="Kategori" />
|
||||||
|
|
@ -377,7 +383,10 @@ export default function ArticleTable() {
|
||||||
{categories
|
{categories
|
||||||
?.filter((category: any) => category.title != null)
|
?.filter((category: any) => category.title != null)
|
||||||
.map((category: any) => (
|
.map((category: any) => (
|
||||||
<SelectItem key={category.id} value={category.title}>
|
<SelectItem
|
||||||
|
key={category.id}
|
||||||
|
value={category.id.toString()} // kirim ID, bukan title
|
||||||
|
>
|
||||||
{category.title}
|
{category.title}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
|
|
@ -394,8 +403,8 @@ export default function ArticleTable() {
|
||||||
<SelectValue placeholder="Pilih Source" />
|
<SelectValue placeholder="Pilih Source" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="INTERNAL">INTERNAL</SelectItem>
|
<SelectItem value="internal">INTERNAL</SelectItem>
|
||||||
<SelectItem value="EXTERNAL">EXTERNAL</SelectItem>
|
<SelectItem value="external">EXTERNAL</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,14 @@ export async function getListArticle(props: PaginationRequest) {
|
||||||
categorySlug,
|
categorySlug,
|
||||||
isBanner,
|
isBanner,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
return await httpGet(
|
return await httpGet(
|
||||||
`/articles?limit=${limit}&page=${page}&isPublish=${
|
`/articles?limit=${limit}&page=${page}&isPublish=${
|
||||||
isPublish === undefined ? "" : isPublish
|
isPublish === undefined ? "" : isPublish
|
||||||
}&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 || "asc"
|
sort || "desc"
|
||||||
}&category=${categorySlug || ""}&isBanner=${isBanner || ""}`,
|
}&category=${categorySlug || ""}&isBanner=${isBanner || ""}`,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ const axiosBaseInstance = axios.create({
|
||||||
baseURL,
|
baseURL,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-Client-Key": "bb65b1ad-e954-4a1a-b4d0-74df5bb0b640"
|
"X-Client-Key": "769a3462-f54b-4b2a-90a3-632ddda3bc27",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ const axiosInterceptorInstance = axios.create({
|
||||||
baseURL,
|
baseURL,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-Client-Key": "bb65b1ad-e954-4a1a-b4d0-74df5bb0b640"
|
"X-Client-Key": "769a3462-f54b-4b2a-90a3-632ddda3bc27",
|
||||||
},
|
},
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ import axiosBaseInstance from "./axios-base-instance";
|
||||||
|
|
||||||
const defaultHeaders = {
|
const defaultHeaders = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-Client-Key": "bb65b1ad-e954-4a1a-b4d0-74df5bb0b640"
|
"X-Client-Key": "769a3462-f54b-4b2a-90a3-632ddda3bc27",
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function httpGet(pathUrl: any, headers?: any) {
|
export async function httpGet(pathUrl: any, headers?: any) {
|
||||||
console.log("X-HEADERS : ", defaultHeaders)
|
console.log("X-HEADERS : ", defaultHeaders);
|
||||||
const mergedHeaders = {
|
const mergedHeaders = {
|
||||||
...defaultHeaders,
|
...defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ import { getCsrfToken } from "../master-user";
|
||||||
|
|
||||||
const defaultHeaders = {
|
const defaultHeaders = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-Client-Key": "bb65b1ad-e954-4a1a-b4d0-74df5bb0b640"
|
"X-Client-Key": "769a3462-f54b-4b2a-90a3-632ddda3bc27",
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function httpGetInterceptor(pathUrl: any) {
|
export async function httpGetInterceptor(pathUrl: any) {
|
||||||
console.log("X-HEADERS : ", defaultHeaders)
|
console.log("X-HEADERS : ", defaultHeaders);
|
||||||
const response = await axiosInterceptorInstance
|
const response = await axiosInterceptorInstance
|
||||||
.get(pathUrl, { headers: defaultHeaders })
|
.get(pathUrl, { headers: defaultHeaders })
|
||||||
.catch((error) => error.response);
|
.catch((error) => error.response);
|
||||||
|
|
@ -35,7 +35,11 @@ export async function httpGetInterceptor(pathUrl: any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function httpPostInterceptor(pathUrl: any, data: any, headers?: any) {
|
export async function httpPostInterceptor(
|
||||||
|
pathUrl: any,
|
||||||
|
data: any,
|
||||||
|
headers?: any
|
||||||
|
) {
|
||||||
const resCsrf = await getCsrfToken();
|
const resCsrf = await getCsrfToken();
|
||||||
const csrfToken = resCsrf?.data?.csrf_token;
|
const csrfToken = resCsrf?.data?.csrf_token;
|
||||||
|
|
||||||
|
|
@ -67,7 +71,11 @@ export async function httpPostInterceptor(pathUrl: any, data: any, headers?: any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function httpPutInterceptor(pathUrl: any, data: any, headers?: any) {
|
export async function httpPutInterceptor(
|
||||||
|
pathUrl: any,
|
||||||
|
data: any,
|
||||||
|
headers?: any
|
||||||
|
) {
|
||||||
const resCsrf = await getCsrfToken();
|
const resCsrf = await getCsrfToken();
|
||||||
const csrfToken = resCsrf?.data?.csrf_token;
|
const csrfToken = resCsrf?.data?.csrf_token;
|
||||||
|
|
||||||
|
|
@ -99,7 +107,7 @@ export async function httpPutInterceptor(pathUrl: any, data: any, headers?: any)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function httpDeleteInterceptor(pathUrl: any, headers?: any) {
|
export async function httpDeleteInterceptor(pathUrl: any, headers?: any) {
|
||||||
const resCsrf = await getCsrfToken();
|
const resCsrf = await getCsrfToken();
|
||||||
const csrfToken = resCsrf?.data?.csrf_token;
|
const csrfToken = resCsrf?.data?.csrf_token;
|
||||||
|
|
||||||
const mergedHeaders = {
|
const mergedHeaders = {
|
||||||
|
|
|
||||||
|
|
@ -164,3 +164,11 @@ export function convertDateFormatNoTime(date: Date): string {
|
||||||
const day = `${date.getDate()}`.padStart(2, "0");
|
const day = `${date.getDate()}`.padStart(2, "0");
|
||||||
return `${year}-${month}-${day}`;
|
return `${year}-${month}-${day}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatDate(date: Date | null) {
|
||||||
|
if (!date) return "";
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
||||||
|
const day = String(date.getDate()).padStart(2, "0");
|
||||||
|
return `${year}-${month}-${day}`;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue