From 3f1ffdd15ad747fe3b310fca698017a0b74a18ec Mon Sep 17 00:00:00 2001 From: Anang Yusman Date: Wed, 1 Jan 2025 23:27:38 +0800 Subject: [PATCH] feat:add content rewrite, add create AI --- components/form/content/image-form.tsx | 22 +- components/form/content/spit-convert-form.tsx | 219 +++++++-- components/landing-page/navbar.tsx | 420 +++++++++++++++--- components/partials/header/profile-info.tsx | 91 +--- 4 files changed, 556 insertions(+), 196 deletions(-) diff --git a/components/form/content/image-form.tsx b/components/form/content/image-form.tsx index 61d426ed..3d7c3574 100644 --- a/components/form/content/image-form.tsx +++ b/components/form/content/image-form.tsx @@ -321,9 +321,10 @@ export default function FormImage() { }; const save = async (data: ImageSchema) => { + const finalTitle = isSwitchOn ? title : data.title; const requestData = { ...data, - title: data.title, + title: finalTitle, description: data.description, htmlDescription: data.description, fileTypeId, @@ -614,31 +615,30 @@ export default function FormImage() {
- +

{isGeneratedArticle && ( -
+
{articleIds.map((id: string, index: number) => ( - +

))}
)} diff --git a/components/form/content/spit-convert-form.tsx b/components/form/content/spit-convert-form.tsx index 7a0210d9..12d81890 100644 --- a/components/form/content/spit-convert-form.tsx +++ b/components/form/content/spit-convert-form.tsx @@ -45,6 +45,8 @@ import "swiper/css"; import "swiper/css/navigation"; import { FreeMode, Navigation, Pagination, Thumbs } from "swiper/modules"; import { request } from "http"; +import { generateDataArticle, getDetailArticle } from "@/service/content/ai"; +import { getCookiesDecrypt } from "@/lib/utils"; const imageSchema = z.object({ contentTitle: z.string().min(1, { message: "Judul diperlukan" }), @@ -53,6 +55,9 @@ const imageSchema = z.object({ .min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter." }), contentCreator: z.string().min(1, { message: "Creator diperlukan" }), // tags: z.string().min(1, { message: "Judul diperlukan" }), + contentRewriteDescription: z + .string() + .min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter." }), }); type Category = { @@ -99,6 +104,17 @@ export default function FormConvertSPIT() { const [selectedPublishers, setSelectedPublishers] = useState([]); const [detailThumb, setDetailThumb] = useState([]); const [thumbsSwiper, setThumbsSwiper] = useState(null); + const [selectedAdvConfig, setSelectedAdvConfig] = useState(""); + const [title, setTitle] = useState(""); + const roleId = getCookiesDecrypt("urie"); + const [articleIds, setArticleIds] = useState([]); + const [isGeneratedArticle, setIsGeneratedArticle] = useState(false); + const [articleBody, setArticleBody] = useState(""); + const [selectedArticleId, setSelectedArticleId] = useState( + null + ); + const [detailData, setDetailData] = useState(null); + const [selectedFileType, setSelectedFileType] = useState("original"); const [selectedTarget, setSelectedTarget] = useState(""); const [unitSelection, setUnitSelection] = useState({ @@ -232,11 +248,15 @@ export default function FormConvertSPIT() { }; const save = async (data: any) => { + const description = + selectedFileType === "original" + ? data.contentDescription + : data.contentRewriteDescription; const requestData = { spitId: id, title: data.contentTitle, - description: data.contentDescription, - htmlDescription: data.contentDescription, + description, + htmlDescription: description, tags: "siap", categoryId: selectedCategoryId, publishedFor: "6", @@ -274,6 +294,72 @@ export default function FormConvertSPIT() { }); }; + const [showRewriteEditor, setShowRewriteEditor] = useState(false); + + // const handleRewriteClick = () => { + // setShowRewriteEditor(true); + // }; + + const handleRewriteClick = async () => { + const request = { + advConfig: selectedAdvConfig, + style: "friendly", + website: "None", + connectToWeb: true, + lang: "id", + pointOfView: "None", + title: detail?.contentTitle, + imageSource: "Web", + mainKeyword: detail?.contentTitle, + additionalKeywords: detail?.contentTitle, + targetCountry: null, + articleSize: "news", + projectId: 2, + createdBy: roleId, + clientId: "ngDLPPiorplznw2jTqVe3YFCz5xqKfUJ", + }; + + const res = await generateDataArticle(request); + close(); + + if (res.error) { + console.error(res.message); + return false; + } + + const newArticleId = res?.data?.data?.id; + setIsGeneratedArticle(true); + + setArticleIds((prevIds: string[]) => { + if (prevIds.length < 5) { + return [...prevIds, newArticleId]; + } else { + const updatedIds = [...prevIds]; + updatedIds[4] = newArticleId; + return updatedIds; + } + }); + + Cookies.set("nulisAIArticleIdTemp", JSON.stringify(articleIds)); + setShowRewriteEditor(true); + }; + + const handleArticleIdClick = async (id: string) => { + const res = await getDetailArticle(id); + const articleData = res?.data?.data; + + const cleanArticleBody = articleData?.articleBody?.replace( + /]*>/g, + "" + ); + const articleImagesData = articleData?.imagesUrl?.split(","); + + setArticleBody(cleanArticleBody || ""); + setDetailData(articleData); + setSelectedArticleId(id); + // setArticleImages(articleImagesData || []); + }; + return (
{detail !== undefined ? ( @@ -330,34 +416,109 @@ export default function FormConvertSPIT() {
- -
- - ( - - )} - /> - {errors.contentDescription?.message && ( -

- {errors.contentDescription.message} -

- )} -
-
- +
+ + +
+ +
+
+ + ( + + )} + /> + {errors.contentDescription?.message && ( +

+ {errors.contentDescription.message} +

+ )} +
+
+

+ Content Rewrite +

+
+ {showRewriteEditor && ( +
+ {isGeneratedArticle && ( +
+ {articleIds.map((id: string, index: number) => ( + // +

handleArticleIdClick(id)} + > + {id} +

+ ))} +
+ )} +
+ + +
+
+ + ( + + )} + /> + {errors.contentRewriteDescription?.message && ( +

+ {errors.contentRewriteDescription.message} +

+ )} +
+
+ )} +
+
diff --git a/components/landing-page/navbar.tsx b/components/landing-page/navbar.tsx index 39029e31..5ccec592 100644 --- a/components/landing-page/navbar.tsx +++ b/components/landing-page/navbar.tsx @@ -6,8 +6,23 @@ import { FiFile, FiImage, FiMusic, FiYoutube } from "react-icons/fi"; import { useParams, usePathname, useRouter } from "next/navigation"; import { generateLocalizedPath } from "@/utils/globals"; import { Link } from "@/i18n/routing"; -import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, navigationMenuTriggerStyle } from "@/components/ui/navigation-menu"; -import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "../ui/dropdown-menu"; +import { + NavigationMenu, + NavigationMenuContent, + NavigationMenuItem, + NavigationMenuLink, + NavigationMenuList, + NavigationMenuTrigger, + navigationMenuTriggerStyle, +} from "@/components/ui/navigation-menu"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuGroup, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from "../ui/dropdown-menu"; import Image from "next/image"; import { Icon } from "../ui/icon"; import { getCookiesDecrypt } from "@/lib/utils"; @@ -56,7 +71,7 @@ const Navbar = () => { setLanguage(lang); setIsOpen(false); }; - + useEffect(() => { async function initState() { const response = await getInfoProfile(); @@ -68,25 +83,47 @@ const Navbar = () => { initState(); }, []); - return (
{/* Logo */} - Media Hub Logo + Media Hub Logo {/* Mobile Menu Toggle */} - @@ -99,7 +136,14 @@ const Navbar = () => { - + { - router.push(generateLocalizedPath("/video/filter", String(locale)))} className="flex items-start gap-1.5 p-2 "> + + router.push( + generateLocalizedPath("/video/filter", String(locale)) + ) + } + className="flex items-start gap-1.5 p-2 " + >

Video

- router.push(generateLocalizedPath("/audio/filter", String(locale)))} className="flex place-items-start gap-1.5 p-2 "> + + router.push( + generateLocalizedPath("/audio/filter", String(locale)) + ) + } + className="flex place-items-start gap-1.5 p-2 " + >

Audio

- router.push(generateLocalizedPath("/image/filter", String(locale)))} className="flex place-items-start gap-1.5 p-2"> + + router.push( + generateLocalizedPath("/image/filter", String(locale)) + ) + } + className="flex place-items-start gap-1.5 p-2" + >

Foto

- router.push(generateLocalizedPath("/document/filter", String(locale)))} className="flex place-items-start gap-1.5 p-2"> + + router.push( + generateLocalizedPath( + "/document/filter", + String(locale) + ) + ) + } + className="flex place-items-start gap-1.5 p-2" + >

Teks @@ -139,7 +214,14 @@ const Navbar = () => { - + { - + {

{/* Tombol Utama */} - @@ -199,12 +306,30 @@ const Navbar = () => { {/* Dropdown Menu */} {isOpen && (
- -
@@ -212,9 +337,18 @@ const Navbar = () => {
- + - + {
-
+ {/*
{fullName ? ( <> @@ -267,16 +401,27 @@ const Navbar = () => { {" "} )} -
+
*/} - {/* {roleId === "5" || roleId === "6" || roleId === "7" || roleId === "8" ? ( + {roleId === "5" || + roleId === "6" || + roleId === "7" || + roleId === "8" ? ( {detail !== undefined ? (
- {"Image"} + {"Image"}
-
{detail?.fullname}
+
+ {detail?.fullname} +

({detail?.fullname})

@@ -297,11 +442,15 @@ const Navbar = () => { }, { name: "Kelola Konten", - icon: "heroicons:megaphone", - href: "/dashboard", + icon: "stash:save-ribbon-duotone", + href: "/content-management", }, ].map((item, index) => ( - + {item.name} @@ -313,7 +462,11 @@ const Navbar = () => {
- @@ -322,15 +475,30 @@ const Navbar = () => { - ) : roleId === "2" || roleId === "3" || roleId === "4" || roleId === "9" || roleId === "10" || roleId === "11" || roleId === "12" || roleId === "13" ? ( + ) : roleId === "2" || + roleId === "3" || + roleId === "4" || + roleId === "9" || + roleId === "10" || + roleId === "11" || + roleId === "12" || + roleId === "13" ? ( // Dropdown menu for roleId === 3 {detail !== undefined ? (
- {"Image"} + {"Image"}
-
{detail?.fullname}
+
+ {detail?.fullname} +

({detail?.fullname})

@@ -351,11 +519,15 @@ const Navbar = () => { }, { name: "Dashboard", - icon: "heroicons:megaphone", + icon: "material-symbols:dashboard", href: "/dashboard", }, ].map((item, index) => ( - + {item.name} @@ -367,7 +539,11 @@ const Navbar = () => {
- @@ -379,14 +555,20 @@ const Navbar = () => { ) : ( // Masuk and Daftar buttons for roleId === null
- + Masuk - + Daftar
- )} */} + )}
@@ -398,7 +580,14 @@ const Navbar = () => { - + { - router.push(generateLocalizedPath("/video/filter", String(locale)))} className="flex items-start gap-1.5 p-2 hover:bg-white"> + + router.push( + generateLocalizedPath("/video/filter", String(locale)) + ) + } + className="flex items-start gap-1.5 p-2 hover:bg-white" + >

Video

- router.push(generateLocalizedPath("/audio/filter", String(locale)))} className="flex place-items-start gap-1.5 p-2 hover:bg-white"> + + router.push( + generateLocalizedPath("/audio/filter", String(locale)) + ) + } + className="flex place-items-start gap-1.5 p-2 hover:bg-white" + >

Audio

- router.push(generateLocalizedPath("/image/filter", String(locale)))} className="flex place-items-start gap-1.5 p-2 hover:bg-white"> + + router.push( + generateLocalizedPath("/image/filter", String(locale)) + ) + } + className="flex place-items-start gap-1.5 p-2 hover:bg-white" + >

Foto

- router.push(generateLocalizedPath("/document/filter", String(locale)))} className="flex place-items-start gap-1.5 p-2 hover:bg-white"> + + router.push( + generateLocalizedPath( + "/document/filter", + String(locale) + ) + ) + } + className="flex place-items-start gap-1.5 p-2 hover:bg-white" + >

Teks @@ -438,7 +658,14 @@ const Navbar = () => { - + { - + {

{/* Tombol Utama Bahasa */} - @@ -497,12 +749,30 @@ const Navbar = () => { {/* Dropdown Menu */} {isOpen && (
- -
@@ -511,25 +781,41 @@ const Navbar = () => {
- +
{fullName ? (

{fullName}

) : ( <> - + Masuk - + Daftar {" "} )} - + Masuk - + Daftar
diff --git a/components/partials/header/profile-info.tsx b/components/partials/header/profile-info.tsx index 3c505c78..39e0b666 100644 --- a/components/partials/header/profile-info.tsx +++ b/components/partials/header/profile-info.tsx @@ -71,7 +71,7 @@ const ProfileInfo = () => { {detail !== undefined ? (
{"Image"} { icon: "heroicons:user", href: "/profile", }, - // { - // name: "Billing", - // icon: "heroicons:megaphone", - // href: "/dashboard", - // }, - // { - // name: "Settings", - // icon: "heroicons:paper-airplane", - // href: "/dashboard", - // }, - // { - // name: "Keyboard shortcuts", - // icon: "heroicons:language", - // href: "/dashboard", - // }, ].map((item, index) => ( { ))} - - {/* - - - team - - - - - - Invite user - - - - {[ - { - name: "email", - }, - { - name: "message", - }, - { - name: "facebook", - }, - ].map((item, index) => ( - - - {item.name} - - - ))} - - - - - - - Github - - - - - - - Support - - - - {[ - { - name: "portal", - }, - { - name: "slack", - }, - { - name: "whatsapp", - }, - ].map((item, index) => ( - - - {item.name} - - - ))} - - - */} - +