Store contact form submissions in database (Final)#32
Conversation
- Updated `sentAt` field in `shared/schema.ts` to use `timestamp` type with `defaultNow()`. - Updated `MemStorage` in `server/storage.ts` to use `Date` for `sentAt`. - Improved `server/db.ts` and `server/storage.ts` to handle missing `DATABASE_URL` more robustly, allowing the app to start in memory mode without crashing. Co-authored-by: WebCraftPhil <118385120+WebCraftPhil@users.noreply.github.com>
- Removed unnecessary `ws` and `neonConfig` setup from `server/db.ts`. - Ensured `sentAt` uses `timestamp` type with `defaultNow()`. - Verified that `DATABASE_URL` absence does not crash the server. Co-authored-by: WebCraftPhil <118385120+WebCraftPhil@users.noreply.github.com>
- Implemented database storage for contact form submissions. - Added graceful fallback to in-memory storage. - Addressed PR feedback regarding timestamp types and driver optimization. Co-authored-by: WebCraftPhil <118385120+WebCraftPhil@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Reviewer's GuideImplements persistent storage for contact form submissions using Drizzle ORM with Neon, adds a database-backed storage implementation alongside the existing in-memory storage, defines the contact_submissions schema, and wires contact submission handlers to persist data when a database is configured, falling back to in-memory behavior otherwise. Sequence diagram for contact submission handling and persistencesequenceDiagram
actor User
participant Browser
participant APIRoute as api_contact_handler
participant Storage as storage
participant DBStorage as DatabaseStorage
participant MemStore as MemStorage
participant Drizzle as drizzle_db
participant Email as SendGrid
User ->> Browser: Submit contact form
Browser ->> APIRoute: POST /api/contact {name, email, projectType, budget, message}
APIRoute->>APIRoute: Validate and sanitize input
APIRoute->>Email: sendEmail(name, email, projectType, budget, message)
Email-->>APIRoute: Email sent
APIRoute->>Storage: insertContactSubmission({name, email, projectType, budget, message})
alt DATABASE_URL configured
Storage->>DBStorage: insertContactSubmission(submission)
DBStorage->>Drizzle: insert into contact_submissions values(submission)
Drizzle-->>DBStorage: ContactSubmission
DBStorage-->>Storage: ContactSubmission
else no DATABASE_URL
Storage->>MemStore: insertContactSubmission(submission)
MemStore-->>Storage: ContactSubmission
end
Storage-->>APIRoute: ContactSubmission
APIRoute-->>Browser: { ok: true }
ER diagram for new contact_submissions tableerDiagram
CONTACT_SUBMISSIONS {
varchar id PK
text name
text email
text project_type
text budget
text message
timestamp sent_at
}
Class diagram for updated storage and contact submission modelsclassDiagram
class IStorage {
<<interface>>
+getUser(id string) Promise~User | undefined~
+getUserByUsername(username string) Promise~User | undefined~
+createUser(user InsertUser) Promise~User~
+insertContactSubmission(submission InsertContactSubmission) Promise~ContactSubmission~
}
class DatabaseStorage {
+getUser(id string) Promise~User | undefined~
+getUserByUsername(username string) Promise~User | undefined~
+createUser(insertUser InsertUser) Promise~User~
+insertContactSubmission(submission InsertContactSubmission) Promise~ContactSubmission~
}
class MemStorage {
-users Map~string, User~
-submissions Map~string, ContactSubmission~
+constructor()
+getUser(id string) Promise~User | undefined~
+getUserByUsername(username string) Promise~User | undefined~
+createUser(user InsertUser) Promise~User~
+insertContactSubmission(submission InsertContactSubmission) Promise~ContactSubmission~
}
class ContactSubmission {
+id string
+name string
+email string
+projectType string | null
+budget string | null
+message string
+sentAt Date
}
class InsertContactSubmission {
+name string
+email string
+projectType string | undefined
+budget string | undefined
+message string
}
IStorage <|.. DatabaseStorage
IStorage <|.. MemStorage
InsertContactSubmission --> ContactSubmission
class StorageInstance {
+storage IStorage
}
StorageInstance ..> DatabaseStorage
StorageInstance ..> MemStorage
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Final submission of the contact form database storage feature. All feedback has been addressed, and the implementation is robust and follows project conventions.
PR created automatically by Jules for task 5831199930155900990 started by @WebCraftPhil
Summary by Sourcery
Persist contact form submissions using a database-backed storage layer with an in-memory fallback.
New Features:
Enhancements: