fix: adjust code from prod

This commit is contained in:
Sabda Yagra 2025-11-27 08:25:28 +07:00
parent 3349450cb9
commit 3698996c0c
4 changed files with 88 additions and 41 deletions

View File

@ -5,7 +5,7 @@ export default function CreateEmailBlast() {
return (
<div>
<SiteBreadcrumb />
<ContentBlast type="email" />
<ContentBlast />
</div>
);
}

View File

@ -5,7 +5,7 @@ export default function CreateWABlast() {
return (
<div>
<SiteBreadcrumb />
<ContentBlast type="wa" />
{/* <ContentBlast /> */}
</div>
);
}

View File

@ -50,9 +50,6 @@ const CustomEditor = dynamic(
const animatedComponent = makeAnimated();
// -------------------------
// ZOD SCHEMA (baru)
// -------------------------
const FormSchema = z.object({
selected: z
.array(
@ -79,7 +76,7 @@ interface Campaign {
name: string;
}
export default function ContentBlast(props: { type: string }) {
export default function ContentBlast() {
const editor = useRef(null);
const id = useParams()?.id;
const MySwal = withReactContent(Swal);
@ -93,7 +90,7 @@ export default function ContentBlast(props: { type: string }) {
defaultValues: {
selected: [],
detail: "",
messageType: [], // checkbox
messageType: [],
},
});
@ -113,23 +110,43 @@ export default function ContentBlast(props: { type: string }) {
});
};
// -------------------------
// SAVE LOGIC (baru)
// -------------------------
function htmlToWaText(html: string) {
// Hilangkan link menjadi URL saja
html = html.replace(/<a [^>]*href="([^"]+)"[^>]*>(.*?)<\/a>/gi, "$1");
// Ambil gambar sebagai URL
html = html.replace(/<img [^>]*src="([^"]+)".*?>/gi, "$1");
// Hapus semua HTML tag
html = html.replace(/<\/?[^>]+>/gi, "");
// Decode HTML entities
html = html.replace(/&amp;/g, "&");
// Rapikan spasi
return html.replace(/\s+/g, " ").trim();
}
const save = async (data: z.infer<typeof FormSchema>) => {
const selectedCampaign = data.selected;
const mediaRes = await detailMediaSummary(String(id));
const details = mediaRes?.data?.data;
for (let i = 0; i < selectedCampaign.length; i++) {
const campaignId = selectedCampaign[i].id;
// Loop WA / Email
for (let mt of data.messageType) {
let finalBody = data.detail;
if (mt === "wa") {
finalBody = textEllipsis(details?.description || "", 150);
}
const payload = {
mediaUploadId: id,
mediaBlastCampaignId: campaignId,
subject: mt === "wa" ? `*${data.title}*` : data.title,
body: data.detail.replace(/\n/g, ""),
type: mt, // <-- WA / email
body: mt === "wa" ? htmlToWaText(finalBody) : finalBody,
type: mt,
isScheduled: false,
thumbnail: data.thumbnail,
sendDate: getLocaleTimestamp(new Date()),
@ -145,6 +162,36 @@ export default function ContentBlast(props: { type: string }) {
setOpenModal(true);
};
// const save = async (data: z.infer<typeof FormSchema>) => {
// const selectedCampaign = data.selected;
// for (let i = 0; i < selectedCampaign.length; i++) {
// const campaignId = selectedCampaign[i].id;
// // Loop WA / Email
// for (let mt of data.messageType) {
// const payload = {
// mediaUploadId: id,
// mediaBlastCampaignId: campaignId,
// subject: mt === "wa" ? `*${data.title}*` : data.title,
// // body: data.detail.replace(/\n/g, ""),
// body: mt === "wa" ? htmlToWaText(data.detail) : data.detail,
// type: mt, // <-- WA / email
// isScheduled: false,
// thumbnail: data.thumbnail,
// sendDate: getLocaleTimestamp(new Date()),
// sendTime: getLocaleTime(new Date()),
// contentUrl: data.url,
// };
// console.log("REQ =>", payload);
// await saveMediaBlastBroadcast(payload);
// }
// }
// setOpenModal(true);
// };
useEffect(() => {
async function init() {
const response = await detailMediaSummary(String(id));

View File

@ -4190,20 +4190,20 @@ export function getMenuList(pathname: string, t: any): Group[] {
},
],
},
{
groupLabel: "",
id: "management-user",
menus: [
{
id: "management-user-menu",
href: "/admin/management-user",
label: "Management User",
active: pathname.includes("/management-user"),
icon: "clarity:users-solid",
submenus: [],
},
],
},
// {
// groupLabel: "",
// id: "management-user",
// menus: [
// {
// id: "management-user-menu",
// href: "/admin/management-user",
// label: "Management User",
// active: pathname.includes("/management-user"),
// icon: "clarity:users-solid",
// submenus: [],
// },
// ],
// },
{
groupLabel: "",
id: "content-production",
@ -4289,20 +4289,20 @@ export function getMenuList(pathname: string, t: any): Group[] {
},
],
},
{
groupLabel: "",
id: "experts",
menus: [
{
id: "experts",
href: "/admin/add-experts",
label: t("add-experts"),
active: pathname.includes("/add-experts"),
icon: "majesticons:user",
submenus: [],
},
],
},
// {
// groupLabel: "",
// id: "experts",
// menus: [
// {
// id: "experts",
// href: "/admin/add-experts",
// label: t("add-experts"),
// active: pathname.includes("/add-experts"),
// icon: "majesticons:user",
// submenus: [],
// },
// ],
// },
{
groupLabel: "",
id: "settings",