diff --git a/app/api/testimonials/route.ts b/app/api/testimonials/route.ts index 69f4f12..78585af 100644 --- a/app/api/testimonials/route.ts +++ b/app/api/testimonials/route.ts @@ -24,7 +24,7 @@ export async function POST(request: Request) { const data = await request.json(); // Basic validation - if (!data.name || !data.role || !data.email || !data.content || !data.imageUrl) { + if (!data.name || !data.role || !data.email || !data.content) { return NextResponse.json( { error: 'Missing required fields' }, { status: 400 } @@ -33,6 +33,7 @@ export async function POST(request: Request) { const testimonial = await Testimonial.create({ ...data, + imageUrl: data.imageUrl || '/avatar.svg', isApproved: false, // Explicitly false for public submissions type: data.videoUrl ? 'video' : 'text' }); diff --git a/components/submit-testimonial-modal.tsx b/components/submit-testimonial-modal.tsx index bd9d1d0..ee7b8b6 100644 --- a/components/submit-testimonial-modal.tsx +++ b/components/submit-testimonial-modal.tsx @@ -22,7 +22,8 @@ export function SubmitTestimonialModal() { role: '', email: '', content: '', - videoUrl: '' + videoUrl: '', + cta: '' }) const handleImageChange = (e: React.ChangeEvent) => { @@ -57,8 +58,6 @@ export function SubmitTestimonialModal() { if (!uploadRes.ok) throw new Error('Image upload failed') const uploadData = await uploadRes.json() imageUrl = uploadData.url - } else { - throw new Error('Image is required') } // Submit testimonial data @@ -84,7 +83,8 @@ export function SubmitTestimonialModal() { role: '', email: '', content: '', - videoUrl: '' + videoUrl: '', + cta: '' }) setImageFile(null) setImagePreview(null) @@ -166,7 +166,7 @@ export function SubmitTestimonialModal() {
- +
+
+ + setFormData({...formData, cta: e.target.value})} + /> +

Short call-to-action or closing thought.

+
+
@@ -115,7 +122,7 @@ export function TestimonialCard({ testimonial }: { testimonial: Testimonial }) {
{testimonial.name}{testimonial.role}

+ {testimonial.cta && ( +

+ {testimonial.cta} +

+ )} ); diff --git a/models/Testimonial.ts b/models/Testimonial.ts index a960af2..2cac3ff 100644 --- a/models/Testimonial.ts +++ b/models/Testimonial.ts @@ -5,8 +5,9 @@ export interface ITestimonial extends Document { role: string; email: string; content: string; + cta?: string; videoUrl?: string; - imageUrl: string; + imageUrl?: string; type: 'text' | 'video'; isApproved: boolean; createdAt: Date; @@ -35,13 +36,17 @@ const TestimonialSchema = new Schema( required: [true, 'Testimonial content is required'], trim: true, }, + cta: { + type: String, + trim: true, + }, videoUrl: { type: String, trim: true, }, imageUrl: { type: String, - required: [true, 'Image/Avatar is required'], + default: '/avatar.svg', }, type: { type: String,