Email System Fixes: - Fix email sending after payment: handle-order-paid now calls send-notification instead of send-email-v2 directly, properly processing template variables - Fix order_created email timing: sent immediately after order creation, before payment QR code generation - Update email templates to use short order ID (8 chars) instead of full UUID - Add working "Akses Sekarang" buttons to payment_success and access_granted emails - Add platform_url column to platform_settings for email links OTP Verification Flow: - Create dedicated /confirm-otp page for users who close registration modal - Add link in checkout modal and email to dedicated OTP page - Update OTP email template with better copywriting and dedicated page link - Fix send-auth-otp to fetch platform settings for dynamic brand_name and platform_url - Auto-login users after OTP verification in checkout flow Admin Features: - Add delete user functionality with cascade deletion of all related data - Update IntegrasiTab to read/write email settings from platform_settings only - Add test email template for email configuration testing Cleanup: - Remove obsolete send-consultation-reminder and send-test-email functions - Update send-email-v2 to read email config from platform_settings - Remove footer links (Ubah Preferensi/Unsubscribe) from email templates 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
390 lines
13 KiB
TypeScript
390 lines
13 KiB
TypeScript
interface EmailTemplateData {
|
|
subject: string;
|
|
content: string;
|
|
brandName?: string;
|
|
brandLogo?: string;
|
|
}
|
|
|
|
export class EmailTemplateRenderer {
|
|
private static readonly MASTER_TEMPLATE = `
|
|
<!DOCTYPE html>
|
|
<html lang="id">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>{{subject}}</title>
|
|
<style>
|
|
body, table, td, a { -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
|
|
table, td { mso-table-lspace: 0pt; mso-table-rspace: 0pt; }
|
|
img { -ms-interpolation-mode: bicubic; border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; }
|
|
table { border-collapse: collapse !important; }
|
|
body { height: 100% !important; margin: 0 !important; padding: 0 !important; width: 100% !important; background-color: #FFFFFF; }
|
|
|
|
:root {
|
|
--color-black: #000000;
|
|
--color-white: #FFFFFF;
|
|
--color-gray: #F4F4F5;
|
|
--color-success: #00A651;
|
|
--color-danger: #E11D48;
|
|
--border-thick: 2px solid #000000;
|
|
--border-thin: 1px solid #000000;
|
|
--shadow-hard: 4px 4px 0px 0px #000000;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
color: #000000;
|
|
-webkit-font-smoothing: antialiased;
|
|
}
|
|
|
|
.tiptap-content h1 {
|
|
font-size: 28px;
|
|
font-weight: 800;
|
|
margin: 0 0 20px 0;
|
|
letter-spacing: -1px;
|
|
line-height: 1.1;
|
|
}
|
|
.tiptap-content h2 {
|
|
font-size: 20px;
|
|
font-weight: 700;
|
|
margin: 25px 0 15px 0;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
border-bottom: 2px solid #000;
|
|
padding-bottom: 5px;
|
|
display: inline-block;
|
|
}
|
|
.tiptap-content h3 {
|
|
font-size: 18px;
|
|
font-weight: 700;
|
|
margin: 20px 0 10px 0;
|
|
color: #333;
|
|
}
|
|
.tiptap-content p {
|
|
font-size: 16px;
|
|
line-height: 1.6;
|
|
margin: 0 0 20px 0;
|
|
color: #333;
|
|
}
|
|
|
|
.tiptap-content a {
|
|
color: #000000;
|
|
text-decoration: underline;
|
|
font-weight: 700;
|
|
text-underline-offset: 3px;
|
|
}
|
|
|
|
.tiptap-content ul, .tiptap-content ol {
|
|
margin: 0 0 20px 0;
|
|
padding-left: 20px;
|
|
}
|
|
.tiptap-content li {
|
|
margin-bottom: 8px;
|
|
font-size: 16px;
|
|
padding-left: 5px;
|
|
}
|
|
|
|
.tiptap-content table {
|
|
width: 100%;
|
|
border: 2px solid #000;
|
|
margin-bottom: 25px;
|
|
border-collapse: collapse;
|
|
}
|
|
.tiptap-content th {
|
|
background-color: #000;
|
|
color: #FFF;
|
|
padding: 12px;
|
|
text-align: left;
|
|
font-size: 14px;
|
|
text-transform: uppercase;
|
|
font-weight: 700;
|
|
border: 1px solid #000;
|
|
}
|
|
.tiptap-content td {
|
|
padding: 12px;
|
|
border: 1px solid #000;
|
|
font-size: 15px;
|
|
vertical-align: top;
|
|
}
|
|
.tiptap-content tr:nth-child(even) td {
|
|
background-color: #F8F8F8;
|
|
}
|
|
|
|
.btn {
|
|
display: inline-block;
|
|
background-color: #000;
|
|
color: #FFF !important;
|
|
padding: 14px 28px;
|
|
font-weight: 700;
|
|
text-transform: uppercase;
|
|
text-decoration: none !important;
|
|
font-size: 16px;
|
|
border: 2px solid #000;
|
|
box-shadow: 4px 4px 0px 0px #000000;
|
|
margin: 10px 0;
|
|
transition: all 0.1s;
|
|
}
|
|
.btn:hover {
|
|
transform: translate(2px, 2px);
|
|
box-shadow: 2px 2px 0px 0px #000000;
|
|
}
|
|
|
|
.tiptap-content pre {
|
|
background-color: #F4F4F5;
|
|
border: 2px solid #000;
|
|
padding: 15px;
|
|
overflow-x: auto;
|
|
margin-bottom: 20px;
|
|
}
|
|
.tiptap-content code {
|
|
font-family: 'Courier New', Courier, monospace;
|
|
font-size: 14px;
|
|
color: #E11D48;
|
|
background-color: #F4F4F5;
|
|
padding: 2px 4px;
|
|
}
|
|
|
|
.otp-box {
|
|
background-color: #F4F4F5;
|
|
border: 2px dashed #000;
|
|
padding: 20px;
|
|
text-align: center;
|
|
margin: 20px 0;
|
|
letter-spacing: 5px;
|
|
font-family: 'Courier New', Courier, monospace;
|
|
font-size: 32px;
|
|
font-weight: 700;
|
|
color: #000;
|
|
}
|
|
|
|
.tiptap-content blockquote {
|
|
margin: 0 0 20px 0;
|
|
padding: 15px 20px;
|
|
border-left: 6px solid #000;
|
|
background-color: #F9F9F9;
|
|
font-style: italic;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.alert-success { background-color: #E6F4EA; border-left-color: #00A651; color: #005A2B; }
|
|
.alert-danger { background-color: #FFE4E6; border-left-color: #E11D48; color: #881337; }
|
|
.alert-info { background-color: #E3F2FD; border-left-color: #1976D2; color: #0D47A1; }
|
|
|
|
@media screen and (max-width: 600px) {
|
|
.email-container { width: 100% !important; border-left: 0 !important; border-right: 0 !important; }
|
|
.content-padding { padding: 30px 20px !important; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body style="margin: 0; padding: 0; background-color: #FFFFFF;">
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: #FFFFFF;">
|
|
<tr>
|
|
<td align="center" style="padding: 40px 0;">
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="600" class="email-container" style="background-color: #FFFFFF; border: 2px solid #000000; width: 600px; min-width: 320px;">
|
|
|
|
<tr>
|
|
<td align="left" style="background-color: #000000; padding: 25px 40px; border-bottom: 2px solid #000000;">
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr>
|
|
<td align="left">
|
|
<div style="font-family: 'Helvetica Neue', sans-serif; font-size: 24px; font-weight: 900; color: #FFFFFF; letter-spacing: -1px; text-transform: uppercase;">
|
|
{{brandName}}
|
|
</div>
|
|
</td>
|
|
<td align="right">
|
|
<div style="font-family: monospace; font-size: 12px; color: #888;">
|
|
NOTIF #{{timestamp}}
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="content-padding" style="padding: 40px 40px 60px 40px;">
|
|
<!-- DYNAMIC CONTENT WRAPPER (.tiptap-content) -->
|
|
<div class="tiptap-content">
|
|
{{content}}
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td style="padding: 30px 40px; border-top: 2px solid #000000; background-color: #F4F4F5; color: #000;">
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr>
|
|
<td align="left" style="font-size: 12px; line-height: 18px; font-family: monospace; color: #555;">
|
|
<p style="margin: 0 0 10px 0; font-weight: bold;">{{brandName}}</p>
|
|
<p style="margin: 0;">Email ini dikirim otomatis. Jangan membalas email ini.</p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
</body>
|
|
</html>
|
|
`;
|
|
|
|
static render(data: EmailTemplateData): string {
|
|
let html = this.MASTER_TEMPLATE;
|
|
|
|
html = html.replace(/{{subject}}/g, data.subject || 'Notification');
|
|
html = html.replace(/{{brandName}}/g, data.brandName || 'ACCESS HUB');
|
|
html = html.replace(/{{brandLogo}}/g, data.brandLogo || '');
|
|
html = html.replace(/{{timestamp}}/g, Date.now().toString().slice(-6));
|
|
html = html.replace(/{{content}}/g, data.content);
|
|
|
|
return html;
|
|
}
|
|
}
|
|
|
|
// Reusable Email Components
|
|
export const EmailComponents = {
|
|
// Buttons
|
|
button: (text: string, url: string, fullwidth = false) =>
|
|
`<p style="margin-top: 20px; text-align: ${fullwidth ? 'center' : 'left'};">
|
|
<a href="${url}" class="${fullwidth ? 'btn-full' : 'btn'}">${text}</a>
|
|
</p>`,
|
|
|
|
// Alert boxes
|
|
alert: (type: 'success' | 'danger' | 'info', content: string) =>
|
|
`<blockquote class="alert-${type}">
|
|
${content}
|
|
</blockquote>`,
|
|
|
|
// Code blocks
|
|
codeBlock: (code: string, language = '') =>
|
|
`<pre><code>${code}</code></pre>`,
|
|
|
|
// OTP boxes
|
|
otpBox: (code: string) =>
|
|
`<div class="otp-box">${code}</div>`,
|
|
|
|
// Info card
|
|
infoCard: (title: string, items: Array<{label: string; value: string}>) => {
|
|
const rows = items.map(item =>
|
|
`<tr>
|
|
<td>${item.label}</td>
|
|
<td>${item.value}</td>
|
|
</tr>`
|
|
).join('');
|
|
|
|
return `
|
|
<h2>${title}</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Parameter</th>
|
|
<th>Value</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
${rows}
|
|
</tbody>
|
|
</table>
|
|
`;
|
|
},
|
|
|
|
// Divider
|
|
divider: () => '<hr style="border: 1px solid #000; margin: 30px 0;">',
|
|
|
|
// Spacing
|
|
spacing: (size: 'small' | 'medium' | 'large' = 'medium') => {
|
|
const sizes = { small: '15px', medium: '25px', large: '40px' };
|
|
return `<div style="height: ${sizes[size]};"></div>`;
|
|
}
|
|
};
|
|
|
|
// Shortcode processor
|
|
export class ShortcodeProcessor {
|
|
private static readonly DEFAULT_DATA = {
|
|
// User information
|
|
nama: 'John Doe',
|
|
email: 'john@example.com',
|
|
|
|
// Order information
|
|
order_id: 'ORD-123456',
|
|
tanggal_pesanan: '22 Desember 2025',
|
|
total: 'Rp 1.500.000',
|
|
metode_pembayaran: 'Transfer Bank',
|
|
status_pesanan: 'Diproses',
|
|
invoice_url: 'https://with.dwindi.com/orders/ORD-123456',
|
|
|
|
// Product information
|
|
produk: 'Digital Marketing Masterclass',
|
|
kategori_produk: 'Digital Marketing',
|
|
harga_produk: 'Rp 1.500.000',
|
|
deskripsi_produk: 'Kelas lengkap digital marketing dari pemula hingga mahir',
|
|
|
|
// Access information
|
|
link_akses: 'https://with.dwindi.com/access',
|
|
username_akses: 'john.doe',
|
|
password_akses: 'Temp123!',
|
|
kadaluarsa_akses: '22 Desember 2026',
|
|
|
|
// Consulting information
|
|
tanggal_konsultasi: '22 Desember 2025',
|
|
jam_konsultasi: '14:00',
|
|
durasi_konsultasi: '60 menit',
|
|
link_meet: 'https://meet.google.com/example',
|
|
jenis_konsultasi: 'Digital Marketing Strategy',
|
|
topik_konsultasi: 'Social Media Marketing for Beginners',
|
|
|
|
// Event information
|
|
judul_event: 'Workshop Digital Marketing',
|
|
tanggal_event: '25 Desember 2025',
|
|
jam_event: '19:00',
|
|
link_event: 'https://with.dwindi.com/events',
|
|
lokasi_event: 'Zoom Online',
|
|
kapasitas_event: '100 peserta',
|
|
|
|
// Bootcamp/Course information
|
|
judul_bootcamp: 'Digital Marketing Bootcamp',
|
|
progres_bootcamp: '75%',
|
|
modul_selesai: '15 dari 20 modul',
|
|
modul_selanjutnya: 'Final Assessment',
|
|
link_progress: 'https://with.dwindi.com/bootcamp/progress',
|
|
|
|
// Company information
|
|
nama_perusahaan: 'ACCESS HUB',
|
|
website_perusahaan: 'https://with.dwindi.com',
|
|
email_support: 'support@with.dwindi.com',
|
|
telepon_support: '+62 812-3456-7890',
|
|
|
|
// Payment information
|
|
bank_tujuan: 'BCA',
|
|
nomor_rekening: '123-456-7890',
|
|
atas_nama: 'PT Access Hub Indonesia',
|
|
jumlah_pembayaran: 'Rp 1.500.000',
|
|
batas_pembayaran: '22 Desember 2025 23:59',
|
|
payment_link: 'https://with.dwindi.com/checkout',
|
|
thank_you_page: 'https://with.dwindi.com/orders/{order_id}'
|
|
};
|
|
|
|
static process(content: string, customData: Record<string, string> = {}): string {
|
|
const data = { ...this.DEFAULT_DATA, ...customData };
|
|
|
|
let processed = content;
|
|
for (const [key, value] of Object.entries(data)) {
|
|
const regex = new RegExp(`\\{${key}\\}`, 'g');
|
|
processed = processed.replace(regex, value);
|
|
}
|
|
|
|
return processed;
|
|
}
|
|
|
|
static getDummyData(): Record<string, string> {
|
|
return this.DEFAULT_DATA;
|
|
}
|
|
}
|