fix: wa blast and excel

This commit is contained in:
Sabda Yagra 2025-11-26 21:39:02 +07:00
commit 3f8d494a3d
7 changed files with 104 additions and 46 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 type="wa" /> */}
</div>
);
}

View File

@ -381,7 +381,7 @@ export default function ExecutiveDashboard() {
</div>
</Card>
</div>
<div className="w-full mt-3">
{/* <div className="w-full mt-3">
<Card className="rounded-sm p-3 h-auto">
<div className="flex flex-row justify-between">
<p className="text-base font-semibold">Emergency Issue</p>
@ -407,7 +407,7 @@ export default function ExecutiveDashboard() {
</div>
</div>
</Card>
</div>
</div> */}
</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

@ -253,11 +253,10 @@ const DetailAudio = () => {
extension = "mp3";
}
if (selectedSize === "WAV") {
if (selectedSize === "WAV") {
extension = "wav";
}
const filename = `${name}.${extension}`;
const blob = new Blob([xhr.response], {

View File

@ -247,7 +247,19 @@ const DetailDocument = () => {
if (xhr.readyState === 4 && xhr.status === 200) {
const contentType =
xhr.getResponseHeader("content-type") || "application/octet-stream";
const extension = contentType.split("/")[1];
let extension = contentType.split("/")[1];
if (selectedSize === "DOC") {
extension = "doc";
}
if (selectedSize === "PPT") {
extension = "ppt";
}
if (selectedSize === "PDF") {
extension = "pdf";
}
const filename = `${name}.${extension}`;
const blob = new Blob([xhr.response], {

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",