make the send estimate modal more beautifull and informative, also besid
This commit is contained in:
@@ -7,13 +7,14 @@ export type Lead = {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
phone: string | null;
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
export async function getLeads(): Promise<Lead[]> {
|
||||
try {
|
||||
const stmt = db.prepare(
|
||||
'SELECT id, name, email, createdAt FROM leads ORDER BY createdAt DESC'
|
||||
'SELECT id, name, email, phone, createdAt FROM leads ORDER BY createdAt DESC'
|
||||
);
|
||||
const leads = stmt.all() as Lead[];
|
||||
return leads;
|
||||
|
||||
@@ -11,6 +11,7 @@ import type { FormData } from '@/components/cost-estimator/cost-estimator-form';
|
||||
const inputSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
email: z.string().email(),
|
||||
phone: z.string().optional(),
|
||||
customHours: z.number(),
|
||||
readyMadeHours: z.number(),
|
||||
formData: z.any(), // Keeping this flexible for now
|
||||
@@ -39,7 +40,7 @@ async function getSmtpSettings() {
|
||||
|
||||
|
||||
async function createEstimatePdf(data: InputType): Promise<Buffer> {
|
||||
const { name, customHours, readyMadeHours, formData } = data;
|
||||
const { name, email, phone, customHours, readyMadeHours, formData } = data;
|
||||
const pdfDoc = await PDFDocument.create();
|
||||
const page = pdfDoc.addPage();
|
||||
const { width, height } = page.getSize();
|
||||
@@ -61,10 +62,16 @@ async function createEstimatePdf(data: InputType): Promise<Buffer> {
|
||||
y -= 30;
|
||||
|
||||
// Subheader
|
||||
page.drawText(`Project Estimate for: ${name}`, { x: 50, y, font: boldFont, size: 18 });
|
||||
page.drawText('Project Estimate For:', { x: 50, y, font: boldFont, size: 18 });
|
||||
y -= 25;
|
||||
page.drawText(name, { x: 50, y, font: font, size: 14 });
|
||||
y -= 20;
|
||||
page.drawText(`Date: ${new Date().toLocaleDateString()}`, { x: 50, y, font, size: 12, color: rgb(0.3, 0.3, 0.3) });
|
||||
y -= 40;
|
||||
page.drawText(email, { x: 50, y, font: font, size: 12, color: rgb(0.3, 0.3, 0.3) });
|
||||
y -= 18;
|
||||
if (phone) {
|
||||
page.drawText(phone, { x: 50, y, font: font, size: 12, color: rgb(0.3, 0.3, 0.3) });
|
||||
}
|
||||
y -= 30;
|
||||
|
||||
// Summary
|
||||
page.drawText('Estimate Summary', { x: 50, y, font: boldFont, size: 16 });
|
||||
@@ -109,10 +116,10 @@ async function createEstimatePdf(data: InputType): Promise<Buffer> {
|
||||
return Buffer.from(pdfBytes);
|
||||
}
|
||||
|
||||
async function saveLead(name: string, email: string) {
|
||||
async function saveLead(name: string, email: string, phone?: string) {
|
||||
try {
|
||||
const stmt = db.prepare('INSERT INTO leads (name, email) VALUES (?, ?)');
|
||||
stmt.run(name, email);
|
||||
const stmt = db.prepare('INSERT INTO leads (name, email, phone) VALUES (?, ?, ?)');
|
||||
stmt.run(name, email, phone || null);
|
||||
console.log(`Lead saved: ${name}, ${email}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to save lead:', error);
|
||||
@@ -160,7 +167,7 @@ export async function sendEstimateEmail(data: InputType): Promise<{ success: boo
|
||||
await transporter.sendMail(mailOptions);
|
||||
|
||||
// Save lead after email is sent successfully
|
||||
await saveLead(validation.data.name, validation.data.email);
|
||||
await saveLead(validation.data.name, validation.data.email, validation.data.phone);
|
||||
|
||||
return { success: true };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user