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 ( return (
<div> <div>
<SiteBreadcrumb /> <SiteBreadcrumb />
<ContentBlast type="email" /> <ContentBlast />
</div> </div>
); );
} }

View File

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

View File

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

View File

@ -50,9 +50,6 @@ const CustomEditor = dynamic(
const animatedComponent = makeAnimated(); const animatedComponent = makeAnimated();
// -------------------------
// ZOD SCHEMA (baru)
// -------------------------
const FormSchema = z.object({ const FormSchema = z.object({
selected: z selected: z
.array( .array(
@ -79,7 +76,7 @@ interface Campaign {
name: string; name: string;
} }
export default function ContentBlast(props: { type: string }) { export default function ContentBlast() {
const editor = useRef(null); const editor = useRef(null);
const id = useParams()?.id; const id = useParams()?.id;
const MySwal = withReactContent(Swal); const MySwal = withReactContent(Swal);
@ -93,7 +90,7 @@ export default function ContentBlast(props: { type: string }) {
defaultValues: { defaultValues: {
selected: [], selected: [],
detail: "", detail: "",
messageType: [], // checkbox messageType: [],
}, },
}); });
@ -113,23 +110,43 @@ export default function ContentBlast(props: { type: string }) {
}); });
}; };
// ------------------------- function htmlToWaText(html: string) {
// SAVE LOGIC (baru) // 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 save = async (data: z.infer<typeof FormSchema>) => {
const selectedCampaign = data.selected; const selectedCampaign = data.selected;
const mediaRes = await detailMediaSummary(String(id));
const details = mediaRes?.data?.data;
for (let i = 0; i < selectedCampaign.length; i++) { for (let i = 0; i < selectedCampaign.length; i++) {
const campaignId = selectedCampaign[i].id; const campaignId = selectedCampaign[i].id;
// Loop WA / Email
for (let mt of data.messageType) { for (let mt of data.messageType) {
let finalBody = data.detail;
if (mt === "wa") {
finalBody = textEllipsis(details?.description || "", 150);
}
const payload = { const payload = {
mediaUploadId: id, mediaUploadId: id,
mediaBlastCampaignId: campaignId, mediaBlastCampaignId: campaignId,
subject: mt === "wa" ? `*${data.title}*` : data.title, subject: mt === "wa" ? `*${data.title}*` : data.title,
body: data.detail.replace(/\n/g, ""), body: mt === "wa" ? htmlToWaText(finalBody) : finalBody,
type: mt, // <-- WA / email type: mt,
isScheduled: false, isScheduled: false,
thumbnail: data.thumbnail, thumbnail: data.thumbnail,
sendDate: getLocaleTimestamp(new Date()), sendDate: getLocaleTimestamp(new Date()),
@ -145,6 +162,36 @@ export default function ContentBlast(props: { type: string }) {
setOpenModal(true); 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(() => { useEffect(() => {
async function init() { async function init() {
const response = await detailMediaSummary(String(id)); const response = await detailMediaSummary(String(id));

View File

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

View File

@ -247,7 +247,19 @@ const DetailDocument = () => {
if (xhr.readyState === 4 && xhr.status === 200) { if (xhr.readyState === 4 && xhr.status === 200) {
const contentType = const contentType =
xhr.getResponseHeader("content-type") || "application/octet-stream"; 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 filename = `${name}.${extension}`;
const blob = new Blob([xhr.response], { const blob = new Blob([xhr.response], {

View File

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