diff --git a/scripts/seed.ts b/scripts/seed.ts index 5acdab7..6a684c7 100644 --- a/scripts/seed.ts +++ b/scripts/seed.ts @@ -1,3 +1,4 @@ + import Database from 'better-sqlite3'; const db = new Database('local.db'); @@ -41,25 +42,60 @@ function seed() { const templateStmt = db.prepare('SELECT * FROM email_templates WHERE id = ?'); const defaultTemplate = templateStmt.get(1); + const defaultSubject = "Your EstimateFlow Project Estimate is Ready!"; + const defaultBody = ` + + + + + + Your Project Estimate + + + + + + + + + + + + +
+

EstimateFlow

+
+

Hello, [User Name],

+

+ Thank you for using EstimateFlow. We've prepared a rough estimate for your project based on your selections. +

+ + [EstimateDetails] + +

+ Please note that this is a preliminary estimate. For a more detailed quote and to discuss your project further, please don't hesitate to contact us. +

+
+ Contact Us +
+
+

Best regards,
The EstimateFlow Team

+

© ${new Date().getFullYear()} EstimateFlow. All rights reserved.

+
+ +`; + if (!defaultTemplate) { const insertTemplate = db.prepare( "INSERT INTO email_templates (id, subject, body) VALUES (?, ?, ?)" ); - const defaultSubject = "Your Project Estimate is Ready!"; - const defaultBody = `Hello, [User Name], - -Thank you for using EstimateFlow. We've prepared a rough estimate for your project based on your selections. - -[EstimateDetails] - -Please note that this is a preliminary estimate. For a more detailed quote and to discuss your project further, please don't hesitate to contact us. - -Best regards, -The EstimateFlow Team`; insertTemplate.run(1, defaultSubject, defaultBody); console.log('Default email template created.'); } else { - console.log('Default email template already exists.'); + // If you want to update the template on every seed, you can use an UPDATE query here + const updateTemplate = db.prepare("UPDATE email_templates SET subject = ?, body = ? WHERE id = ?"); + updateTemplate.run(defaultSubject, defaultBody, 1); + console.log('Default email template updated.'); } diff --git a/src/app/admin/settings/email-templates/page.tsx b/src/app/admin/settings/email-templates/page.tsx index 002e6e3..d245024 100644 --- a/src/app/admin/settings/email-templates/page.tsx +++ b/src/app/admin/settings/email-templates/page.tsx @@ -9,6 +9,7 @@ import { getEmailTemplate, updateEmailTemplate } from '@/lib/actions/email'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Label } from '@/components/ui/label'; +import { Skeleton } from '@/components/ui/skeleton'; type EmailTemplate = { subject: string; @@ -16,26 +17,29 @@ type EmailTemplate = { }; function EmailPreview({ template }: { template: EmailTemplate }) { - const previewBody = template.body.replace( - '[EstimateDetails]', - `
-
-

Custom Development Estimate

-

[Custom Hours]+ hours

-
-
-

Ready-Made Tools Estimate

-

[Ready-Made Hours]+ hours

-
-
` - ).replace('[User Name]', 'Valued Customer').replace(/\n/g, '
'); + const estimateDetailsHtml = ` +
+
+

Custom Development Estimate

+

[Custom Hours]+ hours

+
+
+

Ready-Made Tools Estimate

+

[Ready-Made Hours]+ hours

+
+
`; + + const previewBody = template.body + .replace('[EstimateDetails]', estimateDetailsHtml) + .replace('[User Name]', 'Valued Customer'); return (
-
-

{template.subject}

-
-
+