From 5afe5b13f373b20e8552ed5c0d05ac970fb3ba6e Mon Sep 17 00:00:00 2001 From: sazzadulalambd Date: Wed, 13 May 2026 02:37:29 +0600 Subject: [PATCH] feat: add Email and SMS template management configuration page to admin settings --- .../settings/components/EmailSMSTemplates.tsx | 673 ++++++++++++++++++ src/app/admin/settings/page.tsx | 10 +- 2 files changed, 681 insertions(+), 2 deletions(-) create mode 100644 src/app/admin/settings/components/EmailSMSTemplates.tsx diff --git a/src/app/admin/settings/components/EmailSMSTemplates.tsx b/src/app/admin/settings/components/EmailSMSTemplates.tsx new file mode 100644 index 0000000..850d541 --- /dev/null +++ b/src/app/admin/settings/components/EmailSMSTemplates.tsx @@ -0,0 +1,673 @@ +'use client'; + +import { useState } from 'react'; +import { Mail, MessageSquare, Pencil, Eye, X, Check, Plus } from 'lucide-react'; +import toast from 'react-hot-toast'; + +interface Template { + id: string; + name: string; + subject?: string; + body: string; + enabled: boolean; +} + +interface EmailSMSTemplatesProps { + settings: any; + setSettings: any; +} + +const defaultEmailTemplates: Template[] = [ + { + id: 'welcome', + name: 'Welcome Email', + subject: 'Welcome to JAIBEN Mobility - Your Journey Starts Here!', + body: `Dear {name}, + +Welcome to JAIBEN Mobility! + +We're thrilled to have you join our community of eco-friendly commuters. Your account has been successfully created. + +Your Login Details: +- Phone: {phone} +- Email: {email} + +What's Next? +1. Complete your KYC verification to unlock all features +2. Browse our EV rental plans +3. Choose your perfect electric vehicle + +If you have any questions, our support team is here to help! + +Best regards, +JAIBEN Mobility Team`, + enabled: true, + }, + { + id: 'password_reset', + name: 'Password Reset', + subject: 'Reset Your JAIBEN Password', + body: `Dear {name}, + +We received a request to reset your password. + +Your OTP code is: {otp} + +This code will expire in {expiry_minutes} minutes. + +If you didn't request this, please ignore this email or contact support immediately. + +Note: Never share this OTP with anyone. + +JAIBEN Mobility Team`, + enabled: true, + }, + { + id: 'rental_confirmation', + name: 'Rental Confirmation', + subject: 'Rental Confirmed - Your EV is Ready!', + body: `Dear {name}, + +Your rental has been confirmed! + +Booking Details: +- Bike: {bike} +- Plan: {plan} +- Start Date: {start_date} +- End Date: {end_date} +- Amount: {amount} +- Deposit: {deposit} + +Pickup Location: {pickup_location} + +Important: +- Bring your valid driving license +- Carry NID card for verification +- Arrive 15 minutes before scheduled time + +Enjoy your ride! + +JAIBEN Mobility Team`, + enabled: true, + }, + { + id: 'payment_reminder', + name: 'Payment Reminder', + subject: 'Payment Due Soon - {amount}', + body: `Dear {name}, + +This is a friendly reminder that your payment is due. + +Amount Due: {amount} +Due Date: {due_date} +Rental: {bike} + +Please make your payment to avoid late fees. + +Payment Methods: +- bKash: {bkash_number} +- Nagad: {nagad_number} +- Bank Transfer: {bank_account} + +Need help? Contact us anytime! + +JAIBEN Mobility Team`, + enabled: true, + }, + { + id: 'due_notice', + name: 'Due Notice', + subject: 'Payment Overdue - Action Required', + body: `Dear {name}, + +Your payment for the rental of {bike} is overdue. + +Overdue Amount: {amount} +Days Overdue: {days_overdue} +Late Fee: {late_fee} + +Please make immediate payment to avoid service interruption. + +Total Due: {total_due} + +If you've already made the payment, please ignore this message or contact us to confirm. + +JAIBEN Mobility Team`, + enabled: true, + }, + { + id: 'kyc_verification', + name: 'KYC Verification', + subject: 'KYC Verification {status}', + body: `Dear {name}, + +Your KYC verification has been {status}. + +{status_message} + +{status === 'approved' ? 'You can now access all features and rent EVs!' : 'Please resubmit your documents with correct information.'} + +Documents Submitted: +{documents_list} + +If you have questions, contact our support team. + +JAIBEN Mobility Team`, + enabled: true, + }, + { + id: 'rental_termination', + name: 'Rental Termination', + subject: 'Rental Agreement Terminated', + body: `Dear {name}, + +Your rental agreement for {bike} has been terminated. + +Termination Details: +- End Date: {end_date} +- Final Amount: {final_amount} +- Refund: {refund_amount} + +Please return the vehicle to {return_location} by {return_date}. + +Any outstanding charges will be deducted from your deposit. + +Thank you for choosing JAIBEN! + +JAIBEN Mobility Team`, + enabled: true, + }, + { + id: 'damage_report', + name: 'Damage Report', + subject: 'Vehicle Damage Report - {bike}', + body: `Dear {name}, + +A damage report has been filed for your rented vehicle. + +Incident Details: +- Date: {incident_date} +- Location: {location} +- Description: {description} +- Estimated Cost: {repair_cost} + +Your current deposit: {deposit} +Remaining after repair: {remaining_deposit} + +Please contact us within 24 hours if you have any concerns. + +JAIBEN Mobility Team`, + enabled: true, + }, +]; + +const defaultSmsTemplates: Template[] = [ + { + id: 'otp', + name: 'OTP Code', + body: `JAIBEN: Your OTP is {otp}. Valid for {expiry_minutes} mins. Don't share this code.`, + enabled: true, + }, + { + id: 'rental_reminder', + name: 'Rental Reminder', + body: `JAIBEN: Reminder! Your {bike} rental starts on {start_date}. Pick up from {location}. Reply CONFIRM to proceed.`, + enabled: true, + }, + { + id: 'payment_due', + name: 'Payment Due', + body: `JAIBEN: Payment of {amount} due on {due_date} for your {bike} rental. Pay via bKash: {bkash}. Avoid late fees!`, + enabled: true, + }, + { + id: 'battery_low', + name: 'Battery Low Warning', + body: `JAIBEN: Your {bike} battery is low ({battery_level}%). Visit nearest swap station or charge point. Stay safe!`, + enabled: true, + }, + { + id: 'damage_report_sms', + name: 'Damage Report', + body: `JAIBEN: Damage reported on your {bike}. Est. cost: {repair_cost}. Contact {support_phone} within 24hrs.`, + enabled: true, + }, + { + id: 'welcome_sms', + name: 'Welcome Message', + body: `Welcome to JAIBEN Mobility {name}! Your account is ready. Download our app or visit {app_link} to rent your first EV!`, + enabled: true, + }, + { + id: 'rental_start', + name: 'Rental Started', + body: `JAIBEN: Your {bike} rental has started! Enjoy your ride. Return by {return_time}. Ride safe!`, + enabled: true, + }, + { + id: 'rental_end', + name: 'Rental Ending', + body: `JAIBEN: Your {bike} rental ends on {end_date}. Extend at {app_link} or return to {location}. Thanks!`, + enabled: true, + }, + { + id: 'swap_reminder', + name: 'Battery Swap Reminder', + body: `JAIBEN: Your battery at {location} is low. Swap station: {station_name}, Distance: {distance}km. Free swap with your plan!`, + enabled: true, + }, + { + id: 'kyc_approved', + name: 'KYC Approved', + body: `JAIBEN: Great news! Your KYC is verified. You can now rent EVs. Download app: {app_link} or visit nearest hub!`, + enabled: true, + }, +]; + +const commonVariables = [ + { name: 'name', label: 'Name' }, + { name: 'phone', label: 'Phone' }, + { name: 'email', label: 'Email' }, + { name: 'amount', label: 'Amount' }, + { name: 'date', label: 'Date' }, + { name: 'bike', label: 'Bike Name' }, + { name: 'plan', label: 'Plan' }, + { name: 'otp', label: 'OTP' }, + { name: 'deposit', label: 'Deposit' }, + { name: 'start_date', label: 'Start Date' }, + { name: 'end_date', label: 'End Date' }, + { name: 'location', label: 'Location' }, +]; + +export default function EmailSMSTemplates({ settings, setSettings }: EmailSMSTemplatesProps) { + const [activeTemplateTab, setActiveTemplateTab] = useState<'email' | 'sms'>('email'); + const [emailTemplates, setEmailTemplates] = useState( + settings.emailTemplates || defaultEmailTemplates + ); + const [smsTemplates, setSmsTemplates] = useState( + settings.smsTemplates || defaultSmsTemplates + ); + const [showModal, setShowModal] = useState(false); + const [editingTemplate, setEditingTemplate] = useState