730e2d8ca8
- Implemented CertificateGallery component to display certification images in a gallery format. - Created CertificationsSection component to showcase certifications with titles and descriptions. - Enhanced Gallery component to support animations and keyboard navigation. - Introduced Select component for dropdown selection with images. - Added utility functions for API responses and pagination handling. - Implemented localization functions for text and content. - Created a custom hook for detecting clicks outside of a component.
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { mkdir, writeFile, readFile } from 'fs/promises';
|
|
import path from 'path';
|
|
import { serverError } from '@/lib/api-response';
|
|
|
|
const filePath = path.resolve(process.cwd(), 'data', 'contactMessages.json');
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
await mkdir(path.dirname(filePath), { recursive: true });
|
|
|
|
const body = await request.json();
|
|
const { first_name, last_name, phone, email, message } = body;
|
|
|
|
if (!first_name || !last_name || !phone || !email || !message) {
|
|
return NextResponse.json(
|
|
{ error: 'مقدار تمامی فیلدها را پر کنید' },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
let messages = [];
|
|
try {
|
|
const fileData = await readFile(filePath, 'utf-8');
|
|
messages = JSON.parse(fileData);
|
|
} catch {
|
|
messages = [];
|
|
}
|
|
|
|
const newMessage = {
|
|
first_name,
|
|
last_name,
|
|
phone,
|
|
email,
|
|
message,
|
|
createdAt: new Date().toISOString(),
|
|
};
|
|
|
|
messages.push(newMessage);
|
|
|
|
// Write updated messages back to file
|
|
await writeFile(filePath, JSON.stringify(messages, null, 2), 'utf-8');
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: 'Your message has been received.',
|
|
});
|
|
} catch (error) {
|
|
return serverError('مشکلی پیش آمده.');
|
|
}
|
|
}
|