From 882c77b96fdb50a37a4de646e045b1b8bec19ef2 Mon Sep 17 00:00:00 2001
From: Anang Yusman
Date: Tue, 3 Jun 2025 13:46:06 +0800
Subject: [PATCH] feat:update content-rewrite
---
.../rewrite/create/[id]/page.tsx | 180 +++++++++++++-----
.../content-management/rewrite/page.tsx | 2 +-
service/detail/detail.ts | 10 +-
service/landing/landing.ts | 8 +-
4 files changed, 148 insertions(+), 52 deletions(-)
diff --git a/app/[locale]/(public)/content-management/rewrite/create/[id]/page.tsx b/app/[locale]/(public)/content-management/rewrite/create/[id]/page.tsx
index a982672d..9900b1ba 100644
--- a/app/[locale]/(public)/content-management/rewrite/create/[id]/page.tsx
+++ b/app/[locale]/(public)/content-management/rewrite/create/[id]/page.tsx
@@ -8,12 +8,24 @@ import { useParams, useSearchParams } from "next/navigation";
import React, { useEffect, useState } from "react";
import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content";
-import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "@/components/ui/select";
+import {
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectLabel,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
import { Controller, useForm } from "react-hook-form";
import * as z from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import CustomEditor from "@/components/editor/custom-editor";
-import { generateDataArticle, getDetailArticle } from "@/service/content/ai";
+import {
+ generateDataArticle,
+ generateDataRewrite,
+ getDetailArticle,
+} from "@/service/content/ai";
import { Button } from "@/components/ui/button";
import { close, error, loading } from "@/config/swal";
import { saveContentRewrite } from "@/service/content/content";
@@ -29,8 +41,13 @@ import { useTranslations } from "next-intl";
const imageSchema = z.object({
title: z.string().min(1, { message: "Judul diperlukan" }),
mainKeyword: z.string().min(1, { message: "Keyword diperlukan" }),
- seo: z.string().min(1, { message: "Tuliskan kata kunci atau frasa yang relevan dengan blog Anda, lalu tekan enter" }),
- description: z.string().min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter." }),
+ seo: z.string().min(1, {
+ message:
+ "Tuliskan kata kunci atau frasa yang relevan dengan blog Anda, lalu tekan enter",
+ }),
+ description: z
+ .string()
+ .min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter." }),
creatorName: z.string().min(1, { message: "Creator diperlukan" }),
// tags: z.string().min(1, { message: "Judul diperlukan" }),
});
@@ -73,8 +90,12 @@ const page = (props: any) => {
const validationSchema = Yup.object().shape({
title: Yup.string().required("Judul tidak boleh kosong"),
mainKeyword: Yup.string().required("Keyword tidak boleh kosong"),
- seo: Yup.string().required("Tuliskan kata kunci atau frasa yang relevan dengan blog Anda, lalu tekan enter"),
- description: Yup.string().required("Narasi Penugasan harus lebih dari 2 karakter."),
+ seo: Yup.string().required(
+ "Tuliskan kata kunci atau frasa yang relevan dengan blog Anda, lalu tekan enter"
+ ),
+ description: Yup.string().required(
+ "Narasi Penugasan harus lebih dari 2 karakter."
+ ),
});
let componentMounted = true;
@@ -152,7 +173,10 @@ const page = (props: any) => {
useEffect(() => {
async function initState() {
setLoadingState(true);
- const response = await getDetail(id, states == "polda" ? "polda" : "mabes");
+ const response = await getDetail(
+ id,
+ states == "polda" ? "polda" : "mabes"
+ );
console.log("Detail dataaaa ::", response);
if (response?.data?.data?.isActive == false) {
window.location.replace("/");
@@ -174,7 +198,10 @@ const page = (props: any) => {
setMain({
id: response?.data?.data?.files[0]?.id,
type: response?.data?.data?.fileType.name,
- url: Number(response?.data?.data?.fileType?.id) == 4 ? response?.data?.data?.files[0]?.secondaryUrl : response?.data?.data?.files[0]?.url,
+ url:
+ Number(response?.data?.data?.fileType?.id) == 4
+ ? response?.data?.data?.files[0]?.secondaryUrl
+ : response?.data?.data?.files[0]?.url,
thumbnailFileUrl: response?.data?.data?.files[0]?.thumbnailFileUrl,
names: response?.data?.data?.files[0]?.fileName,
format: response?.data?.data?.files[0]?.format,
@@ -208,25 +235,17 @@ const page = (props: any) => {
const handleGenerateArtikel = async () => {
loading();
const request = {
- advConfig: "",
- style: selectedWritingStyle,
- website: "None",
- connectToWeb: true,
- lang: selectedLanguage,
- pointOfView: "None",
- title: getValues("title"),
- imageSource: "Web",
- mainKeyword: getValues("mainKeyword"),
- additionalKeywords: getValues("seo"),
- targetCountry: null,
- articleSize: selectedSize,
- projectId: 2,
+ style: "friendly",
+ lang: "id",
+ contextType: "text",
+ urlContext: null,
+ context: content?.description,
createdBy: roleId,
- // clientId: "ngDLPPiorplznw2jTqVe3YFCz5xqKfUJ",
- clientId: "mediahubClientId",
+ sentiment: "Humorous",
+ clientId: "7QTW8cMojyayt6qnhqTOeJaBI70W4EaQ",
};
console.log("Request", request);
- const res = await generateDataArticle(request);
+ const res = await generateDataRewrite(request);
close();
if (res.error) {
@@ -272,7 +291,10 @@ const page = (props: any) => {
throw new Error("Timeout: Artikel belum selesai diproses.");
};
const articleData = await waitForStatusUpdate();
- const cleanArticleBody = articleData?.articleBody?.replace(/
]*>/g, "");
+ const cleanArticleBody = articleData?.articleBody?.replace(
+ /
]*>/g,
+ ""
+ );
console.log("lalalala", cleanArticleBody);
const articleImagesData = articleData?.imagesUrl?.split(",");
setValue("description", cleanArticleBody || "");
@@ -302,7 +324,10 @@ const page = (props: any) => {
{t("language")}
-
{t("contextType")}
-
+
@@ -325,8 +353,12 @@ const page = (props: any) => {
{t("selectContext")}
{t("text")}
- {t("article")}
- {t("transcript")}
+
+ {t("article")}
+
+
+ {t("transcript")}
+
URL
@@ -334,7 +366,10 @@ const page = (props: any) => {
{t("writingStyle")}
-
+
@@ -342,8 +377,12 @@ const page = (props: any) => {
{t("selectWriting")}
Friendly
- Profesional
- Informational
+
+ Profesional
+
+
+ Informational
+
Neutral
Witty
@@ -352,16 +391,25 @@ const page = (props: any) => {
@@ -381,7 +440,16 @@ const page = (props: any) => {
control={control}
name="mainKeyword"
render={({ field: { onChange, value } }) => (
-
+
)}
/>
@@ -391,12 +459,22 @@ const page = (props: any) => {
control={control}
name="seo"
render={({ field: { onChange, value } }) => (
-
+
)}
/>
-
+
Generate Artikel
{isGeneratedArticle && (
@@ -426,14 +504,25 @@ const page = (props: any) => {
render={({ field: { onChange, value } }) =>
isLoadingData ? (
-
Loading Proses Data...
+
+ Loading Proses Data...
+
) : (
-
+
)
}
/>
- {articleBody === null || articleBody === "" ?
Deskripsi tidak boleh kosong*
: ""}
+ {articleBody === null || articleBody === "" ? (
+
+ Deskripsi tidak boleh kosong*
+
+ ) : (
+ ""
+ )}
-
diff --git a/app/[locale]/(public)/content-management/rewrite/page.tsx b/app/[locale]/(public)/content-management/rewrite/page.tsx
index 6a1b1d9d..660d10a1 100644
--- a/app/[locale]/(public)/content-management/rewrite/page.tsx
+++ b/app/[locale]/(public)/content-management/rewrite/page.tsx
@@ -283,7 +283,7 @@ const page = () => {
diff --git a/service/detail/detail.ts b/service/detail/detail.ts
index 7d3db8e3..d23b1014 100644
--- a/service/detail/detail.ts
+++ b/service/detail/detail.ts
@@ -1,6 +1,10 @@
-import { httpDeleteInterceptor, httpGetInterceptor, httpPostInterceptor } from "../http-config/http-interceptor-service";
+import {
+ httpDeleteInterceptor,
+ httpGetInterceptor,
+ httpPostInterceptor,
+} from "../http-config/http-interceptor-service";
-export async function getDetail(id: any, state: any) {
- const url = `media/public?slug=${id}&state=${state}`;
+export async function getDetail(slug: any, state: any) {
+ const url = `media/public?slug=${slug}&state=${state}`;
return httpGetInterceptor(url);
}
diff --git a/service/landing/landing.ts b/service/landing/landing.ts
index ffdcc2d4..51876f78 100644
--- a/service/landing/landing.ts
+++ b/service/landing/landing.ts
@@ -228,10 +228,10 @@ export async function saveWishlist(data: { mediaUploadId: string }) {
export async function getPublicSuggestionList(slug: any) {
const url = `media/public/suggestion?mediaId=${slug}`;
- const headers = {
- "content-Type": "application/json",
- };
- return httpGet(url, headers);
+ // const headers = {
+ // "content-Type": "application/json",
+ // };
+ return httpGetInterceptor(url);
}
export async function getUserNotifications(page = 0, typeId: any) {