diff --git a/surfsense_web/app/api/contact/route.ts b/surfsense_web/app/api/contact/route.ts index c7cafa467..0af47dfe3 100644 --- a/surfsense_web/app/api/contact/route.ts +++ b/surfsense_web/app/api/contact/route.ts @@ -1,59 +1,61 @@ -import { NextRequest, NextResponse } from 'next/server'; -import { db } from '@/app/db'; -import { usersTable } from '@/app/db/schema'; -import { z } from 'zod'; +import { type NextRequest, NextResponse } from "next/server"; +import { z } from "zod"; +import { db } from "@/app/db"; +import { usersTable } from "@/app/db/schema"; // Define validation schema matching the database schema const contactSchema = z.object({ - name: z.string().min(1, 'Name is required').max(255, 'Name is too long'), - email: z.string().email('Invalid email address').max(255, 'Email is too long'), - company: z.string().min(1, 'Company is required').max(255, 'Company name is too long'), - message: z.string().optional().default(''), + name: z.string().min(1, "Name is required").max(255, "Name is too long"), + email: z.string().email("Invalid email address").max(255, "Email is too long"), + company: z.string().min(1, "Company is required").max(255, "Company name is too long"), + message: z.string().optional().default(""), }); export async function POST(request: NextRequest) { - try { - const body = await request.json(); - - // Validate the request body - const validatedData = contactSchema.parse(body); - - // Insert into database - const result = await db.insert(usersTable).values({ - name: validatedData.name, - email: validatedData.email, - company: validatedData.company, - message: validatedData.message, - }).returning(); - - return NextResponse.json( - { - success: true, - message: 'Contact form submitted successfully', - data: result[0] - }, - { status: 201 } - ); - } catch (error) { - if (error instanceof z.ZodError) { - return NextResponse.json( - { - success: false, - message: 'Validation error', - errors: error.errors - }, - { status: 400 } - ); - } - - console.error('Error submitting contact form:', error); - return NextResponse.json( - { - success: false, - message: 'Failed to submit contact form' - }, - { status: 500 } - ); - } -} + try { + const body = await request.json(); + // Validate the request body + const validatedData = contactSchema.parse(body); + + // Insert into database + const result = await db + .insert(usersTable) + .values({ + name: validatedData.name, + email: validatedData.email, + company: validatedData.company, + message: validatedData.message, + }) + .returning(); + + return NextResponse.json( + { + success: true, + message: "Contact form submitted successfully", + data: result[0], + }, + { status: 201 } + ); + } catch (error) { + if (error instanceof z.ZodError) { + return NextResponse.json( + { + success: false, + message: "Validation error", + errors: error.errors, + }, + { status: 400 } + ); + } + + console.error("Error submitting contact form:", error); + return NextResponse.json( + { + success: false, + message: "Failed to submit contact form", + }, + { status: 500 } + ); + } +} diff --git a/surfsense_web/app/db/index.ts b/surfsense_web/app/db/index.ts index 5d7a87757..277848bb5 100644 --- a/surfsense_web/app/db/index.ts +++ b/surfsense_web/app/db/index.ts @@ -1,6 +1,6 @@ -import { drizzle } from 'drizzle-orm/postgres-js' -import postgres from 'postgres' -import * as schema from './schema' +import { drizzle } from "drizzle-orm/postgres-js"; +import postgres from "postgres"; +import * as schema from "./schema"; -const client = postgres(process.env.DATABASE_URL!) +const client = postgres(process.env.DATABASE_URL!); export const db = drizzle({ client, schema }); diff --git a/surfsense_web/app/db/schema.ts b/surfsense_web/app/db/schema.ts index fc5678bc3..d8b941ba5 100644 --- a/surfsense_web/app/db/schema.ts +++ b/surfsense_web/app/db/schema.ts @@ -1,9 +1,9 @@ import { integer, pgTable, text, varchar } from "drizzle-orm/pg-core"; export const usersTable = pgTable("users", { - id: integer().primaryKey().generatedAlwaysAsIdentity(), - name: varchar({ length: 255 }).notNull(), - email: varchar({ length: 255 }).notNull().unique(), - company: varchar({ length: 255 }).notNull(), - message: text().default(''), + id: integer().primaryKey().generatedAlwaysAsIdentity(), + name: varchar({ length: 255 }).notNull(), + email: varchar({ length: 255 }).notNull().unique(), + company: varchar({ length: 255 }).notNull(), + message: text().default(""), }); diff --git a/surfsense_web/components/contact/contact-form.tsx b/surfsense_web/components/contact/contact-form.tsx index 4a658d302..0fd07a056 100644 --- a/surfsense_web/components/contact/contact-form.tsx +++ b/surfsense_web/components/contact/contact-form.tsx @@ -76,11 +76,10 @@ export function ContactFormGridWithDetails() {
- We are always looking for ways to improve our products and services. Contact us and let us - know how we can help you. + We'd love to Hear From You.