diff --git a/package-lock.json b/package-lock.json
index 222a993..29bb911 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -59,7 +59,8 @@
"tailwind-variants": "^0.1.18",
"tailwindcss": "3.3.5",
"typescript": "5.0.4",
- "zod": "^3.23.8"
+ "zod": "^3.23.8",
+ "zustand": "^5.0.1"
}
},
"node_modules/@aashutoshrathi/word-wrap": {
@@ -7290,6 +7291,34 @@
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
+ },
+ "node_modules/zustand": {
+ "version": "5.0.1",
+ "resolved": "https://registry.npmjs.org/zustand/-/zustand-5.0.1.tgz",
+ "integrity": "sha512-pRET7Lao2z+n5R/HduXMio35TncTlSW68WsYBq2Lg1ASspsNGjpwLAsij3RpouyV6+kHMwwwzP0bZPD70/Jx/w==",
+ "engines": {
+ "node": ">=12.20.0"
+ },
+ "peerDependencies": {
+ "@types/react": ">=18.0.0",
+ "immer": ">=9.0.6",
+ "react": ">=18.0.0",
+ "use-sync-external-store": ">=1.2.0"
+ },
+ "peerDependenciesMeta": {
+ "@types/react": {
+ "optional": true
+ },
+ "immer": {
+ "optional": true
+ },
+ "react": {
+ "optional": true
+ },
+ "use-sync-external-store": {
+ "optional": true
+ }
+ }
}
}
}
diff --git a/package.json b/package.json
index 324c49e..0e521e9 100644
--- a/package.json
+++ b/package.json
@@ -60,6 +60,7 @@
"tailwind-variants": "^0.1.18",
"tailwindcss": "3.3.5",
"typescript": "5.0.4",
- "zod": "^3.23.8"
+ "zod": "^3.23.8",
+ "zustand": "^5.0.1"
}
}
diff --git a/service/generate-article.ts b/service/generate-article.ts
new file mode 100644
index 0000000..9d9bbda
--- /dev/null
+++ b/service/generate-article.ts
@@ -0,0 +1,190 @@
+import { httpGet, httpPost } from "@/services/http-config/disestages-services";
+
+interface GenerateKeywordsAndTitleRequestData {
+ keyword: string;
+ style: string;
+ website: string;
+ connectToWeb: boolean;
+ lang: string;
+ pointOfView: string;
+ clientId: string;
+}
+
+interface GenerateArticleRequest {
+ advConfig: string;
+ style: string;
+ website: string;
+ connectToWeb: boolean;
+ lang: string;
+ pointOfView: string;
+ title: string;
+ imageSource: string;
+ mainKeyword: string;
+ additionalKeywords: string;
+ targetCountry: null;
+ articleSize: string;
+ projectId: number;
+ createdBy: string;
+ clientId: string;
+}
+
+type BulkArticleRequest = {
+ style: string;
+ website: string;
+ connectToWeb: boolean;
+ lang: string;
+ pointOfView: string;
+ imageSource: string;
+ targetCountry: null;
+ articleSize: string;
+ projectId: number;
+ data: { title: string; mainKeyword: string; additionalKeywords: string }[];
+ createdBy: string;
+ clientId: string;
+};
+
+interface ContentRewriteRequest {
+ advConfig: string;
+ context: string | null;
+ style: string;
+ sentiment: string;
+ clientId: string;
+ createdBy: string;
+ contextType: string;
+ urlContext: string | null;
+ lang: string;
+}
+
+export type ContentBankRequest = {
+ query: string;
+ page: number;
+ userId: string;
+ limit: number;
+ status: number[];
+ isSingle: boolean;
+ createdBy: string;
+ sort: { column: string; sort: string }[];
+};
+
+export async function getGenerateTitle(
+ data: GenerateKeywordsAndTitleRequestData
+) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/generate-title", headers, data);
+}
+
+export async function getGenerateKeywords(
+ data: GenerateKeywordsAndTitleRequestData
+) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/generate-keywords", headers, data);
+}
+
+export async function generateDataArticle(data: GenerateArticleRequest) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/save-article", headers, data);
+}
+
+export async function approveArticle(props: { id: number[] }) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/approve-article", headers, props);
+}
+export async function rejectArticle(props: { id: number[] }) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/reject-article", headers, props);
+}
+
+export async function getGenerateTopicKeywords(data: {
+ keyword: string;
+ count: number;
+}) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/generate-topic-keywords", headers, data);
+}
+
+export async function saveBulkArticle(data: BulkArticleRequest) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/save-bulk-article", headers, data);
+}
+
+export async function getDetailArticle(id: number) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpGet(`ai-writer/article/findArticleById/${id}`, headers);
+}
+
+export async function generateSpeechToText(data: any) {
+ const headers = {
+ "content-type": "multipart/form-data",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/speech-to-text", headers, data);
+}
+
+export async function getTranscriptById(id: number) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpGet(`ai-writer/speech-to-text/findById/${id}`, headers);
+}
+
+export async function getGenerateRewriter(data: ContentRewriteRequest) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/create-rewriter", headers, data);
+}
+
+export async function getListTranscript(data: any) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/speech-to-text/datatable", headers, data);
+}
+
+export async function getListArticleDraft(data: ContentBankRequest) {
+ const headers = {
+ "content-type": "application/json",
+ Authorization:
+ "Basic bmdETFBQaW9ycGx6bncyalRxVmUzWUZDejV4cUtmVUo6UHJEaERXUmNvdkJSNlc1Sg==",
+ };
+ return await httpPost("ai-writer/article/datatable", headers, data);
+}
diff --git a/services/http-config/disestages-instance.ts b/services/http-config/disestages-instance.ts
new file mode 100644
index 0000000..ffbac6f
--- /dev/null
+++ b/services/http-config/disestages-instance.ts
@@ -0,0 +1,12 @@
+import axios from "axios";
+
+const baseURL = "https://disestages.com/api";
+
+const axiosDisestagesInstance = axios.create({
+ baseURL,
+ headers: {
+ "content-type": "application/json",
+ },
+});
+
+export default axiosDisestagesInstance;
diff --git a/services/http-config/disestages-services.ts b/services/http-config/disestages-services.ts
new file mode 100644
index 0000000..cf07e03
--- /dev/null
+++ b/services/http-config/disestages-services.ts
@@ -0,0 +1,47 @@
+import axiosDisestagesInstance from "./disestages-instance";
+
+export async function httpPost(pathUrl: any, headers: any, data?: any) {
+ const response = await axiosDisestagesInstance
+ .post(pathUrl, data, { headers })
+ .catch(function (error) {
+ console.log(error);
+ return error.response;
+ });
+ console.log("Response base svc : ", response);
+ if (response?.status == 200 || response?.status == 201) {
+ return {
+ error: false,
+ message: "success",
+ data: response?.data,
+ };
+ } else {
+ return {
+ error: true,
+ message: response?.data?.message || response?.data || null,
+ data: null,
+ };
+ }
+}
+
+export async function httpGet(pathUrl: any, headers: any) {
+ const response = await axiosDisestagesInstance
+ .get(pathUrl, { headers })
+ .catch(function (error) {
+ console.log(error);
+ return error.response;
+ });
+ console.log("Response base svc : ", response);
+ if (response?.status == 200 || response?.status == 201) {
+ return {
+ error: false,
+ message: "success",
+ data: response?.data,
+ };
+ } else {
+ return {
+ error: true,
+ message: response?.data?.message || response?.data || null,
+ data: null,
+ };
+ }
+}
diff --git a/store/generated-article-store.tsx b/store/generated-article-store.tsx
new file mode 100644
index 0000000..c033a84
--- /dev/null
+++ b/store/generated-article-store.tsx
@@ -0,0 +1,32 @@
+import { create } from "zustand";
+
+interface targetStore {
+ articleIds: { singleArticle: number[]; bulkArticle: number[] };
+ setArticleIds: (newTarget: {
+ singleArticle: number[];
+ bulkArticle: number[];
+ }) => void;
+}
+
+const getInitialTarget = () => {
+ if (typeof localStorage !== "undefined") {
+ const stored = localStorage.getItem("generated-article");
+ const initial = stored
+ ? JSON.parse(stored)
+ : { singleArticle: [], bulkArticle: [] };
+ return initial;
+ }
+};
+
+const generatedArticleIds = create((set) => ({
+ articleIds: getInitialTarget(),
+ setArticleIds: (newTarget: {
+ singleArticle: number[];
+ bulkArticle: number[];
+ }) => {
+ localStorage.setItem("generated-article", JSON.stringify(newTarget));
+ set({ articleIds: newTarget });
+ },
+}));
+
+export default generatedArticleIds;
diff --git a/utils/global.tsx b/utils/global.tsx
index 289a819..529d242 100644
--- a/utils/global.tsx
+++ b/utils/global.tsx
@@ -70,3 +70,25 @@ const LoadScript = () => {
};
export default LoadScript;
+
+export function delay(ms: number) {
+ return new Promise((resolve) => setTimeout(resolve, ms));
+}
+
+export function textEllipsis(
+ str: string,
+ maxLength: number,
+ { side = "end", ellipsis = "..." } = {}
+) {
+ if (str !== undefined && str?.length > maxLength) {
+ switch (side) {
+ case "start":
+ return ellipsis + str.slice(-(maxLength - ellipsis.length));
+
+ case "end":
+ default:
+ return str.slice(0, maxLength - ellipsis.length) + ellipsis;
+ }
+ }
+ return str;
+}