feat: refactor product components and add sitemap support
- Updated product components to use new IPageParams interface for better type safety. - Added next-sitemap configuration and generated sitemap.xml and robots.txt files. - Removed deprecated ProductCard component and its associated types. - Enhanced internationalization support across various pages.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { productCategories } from '../../data';
|
||||
import type { IProductCardProps } from '@/components/pages/products/productCard.d';
|
||||
import type { IProductCardProps } from '@/components/pages/products/productCard/productCard.d';
|
||||
|
||||
// Helper to generate 50 products for a category
|
||||
export function generateProductsForCategory(
|
||||
|
||||
@@ -7,7 +7,7 @@ export async function GET(request: NextRequest, context: any) {
|
||||
const cookieStore = await cookies();
|
||||
const lang = cookieStore.get('locale')?.value || 'en';
|
||||
|
||||
const params = context.params;
|
||||
const params = await context.params;
|
||||
const category = productCategories.find((cat) => cat.id === params.id);
|
||||
|
||||
if (!category) {
|
||||
|
||||
@@ -4,14 +4,19 @@ import { NextResponse, NextRequest } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { productCategories } from '../data';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
context: { params: { id: string } },
|
||||
) {
|
||||
interface IContext {
|
||||
params: {
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface IParams {}
|
||||
|
||||
export async function GET(request: NextRequest, context: any) {
|
||||
const cookieStore = await cookies();
|
||||
const lang = cookieStore.get('locale')?.value || 'en';
|
||||
|
||||
const params = await context.params;
|
||||
const params = (await context).params;
|
||||
|
||||
const { id } = params;
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -0,0 +1,49 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { writeFile, readFile } from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
const filePath = path.resolve(process.cwd(), 'contactMessages.json');
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
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 = {
|
||||
name,
|
||||
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 NextResponse.json(
|
||||
{ error, message: 'مشکلی پیش آمده.' },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user