diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index a7664eb9..9c75b2ef 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -31,6 +31,7 @@ model User { paymentTransactions PaymentTransaction[] tickets Ticket[] reviews ProductReview[] + blogComments BlogComment[] @@map("users") } @@ -114,10 +115,14 @@ model Blog { metaDescription String? @map("meta_description") @db.Text keywords String? @db.Text isPublished Boolean @default(true) @map("is_published") + viewCount Int @default(0) @map("view_count") + showOnHome Boolean @default(false) @map("show_on_home") + homeDisplayMode String @default("selected") @map("home_display_mode") @db.VarChar(30) createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz() updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamptz() - author User @relation(fields: [authorId], references: [id]) + author User @relation(fields: [authorId], references: [id]) + comments BlogComment[] @@map("blogs") } @@ -463,20 +468,23 @@ model SmartAdvisorRule { } model Doctor { - id String @id @default(uuid()) @db.Uuid - name String @db.VarChar(150) - title String? @db.VarChar(150) - clinicName String? @map("clinic_name") @db.VarChar(200) - avatarUrl String? @map("avatar_url") @db.Text - bio String? @db.Text - cv String? @db.Text - phone String? @db.VarChar(50) - email String? @db.VarChar(150) - instagram String? @db.VarChar(100) - isActive Boolean @default(true) @map("is_active") - order Int @default(0) - createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz() - updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz() + id String @id @default(uuid()) @db.Uuid + name String @db.VarChar(150) + title String? @db.VarChar(150) + clinicName String? @map("clinic_name") @db.VarChar(200) + avatarUrl String? @map("avatar_url") @db.Text + bio String? @db.Text + cv String? @db.Text + phone String? @db.VarChar(50) + email String? @db.VarChar(150) + instagram String? @db.VarChar(100) + quote String? @db.Text + quoteProductRef String? @map("quote_product_ref") @db.VarChar(200) + showQuoteOnHome Boolean @default(false) @map("show_quote_on_home") + isActive Boolean @default(true) @map("is_active") + order Int @default(0) + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz() + updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz() videos Video[] @@ -553,6 +561,7 @@ model Testimonial { rating Int @default(5) isFeatured Boolean @default(false) @map("is_featured") isActive Boolean @default(true) @map("is_active") + showOnHome Boolean @default(false) @map("show_on_home") order Int @default(0) createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz() updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz() @@ -720,3 +729,54 @@ model ProductReview { } + +model BlogComment { + id String @id @default(uuid()) @db.Uuid + blogId String @map("blog_id") @db.Uuid + userId String? @map("user_id") @db.Uuid + userName String @map("user_name") @db.VarChar(100) + content String @db.Text + status String @default("PENDING") @db.VarChar(20) + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz() + + blog Blog @relation(fields: [blogId], references: [id], onDelete: Cascade) + user User? @relation(fields: [userId], references: [id], onDelete: SetNull) + + @@index([blogId]) + @@index([status]) + @@map("blog_comments") +} + +model FAQ { + id String @id @default(uuid()) @db.Uuid + question String @db.Text + answer String @db.Text + order Int @default(0) + isActive Boolean @default(true) @map("is_active") + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz() + updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz() + + @@map("faqs") +} + +model MenuItem { + id String @id @default(uuid()) @db.Uuid + menuType String @map("menu_type") @db.VarChar(30) + label String @db.VarChar(150) + href String @db.VarChar(500) + parentId String? @map("parent_id") @db.Uuid + order Int @default(0) + isActive Boolean @default(true) @map("is_active") + isExternal Boolean @default(false) @map("is_external") + icon String? @db.VarChar(100) + badge String? @db.VarChar(50) + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz() + updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz() + + parent MenuItem? @relation("MenuChildren", fields: [parentId], references: [id]) + children MenuItem[] @relation("MenuChildren") + + @@index([menuType]) + @@index([parentId]) + @@map("menu_items") +} diff --git a/backend/src/admin/blogs.controller.ts b/backend/src/admin/blogs.controller.ts index e7fe0cb0..9fe205b9 100644 --- a/backend/src/admin/blogs.controller.ts +++ b/backend/src/admin/blogs.controller.ts @@ -3,6 +3,7 @@ import { Get, Post, Put, + Patch, Delete, Body, Param, @@ -19,7 +20,6 @@ import { ApiOperation, ApiQuery, } from '@nestjs/swagger'; - import { PaginationDto } from '../common/dto/pagination.dto'; @ApiTags('Admin - مدیریت مقالات (بلاگ)') @@ -31,9 +31,9 @@ export class BlogsController { @Get() @ApiOperation({ summary: 'لیست مقالات' }) - @ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' }) - @ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتم‌ها' }) - @ApiQuery({ name: 'search', required: false, description: 'جستجو' }) + @ApiQuery({ name: 'page', required: false }) + @ApiQuery({ name: 'limit', required: false }) + @ApiQuery({ name: 'search', required: false }) async getBlogs(@Query() query: PaginationDto) { return this.blogsService.getBlogs(query); } @@ -64,4 +64,43 @@ export class BlogsController { await this.blogsService.deleteBlog(id); return { success: true }; } + + // Blog Comments endpoints + @Get('comments') + @ApiOperation({ summary: 'لیست نظرات مقالات' }) + @ApiQuery({ + name: 'status', + required: false, + description: 'PENDING | APPROVED | REJECTED', + }) + @ApiQuery({ name: 'blogId', required: false }) + @ApiQuery({ name: 'page', required: false }) + @ApiQuery({ name: 'limit', required: false }) + async getComments( + @Query() + query: { + page?: number; + limit?: number; + status?: string; + blogId?: string; + }, + ) { + return this.blogsService.getComments(query); + } + + @Patch('comments/:id/status') + @ApiOperation({ summary: 'تغییر وضعیت نظر (تأیید/رد)' }) + async updateCommentStatus( + @Param('id') id: string, + @Body() body: { status: 'APPROVED' | 'REJECTED' }, + ) { + return this.blogsService.updateCommentStatus(id, body.status); + } + + @Delete('comments/:id') + @ApiOperation({ summary: 'حذف نظر' }) + async deleteComment(@Param('id') id: string) { + await this.blogsService.deleteComment(id); + return { success: true }; + } } diff --git a/backend/src/admin/blogs.service.ts b/backend/src/admin/blogs.service.ts index f82328bd..739c503e 100644 --- a/backend/src/admin/blogs.service.ts +++ b/backend/src/admin/blogs.service.ts @@ -1,18 +1,13 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import { Prisma } from '@prisma/client'; import { PrismaService } from '../prisma/prisma.service'; - -export class BlogQuery { - page?: number | string; - limit?: number | string; - search?: string; -} +import { PaginationDto } from '../common/dto/pagination.dto'; @Injectable() export class BlogsService { constructor(private prisma: PrismaService) {} - async getBlogs(query: BlogQuery = {}) { + async getBlogs(query: PaginationDto) { const page = Number(query.page) || 1; const limit = Number(query.limit) || 10; const skip = (page - 1) * limit; @@ -27,7 +22,10 @@ export class BlogsService { skip, take: limit, orderBy: { createdAt: 'desc' }, - include: { author: { select: { firstName: true, lastName: true } } }, + include: { + author: { select: { firstName: true, lastName: true } }, + _count: { select: { comments: true } }, + }, }), this.prisma.blog.count({ where }), ]); @@ -63,4 +61,51 @@ export class BlogsService { if (!blog) throw new NotFoundException('Blog not found'); return this.prisma.blog.delete({ where: { id } }); } + + // Blog Comments Management + async getComments(query: { + page?: number; + limit?: number; + status?: string; + blogId?: string; + }) { + const page = Number(query.page) || 1; + const limit = Number(query.limit) || 20; + const skip = (page - 1) * limit; + + const where: Prisma.BlogCommentWhereInput = {}; + if (query.status) where.status = query.status; + if (query.blogId) where.blogId = query.blogId; + + const [data, total] = await Promise.all([ + this.prisma.blogComment.findMany({ + where, + skip, + take: limit, + orderBy: { createdAt: 'desc' }, + include: { + blog: { select: { title: true, slug: true } }, + user: { select: { firstName: true, lastName: true, mobile: true } }, + }, + }), + this.prisma.blogComment.count({ where }), + ]); + + return { + data, + meta: { total, page, limit, lastPage: Math.ceil(total / limit) }, + }; + } + + async updateCommentStatus(id: string, status: 'APPROVED' | 'REJECTED') { + const comment = await this.prisma.blogComment.findUnique({ where: { id } }); + if (!comment) throw new NotFoundException('Comment not found'); + return this.prisma.blogComment.update({ where: { id }, data: { status } }); + } + + async deleteComment(id: string) { + const comment = await this.prisma.blogComment.findUnique({ where: { id } }); + if (!comment) throw new NotFoundException('Comment not found'); + return this.prisma.blogComment.delete({ where: { id } }); + } } diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 1e8a5930..22ab2899 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -31,6 +31,8 @@ import { PaymentModule } from './payment/payment.module'; import { TicketsModule } from './tickets/tickets.module'; import { ReviewsModule } from './reviews/reviews.module'; import { DoctorsModule } from './doctors/doctors.module'; +import { FaqModule } from './faq/faq.module'; +import { MenuModule } from './menu/menu.module'; import { Request, Response, NextFunction } from 'express'; @@ -70,6 +72,8 @@ import { Request, Response, NextFunction } from 'express'; IngredientsModule, PrescriptionsModule, B2BModule, + FaqModule, + MenuModule, ], controllers: [MetricsController], providers: [ diff --git a/backend/src/blogs/blogs.controller.ts b/backend/src/blogs/blogs.controller.ts index 1219b45b..1ab47889 100644 --- a/backend/src/blogs/blogs.controller.ts +++ b/backend/src/blogs/blogs.controller.ts @@ -1,4 +1,14 @@ -import { Controller, Get, Param, HttpStatus, Query } from '@nestjs/common'; +import { + Controller, + Get, + Post, + Param, + Body, + HttpStatus, + Query, + UseGuards, + Request, +} from '@nestjs/common'; import { BlogsService } from './blogs.service'; import { ApiTags, @@ -6,8 +16,10 @@ import { ApiResponse, ApiOkResponse, ApiNotFoundResponse, + ApiBearerAuth, } from '@nestjs/swagger'; import { PaginationDto } from '../common/dto/pagination.dto'; +import { JwtAuthGuard } from '../auth/jwt-auth.guard'; @ApiTags('Blogs - مجله سلامت') @Controller('blogs') @@ -25,6 +37,13 @@ export class BlogsController { return this.blogsService.findAll(query); } + @Get('homepage') + @ApiOperation({ summary: 'دریافت مقالات برای نمایش در صفحه اصلی' }) + @ApiOkResponse({ description: 'مقالات انتخاب شده برای صفحه اصلی' }) + findHomepage() { + return this.blogsService.findHomepage(); + } + @Get(':slug') @ApiOperation({ summary: 'دریافت مقاله با اسلاگ (Slug)' }) @ApiOkResponse({ description: 'اطلاعات کامل مقاله' }) @@ -32,4 +51,25 @@ export class BlogsController { findOne(@Param('slug') slug: string) { return this.blogsService.findOneBySlug(slug); } + + @Get(':slug/comments') + @ApiOperation({ summary: 'دریافت نظرات تأیید شده مقاله' }) + findComments(@Param('slug') slug: string) { + return this.blogsService.findCommentsBySlug(slug); + } + + @UseGuards(JwtAuthGuard) + @ApiBearerAuth() + @Post(':slug/comments') + @ApiOperation({ summary: 'ارسال نظر برای مقاله (نیازمند ورود)' }) + addComment( + @Param('slug') slug: string, + @Body() body: { userName: string; content: string }, + @Request() req: any, + ) { + return this.blogsService.addComment(slug, { + ...body, + userId: req.user?.id, + }); + } } diff --git a/backend/src/blogs/blogs.service.ts b/backend/src/blogs/blogs.service.ts index 6f11e927..eb30fb92 100644 --- a/backend/src/blogs/blogs.service.ts +++ b/backend/src/blogs/blogs.service.ts @@ -36,6 +36,9 @@ export class BlogsService { author: { select: { firstName: true, lastName: true }, }, + _count: { + select: { comments: true }, + }, }, }), this.prisma.blog.count({ where: whereClause }), @@ -52,6 +55,36 @@ export class BlogsService { }; } + async findHomepage() { + // Find blogs that have showOnHome = true (selected mode) + const selectedBlogs = await this.prisma.blog.findMany({ + where: { isPublished: true, showOnHome: true }, + take: 3, + orderBy: { createdAt: 'desc' }, + include: { + author: { select: { firstName: true, lastName: true } }, + _count: { select: { comments: true } }, + }, + }); + + if (selectedBlogs.length > 0) { + return { mode: 'selected', blogs: selectedBlogs }; + } + + // Fallback: return newest 3 published blogs + const newestBlogs = await this.prisma.blog.findMany({ + where: { isPublished: true }, + take: 3, + orderBy: { createdAt: 'desc' }, + include: { + author: { select: { firstName: true, lastName: true } }, + _count: { select: { comments: true } }, + }, + }); + + return { mode: 'newest', blogs: newestBlogs }; + } + async findOneBySlug(slug: string) { const blog = await this.prisma.blog.findUnique({ where: { slug, isPublished: true }, @@ -59,6 +92,9 @@ export class BlogsService { author: { select: { firstName: true, lastName: true }, }, + _count: { + select: { comments: true }, + }, }, }); @@ -66,6 +102,46 @@ export class BlogsService { throw new NotFoundException('مقاله یافت نشد'); } - return blog; + // Increment view count + await this.prisma.blog.update({ + where: { id: blog.id }, + data: { viewCount: { increment: 1 } }, + }); + + return { ...blog, viewCount: blog.viewCount + 1 }; + } + + async findCommentsBySlug(slug: string) { + const blog = await this.prisma.blog.findUnique({ + where: { slug, isPublished: true }, + select: { id: true }, + }); + if (!blog) throw new NotFoundException('مقاله یافت نشد'); + + return this.prisma.blogComment.findMany({ + where: { blogId: blog.id, status: 'APPROVED' }, + orderBy: { createdAt: 'asc' }, + }); + } + + async addComment( + slug: string, + data: { userName: string; content: string; userId?: string }, + ) { + const blog = await this.prisma.blog.findUnique({ + where: { slug, isPublished: true }, + select: { id: true }, + }); + if (!blog) throw new NotFoundException('مقاله یافت نشد'); + + return this.prisma.blogComment.create({ + data: { + blogId: blog.id, + userName: data.userName, + content: data.content, + userId: data.userId, + status: 'PENDING', + }, + }); } } diff --git a/backend/src/doctors/doctors.controller.ts b/backend/src/doctors/doctors.controller.ts index b604757a..733e8f13 100644 --- a/backend/src/doctors/doctors.controller.ts +++ b/backend/src/doctors/doctors.controller.ts @@ -10,7 +10,8 @@ import { UseGuards, } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger'; -import { DoctorsService, DoctorQuery } from './doctors.service'; +import { DoctorsService } from './doctors.service'; +import { DoctorQueryDto } from './dto/doctor-query.dto'; import { JwtAuthGuard } from '../auth/jwt-auth.guard'; import { Prisma } from '@prisma/client'; @@ -21,7 +22,7 @@ export class DoctorsController { @Get() @ApiOperation({ summary: 'Get list of all doctors / specialists' }) - findAll(@Query() query: DoctorQuery) { + findAll(@Query() query: DoctorQueryDto) { return this.doctorsService.findAll(query); } diff --git a/backend/src/doctors/doctors.service.ts b/backend/src/doctors/doctors.service.ts index 89ce6272..fb94ed15 100644 --- a/backend/src/doctors/doctors.service.ts +++ b/backend/src/doctors/doctors.service.ts @@ -1,26 +1,22 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import { Prisma } from '@prisma/client'; import { PrismaService } from '../prisma/prisma.service'; +import { DoctorQueryDto } from './dto/doctor-query.dto'; -export class DoctorQuery { - page?: number | string; - limit?: number | string; - search?: string; - activeOnly?: boolean | string; -} +export { DoctorQueryDto as DoctorQuery }; @Injectable() export class DoctorsService { constructor(private readonly prisma: PrismaService) {} - async findAll(query: DoctorQuery = {}) { + async findAll(query: DoctorQueryDto = {}) { const page = Number(query.page) || 1; const limit = Number(query.limit) || 50; const skip = (page - 1) * limit; const where: Prisma.DoctorWhereInput = {}; - if (query.activeOnly === 'true' || query.activeOnly === true) { + if (query.activeOnly === true) { where.isActive = true; } diff --git a/backend/src/doctors/dto/doctor-query.dto.ts b/backend/src/doctors/dto/doctor-query.dto.ts new file mode 100644 index 00000000..36f7df83 --- /dev/null +++ b/backend/src/doctors/dto/doctor-query.dto.ts @@ -0,0 +1,38 @@ +import { ApiPropertyOptional } from '@nestjs/swagger'; +import { IsOptional, IsInt, Min, IsString, IsBoolean } from 'class-validator'; +import { Type, Transform } from 'class-transformer'; + +export class DoctorQueryDto { + @ApiPropertyOptional({ description: 'شماره صفحه', minimum: 1, default: 1 }) + @IsOptional() + @Type(() => Number) + @IsInt() + @Min(1) + page?: number = 1; + + @ApiPropertyOptional({ + description: 'تعداد آیتم در هر صفحه', + minimum: 1, + default: 50, + }) + @IsOptional() + @Type(() => Number) + @IsInt() + @Min(1) + limit?: number = 50; + + @ApiPropertyOptional({ description: 'عبارت جستجو' }) + @IsOptional() + @IsString() + search?: string; + + @ApiPropertyOptional({ description: 'فقط پزشکان فعال' }) + @IsOptional() + @Transform(({ value }) => { + if (value === 'true' || value === true) return true; + if (value === 'false' || value === false) return false; + return undefined; + }) + @IsBoolean() + activeOnly?: boolean; +} diff --git a/backend/src/faq/faq.controller.ts b/backend/src/faq/faq.controller.ts new file mode 100644 index 00000000..35b5de72 --- /dev/null +++ b/backend/src/faq/faq.controller.ts @@ -0,0 +1,89 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Body, + Param, + UseGuards, +} from '@nestjs/common'; +import { FaqService } from './faq.service'; +import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger'; +import { JwtAuthGuard } from '../auth/jwt-auth.guard'; +import { RolesGuard } from '../common/guards/roles.guard'; +import { Roles } from '../common/decorators/roles.decorator'; + +@ApiTags('FAQ - سوالات متداول') +@Controller('faq') +export class FaqController { + constructor(private readonly faqService: FaqService) {} + + @Get() + @ApiOperation({ summary: 'دریافت سوالات متداول فعال برای صفحه اصلی' }) + findActive() { + return this.faqService.findActive(); + } + + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('Admin') + @ApiBearerAuth() + @Get('admin') + @ApiOperation({ summary: 'دریافت تمام سوالات (ادمین)' }) + findAll() { + return this.faqService.findAll(); + } + + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('Admin') + @ApiBearerAuth() + @Post() + @ApiOperation({ summary: 'ایجاد سوال متداول جدید' }) + create( + @Body() + body: { + question: string; + answer: string; + order?: number; + isActive?: boolean; + }, + ) { + return this.faqService.create(body); + } + + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('Admin') + @ApiBearerAuth() + @Put('reorder') + @ApiOperation({ summary: 'مرتب‌سازی سوالات' }) + reorder(@Body() body: { items: { id: string; order: number }[] }) { + return this.faqService.reorder(body.items); + } + + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('Admin') + @ApiBearerAuth() + @Put(':id') + @ApiOperation({ summary: 'ویرایش سوال متداول' }) + update( + @Param('id') id: string, + @Body() + body: Partial<{ + question: string; + answer: string; + order: number; + isActive: boolean; + }>, + ) { + return this.faqService.update(id, body); + } + + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('Admin') + @ApiBearerAuth() + @Delete(':id') + @ApiOperation({ summary: 'حذف سوال متداول' }) + remove(@Param('id') id: string) { + return this.faqService.remove(id); + } +} diff --git a/backend/src/faq/faq.module.ts b/backend/src/faq/faq.module.ts new file mode 100644 index 00000000..b63c7e27 --- /dev/null +++ b/backend/src/faq/faq.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { FaqController } from './faq.controller'; +import { FaqService } from './faq.service'; + +@Module({ + controllers: [FaqController], + providers: [FaqService], +}) +export class FaqModule {} diff --git a/backend/src/faq/faq.service.ts b/backend/src/faq/faq.service.ts new file mode 100644 index 00000000..758c2c34 --- /dev/null +++ b/backend/src/faq/faq.service.ts @@ -0,0 +1,63 @@ +import { Injectable, NotFoundException } from '@nestjs/common'; +import { PrismaService } from '../prisma/prisma.service'; + +@Injectable() +export class FaqService { + constructor(private prisma: PrismaService) {} + + // Public: only active FAQs + async findActive() { + return this.prisma.fAQ.findMany({ + where: { isActive: true }, + orderBy: { order: 'asc' }, + }); + } + + // Admin: all FAQs + async findAll() { + return this.prisma.fAQ.findMany({ + orderBy: { order: 'asc' }, + }); + } + + async create(data: { + question: string; + answer: string; + order?: number; + isActive?: boolean; + }) { + return this.prisma.fAQ.create({ data }); + } + + async update( + id: string, + data: Partial<{ + question: string; + answer: string; + order: number; + isActive: boolean; + }>, + ) { + const faq = await this.prisma.fAQ.findUnique({ where: { id } }); + if (!faq) throw new NotFoundException('سوال یافت نشد'); + return this.prisma.fAQ.update({ where: { id }, data }); + } + + async remove(id: string) { + const faq = await this.prisma.fAQ.findUnique({ where: { id } }); + if (!faq) throw new NotFoundException('سوال یافت نشد'); + return this.prisma.fAQ.delete({ where: { id } }); + } + + async reorder(items: { id: string; order: number }[]) { + await Promise.all( + items.map((item) => + this.prisma.fAQ.update({ + where: { id: item.id }, + data: { order: item.order }, + }), + ), + ); + return { success: true }; + } +} diff --git a/backend/src/menu/menu.controller.ts b/backend/src/menu/menu.controller.ts new file mode 100644 index 00000000..8eeff03a --- /dev/null +++ b/backend/src/menu/menu.controller.ts @@ -0,0 +1,111 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Body, + Param, + Query, + UseGuards, +} from '@nestjs/common'; +import { MenuService } from './menu.service'; +import { + ApiTags, + ApiOperation, + ApiBearerAuth, + ApiQuery, +} from '@nestjs/swagger'; +import { JwtAuthGuard } from '../auth/jwt-auth.guard'; +import { RolesGuard } from '../common/guards/roles.guard'; +import { Roles } from '../common/decorators/roles.decorator'; + +@ApiTags('Menu - مدیریت منو') +@Controller('menu') +export class MenuController { + constructor(private readonly menuService: MenuService) {} + + @Get() + @ApiOperation({ summary: 'دریافت منو عمومی بر اساس نوع' }) + @ApiQuery({ + name: 'type', + required: true, + description: 'HEADER | FOOTER_COL1 | FOOTER_COL2 | FOOTER_COL3', + }) + findByType(@Query('type') type: string) { + return this.menuService.findByType(type); + } + + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('Admin') + @ApiBearerAuth() + @Get('admin') + @ApiOperation({ summary: 'دریافت تمام آیتم‌های منو (ادمین)' }) + @ApiQuery({ name: 'type', required: false }) + findAllAdmin(@Query('type') type?: string) { + return this.menuService.findAllAdmin(type); + } + + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('Admin') + @ApiBearerAuth() + @Post() + @ApiOperation({ summary: 'ایجاد آیتم منو جدید' }) + create( + @Body() + body: { + menuType: string; + label: string; + href: string; + parentId?: string; + order?: number; + isActive?: boolean; + isExternal?: boolean; + icon?: string; + badge?: string; + }, + ) { + return this.menuService.create(body); + } + + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('Admin') + @ApiBearerAuth() + @Put('reorder') + @ApiOperation({ summary: 'مرتب‌سازی آیتم‌های منو' }) + reorder(@Body() body: { items: { id: string; order: number }[] }) { + return this.menuService.reorder(body.items); + } + + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('Admin') + @ApiBearerAuth() + @Put(':id') + @ApiOperation({ summary: 'ویرایش آیتم منو' }) + update( + @Param('id') id: string, + @Body() + body: Partial<{ + menuType: string; + label: string; + href: string; + parentId: string | null; + order: number; + isActive: boolean; + isExternal: boolean; + icon: string; + badge: string; + }>, + ) { + return this.menuService.update(id, body); + } + + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('Admin') + @ApiBearerAuth() + @Delete(':id') + @ApiOperation({ summary: 'حذف آیتم منو' }) + remove(@Param('id') id: string) { + return this.menuService.remove(id); + } +} diff --git a/backend/src/menu/menu.module.ts b/backend/src/menu/menu.module.ts new file mode 100644 index 00000000..431d0ba7 --- /dev/null +++ b/backend/src/menu/menu.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { MenuController } from './menu.controller'; +import { MenuService } from './menu.service'; + +@Module({ + controllers: [MenuController], + providers: [MenuService], + exports: [MenuService], +}) +export class MenuModule {} diff --git a/backend/src/menu/menu.service.ts b/backend/src/menu/menu.service.ts new file mode 100644 index 00000000..8c7e20bc --- /dev/null +++ b/backend/src/menu/menu.service.ts @@ -0,0 +1,145 @@ +import { Injectable, NotFoundException, OnModuleInit } from '@nestjs/common'; +import { PrismaService } from '../prisma/prisma.service'; + +export type MenuType = 'HEADER' | 'FOOTER_COL1' | 'FOOTER_COL2' | 'FOOTER_COL3'; + +@Injectable() +export class MenuService implements OnModuleInit { + constructor(private prisma: PrismaService) {} + + async onModuleInit() { + await this.seedIfEmpty(); + } + + private async seedIfEmpty() { + const count = await this.prisma.menuItem.count(); + if (count > 0) return; + + // Seed with current site navigation + const headerItems = [ + { label: 'راهکارهای درمانی', href: '/shop?view=symptoms', order: 1 }, + { label: 'محصولات تخصصی', href: '/shop', order: 2 }, + { label: 'دانشنامه علمی', href: '/wiki', order: 3 }, + { label: 'مجله سلامت پت', href: '/blog', order: 4 }, + { label: 'شناسنامه پت‌ها', href: '/dashboard/pets', order: 5 }, + { label: 'ویدیوها', href: '/videos', order: 6 }, + ]; + + const footerCol1 = [ + { label: 'درباره کنینا آلمان', href: '/about', order: 1 }, + { label: 'تماس با ما', href: '/contact', order: 2 }, + { label: 'مجوزها و گواهی‌ها', href: '/trust-seals', order: 3 }, + { label: 'حریم خصوصی', href: '/privacy', order: 4 }, + ]; + + const footerCol2 = [ + { label: 'فروشگاه تخصصی', href: '/shop', order: 1 }, + { label: 'دستهٔ‌بندی درمانی', href: '/shop?view=symptoms', order: 2 }, + { label: 'دانشنامه علمی', href: '/wiki', order: 3 }, + { label: 'مجله سلامت پت', href: '/blog', order: 4 }, + ]; + + const footerCol3 = [ + { label: 'شناسنامه پت‌ها', href: '/dashboard/pets', order: 1 }, + { label: 'سفارشات من', href: '/dashboard/orders', order: 2 }, + { label: 'ردیابی سفارش', href: '/track', order: 3 }, + { label: 'ورود / ثبت‌نام', href: '/?login=1', order: 4 }, + ]; + + const createItems = (items: typeof headerItems, menuType: MenuType) => + items.map((item) => ({ + ...item, + menuType, + isActive: true, + isExternal: false, + })); + + await this.prisma.menuItem.createMany({ + data: [ + ...createItems(headerItems, 'HEADER'), + ...createItems(footerCol1, 'FOOTER_COL1'), + ...createItems(footerCol2, 'FOOTER_COL2'), + ...createItems(footerCol3, 'FOOTER_COL3'), + ], + }); + } + + async findByType(menuType: string) { + const items = await this.prisma.menuItem.findMany({ + where: { menuType, isActive: true, parentId: null }, + orderBy: { order: 'asc' }, + include: { + children: { + where: { isActive: true }, + orderBy: { order: 'asc' }, + }, + }, + }); + return items; + } + + async findAllAdmin(menuType?: string) { + return this.prisma.menuItem.findMany({ + where: menuType ? { menuType } : undefined, + orderBy: [{ menuType: 'asc' }, { order: 'asc' }], + include: { + children: { + orderBy: { order: 'asc' }, + }, + }, + }); + } + + async create(data: { + menuType: string; + label: string; + href: string; + parentId?: string; + order?: number; + isActive?: boolean; + isExternal?: boolean; + icon?: string; + badge?: string; + }) { + return this.prisma.menuItem.create({ data }); + } + + async update( + id: string, + data: Partial<{ + menuType: string; + label: string; + href: string; + parentId: string | null; + order: number; + isActive: boolean; + isExternal: boolean; + icon: string; + badge: string; + }>, + ) { + const item = await this.prisma.menuItem.findUnique({ where: { id } }); + if (!item) throw new NotFoundException('Menu item not found'); + return this.prisma.menuItem.update({ where: { id }, data }); + } + + async remove(id: string) { + const item = await this.prisma.menuItem.findUnique({ where: { id } }); + if (!item) throw new NotFoundException('Menu item not found'); + // Delete children first + await this.prisma.menuItem.deleteMany({ where: { parentId: id } }); + return this.prisma.menuItem.delete({ where: { id } }); + } + + async reorder(items: { id: string; order: number }[]) { + await Promise.all( + items.map((item) => + this.prisma.menuItem.update({ + where: { id: item.id }, + data: { order: item.order }, + }), + ), + ); + return { success: true }; + } +} diff --git a/backend/src/settings/default-ui-texts.ts b/backend/src/settings/default-ui-texts.ts index aae60c6a..09f49e4b 100644 --- a/backend/src/settings/default-ui-texts.ts +++ b/backend/src/settings/default-ui-texts.ts @@ -167,88 +167,133 @@ export const DEFAULT_UI_TEXTS: Record = { title_separator: '|', title_position: 'suffix', defaultMetaTitle: 'کنینا ایران | نماینده رسمی مکمل‌های دارویی Canina آلمان', - defaultMetaDescription: 'فروشگاه تخصصی و نماینده انحصاری مکمل‌های درمانی و تقویتی سگ و گربه کنینا آلمان با فرمولاسیون دارویی و تاییدیه بالینی.', + defaultMetaDescription: + 'فروشگاه تخصصی و نماینده انحصاری مکمل‌های درمانی و تقویتی سگ و گربه کنینا آلمان با فرمولاسیون دارویی و تاییدیه بالینی.', canonicalBaseUrl: 'https://canina.ir', ogImageUrl: '/assets/images/regenerated_image_1779109861747.png', // === Page-by-Page SEO Metadata Defaults === home_meta_title: 'کنینا ایران | نماینده رسمی مکمل‌های دارویی Canina آلمان', - home_meta_desc: 'فروشگاه تخصصی و نماینده انحصاری مکمل‌های درمانی و تقویتی سگ و گربه کنینا آلمان با فرمولاسیون دارویی و تاییدیه بالینی.', - home_keywords: 'کنینا, مکمل سگ, مکمل گربه, مکمل دارویی حیوانات, Canina Germany', + home_meta_desc: + 'فروشگاه تخصصی و نماینده انحصاری مکمل‌های درمانی و تقویتی سگ و گربه کنینا آلمان با فرمولاسیون دارویی و تاییدیه بالینی.', + home_keywords: + 'کنینا, مکمل سگ, مکمل گربه, مکمل دارویی حیوانات, Canina Germany', home_canonical: 'https://canina.ir', shop_meta_title: 'فروشگاه تخصصی مکمل‌های دارویی سگ و گربه', - shop_meta_desc: 'خرید آنلاین انواع مکمل‌های درمانی مفاصل، پوست و مو، گوارش و ایمنی، رشد و ویتامینه سگ و گربه با ضمانت اصالت کنینا آلمان.', - shop_keywords: 'خرید مکمل سگ, خرید مکمل گربه, مکمل مفاصل پت, پت شاپ تخصصی دارویی', + shop_meta_desc: + 'خرید آنلاین انواع مکمل‌های درمانی مفاصل، پوست و مو، گوارش و ایمنی، رشد و ویتامینه سگ و گربه با ضمانت اصالت کنینا آلمان.', + shop_keywords: + 'خرید مکمل سگ, خرید مکمل گربه, مکمل مفاصل پت, پت شاپ تخصصی دارویی', shop_canonical: 'https://canina.ir/shop', catalog_meta_title: 'کاتالوگ رسمی مکمل‌های درمانی و دارویی', - catalog_meta_desc: 'مشاهده و مطالعه کاتالوگ جامع دارویی و مکمل‌های تغذیه‌ای تخصصی کنینا آلمان با قابلیت ورق‌زدن تعاملی و ثبت پیش‌خرید.', - catalog_keywords: 'کاتالوگ کنینا, کاتالوگ محصولات Canina, راهنمای مکمل‌های دارویی پت', + catalog_meta_desc: + 'مشاهده و مطالعه کاتالوگ جامع دارویی و مکمل‌های تغذیه‌ای تخصصی کنینا آلمان با قابلیت ورق‌زدن تعاملی و ثبت پیش‌خرید.', + catalog_keywords: + 'کاتالوگ کنینا, کاتالوگ محصولات Canina, راهنمای مکمل‌های دارویی پت', catalog_canonical: 'https://canina.ir/catalog', blog_meta_title: 'مجله سلامت و دانشنامه مقالات تخصصی پت', - blog_meta_desc: 'جدیدترین مقالات علمی، راهنمای تغذیه، بیماری‌های سگ و گربه و توصیه‌های بالینی متخصصان و دامپزشکان کنینا.', - blog_keywords: 'مقالات سگ و گربه, مجله سلامت حیوانات, تغذیه پت, بیماریهای سگ و گربه', + blog_meta_desc: + 'جدیدترین مقالات علمی، راهنمای تغذیه، بیماری‌های سگ و گربه و توصیه‌های بالینی متخصصان و دامپزشکان کنینا.', + blog_keywords: + 'مقالات سگ و گربه, مجله سلامت حیوانات, تغذیه پت, بیماریهای سگ و گربه', blog_canonical: 'https://canina.ir/blog', wiki_meta_title: 'دانشنامه علمی ترکیبات و اصطلاحات دارویی', - wiki_meta_desc: 'مرجع تخصصی اثرات بالینی، مواد تشکیل‌دهنده، ویتامین‌ها و ترکیبات ارگانیک به کار رفته در مکمل‌های دارویی کنینا آلمان.', - wiki_keywords: 'دانشنامه دارویی پت, ترکیبات مکمل سگ, گلوکوزامین سگ, صدف سبز نیوزیلند', + wiki_meta_desc: + 'مرجع تخصصی اثرات بالینی، مواد تشکیل‌دهنده، ویتامین‌ها و ترکیبات ارگانیک به کار رفته در مکمل‌های دارویی کنینا آلمان.', + wiki_keywords: + 'دانشنامه دارویی پت, ترکیبات مکمل سگ, گلوکوزامین سگ, صدف سبز نیوزیلند', wiki_canonical: 'https://canina.ir/wiki', about_meta_title: 'درباره شرکت کنینا ایران و اصالت آلمانی', - about_meta_desc: 'داستان کنینا ایران و بیش از ۴۰ سال سابقه درخشان شرکت Canina pharma GmbH آلمان در تولید مکمل‌های فوق‌تخصصی دامپزشکی.', - about_keywords: 'درباره کنینا, شرکت Canina pharma, تاریخچه مکمل کنینا, استاندارد دارویی آلمان', + about_meta_desc: + 'داستان کنینا ایران و بیش از ۴۰ سال سابقه درخشان شرکت Canina pharma GmbH آلمان در تولید مکمل‌های فوق‌تخصصی دامپزشکی.', + about_keywords: + 'درباره کنینا, شرکت Canina pharma, تاریخچه مکمل کنینا, استاندارد دارویی آلمان', about_canonical: 'https://canina.ir/about', contact_meta_title: 'تماس با ما و مشاوره تخصصی دامپزشکی', - contact_meta_desc: 'راه‌های ارتباطی با دفتر مرکزی کنینا ایران، مشاوره تلفنی رایگان، پشتیبانی آنلاین و نشانی.', + contact_meta_desc: + 'راه‌های ارتباطی با دفتر مرکزی کنینا ایران، مشاوره تلفنی رایگان، پشتیبانی آنلاین و نشانی.', contact_keywords: 'تماس با کنینا, پشتیبانی کنینا ایران, مشاوره دارویی پت', contact_canonical: 'https://canina.ir/contact', b2b_meta_title: 'پرتال همکاران تجاری، کلینیک‌ها و پت‌شاپ‌ها', - b2b_meta_desc: 'ثبت‌نام و خرید عمده مکمل‌های دارویی کنینا ویژه کلینیک‌های دامپزشکی، بیمارستان‌ها و پت‌شاپ‌های سراسر کشور با تخفیف سازمانی.', + b2b_meta_desc: + 'ثبت‌نام و خرید عمده مکمل‌های دارویی کنینا ویژه کلینیک‌های دامپزشکی، بیمارستان‌ها و پت‌شاپ‌های سراسر کشور با تخفیف سازمانی.', b2b_keywords: 'خرید عمده مکمل پت, نمایندگی کنینا, فروش سازمانی دامپزشکی', b2b_canonical: 'https://canina.ir/b2b', videos_meta_title: 'ویدئوهای آموزشی و توصیه‌های بالینی دامپزشکان', - videos_meta_desc: 'مشاهده ویدئوهای تخصصی نحوه مصرف مکمل‌های درمانی، نظرات دامپزشکان و راهکارهای بالینی تصویری.', - videos_keywords: 'ویدیوهای آموزشی پت, راهنمای مصرف مکمل سگ, فیلم های دامپزشکی', + videos_meta_desc: + 'مشاهده ویدئوهای تخصصی نحوه مصرف مکمل‌های درمانی، نظرات دامپزشکان و راهکارهای بالینی تصویری.', + videos_keywords: + 'ویدیوهای آموزشی پت, راهنمای مصرف مکمل سگ, فیلم های دامپزشکی', videos_canonical: 'https://canina.ir/videos', search_meta_title: 'جستجوی هوشمند مکمل‌ها و دانشنامه سلامت', - search_meta_desc: 'جستجوی سریع در کاتالوگ محصولات، بیماری‌ها، علائم بالینی و مقالات سلامت کنینا ایران.', + search_meta_desc: + 'جستجوی سریع در کاتالوگ محصولات، بیماری‌ها، علائم بالینی و مقالات سلامت کنینا ایران.', search_keywords: 'جستجوی داروی پت, سرچ مکمل کنینا', search_canonical: 'https://canina.ir/search', dashboard_meta_title: 'داشبورد کاربری و پیگیری سفارشات', - dashboard_meta_desc: 'مشاهده تاریخچه خریدها، وضعیت کیف پول، پیگیری آنلاین بسته‌های پستی و مدیریت پت‌ها.', + dashboard_meta_desc: + 'مشاهده تاریخچه خریدها، وضعیت کیف پول، پیگیری آنلاین بسته‌های پستی و مدیریت پت‌ها.', dashboard_keywords: 'داشبورد کاربری, پروفایل کنینا', dashboard_canonical: 'https://canina.ir/dashboard', profile_pets_meta_title: 'پرونده الکترونیک سلامت پت', - profile_pets_meta_desc: 'مدیریت و ثبت پرونده سلامت سگ و گربه، تنظیم یادآورهای دوز دارو و تاریخچه تغذیه مکمل‌ها.', + profile_pets_meta_desc: + 'مدیریت و ثبت پرونده سلامت سگ و گربه، تنظیم یادآورهای دوز دارو و تاریخچه تغذیه مکمل‌ها.', profile_pets_keywords: 'پرونده سلامت سگ, یادآور داروی پت, شناسنامه گربه', profile_pets_canonical: 'https://canina.ir/profile', checkout_meta_title: 'تسویه‌حساب و پرداخت امن', - checkout_meta_desc: 'انتخاب آدرس تحویل، روش ارسال و تسویه‌حساب سریع و امن سفارشات مکمل‌های کنینا.', + checkout_meta_desc: + 'انتخاب آدرس تحویل، روش ارسال و تسویه‌حساب سریع و امن سفارشات مکمل‌های کنینا.', checkout_keywords: 'خرید آنلاین مکمل, پرداخت سفارش', checkout_canonical: 'https://canina.ir/checkout', track_meta_title: 'پیگیری آنلاین سفارش و مرسوله پستی', - track_meta_desc: 'پیگیری وضعیت لحظه‌ای پردازش، بسته‌بندی و کد رهگیری پست پیشتاز سفارشات کنینا ایران.', + track_meta_desc: + 'پیگیری وضعیت لحظه‌ای پردازش، بسته‌بندی و کد رهگیری پست پیشتاز سفارشات کنینا ایران.', track_keywords: 'رهگیری پست پیشتاز, پیگیری سفارش کنینا', track_canonical: 'https://canina.ir/track', trust_seals_meta_title: 'مجوزهای رسمی، گواهی اصالت و اینماد', - trust_seals_meta_desc: 'بررسی تاییدیه‌های رسمی سازمان دامپزشکی کشور، گواهی استاندارد آلمان و اینماد رسمی کنینا ایران.', + trust_seals_meta_desc: + 'بررسی تاییدیه‌های رسمی سازمان دامپزشکی کشور، گواهی استاندارد آلمان و اینماد رسمی کنینا ایران.', trust_seals_keywords: 'اینماد کنینا, مجوز دامپزشکی مکمل, اصالت کالا کنینا', trust_seals_canonical: 'https://canina.ir/trust-seals', privacy_meta_title: 'حریم خصوصی و شرایط استفاده', - privacy_meta_desc: 'سیاست‌های حفاظت از اطلاعات شخصی کاربران، امنیت داده‌های پزشکی و قوانین استفاده از خدمات کنینا ایران.', + privacy_meta_desc: + 'سیاست‌های حفاظت از اطلاعات شخصی کاربران، امنیت داده‌های پزشکی و قوانین استفاده از خدمات کنینا ایران.', privacy_keywords: 'قوانین کنینا, شرایط مرجوعی, حریم خصوصی', privacy_canonical: 'https://canina.ir/privacy', + + // === Testimonials Section (Homepage) === + testimonials_badge: 'صداهای واقعی، تجربه‌های اصیل', + testimonials_title: 'مشتریان کنینا چه می‌گویند؟', + testimonials_subtitle: + 'نظرات صادقانه صاحبان پت که از محصولات تخصصی کنینا استفاده کرده‌اند', + + // === Blog Preview Section (Homepage) === + blog_preview_badge: 'آخرین مطالب تخصصی', + blog_preview_title: 'مجله سلامت پت کنینا', + blog_preview_subtitle: + 'مقالات علمی و تخصصی دامپزشکی برای مراقبت بهتر از حیوان خانگی شما', + blog_preview_read_more: 'مشاهده همه مقالات', + blog_preview_read_article: 'خواندن مقاله', + blog_preview_views: 'بازدید', + blog_preview_comments: 'نظر', + + // === FAQ Section (Homepage) === + faq_badge: 'سوالات پرتکرار', + faq_title: 'سوالات متداول', + faq_subtitle: 'پاسخ سوالاتی که اغلب از ما می‌پرسید', }; diff --git a/backend/src/settings/settings.service.ts b/backend/src/settings/settings.service.ts index 132c5a72..af0db206 100644 --- a/backend/src/settings/settings.service.ts +++ b/backend/src/settings/settings.service.ts @@ -513,10 +513,14 @@ export class SettingsService implements OnModuleInit { updates['brand_name_en'] = brandEn; } if (obj.titleSeparator || obj.title_separator) { - updates['title_separator'] = String(obj.titleSeparator || obj.title_separator); + updates['title_separator'] = String( + obj.titleSeparator || obj.title_separator, + ); } if (obj.titlePosition || obj.title_position) { - updates['title_position'] = String(obj.titlePosition || obj.title_position); + updates['title_position'] = String( + obj.titlePosition || obj.title_position, + ); } if (obj.defaultMetaTitle) { updates['defaultMetaTitle'] = String(obj.defaultMetaTitle); diff --git a/backend/src/testimonials/testimonials.controller.ts b/backend/src/testimonials/testimonials.controller.ts index e156d4c5..07d14e20 100644 --- a/backend/src/testimonials/testimonials.controller.ts +++ b/backend/src/testimonials/testimonials.controller.ts @@ -26,6 +26,12 @@ export class TestimonialsController { return this.testimonialsService.findAll(); } + @Get('homepage') + @ApiOperation({ summary: 'دریافت نظرات فعال برای نمایش در صفحه اصلی' }) + findHomepage() { + return this.testimonialsService.findHomepage(); + } + @UseGuards(JwtAuthGuard, RolesGuard) @Roles('Admin') @ApiBearerAuth() diff --git a/backend/src/testimonials/testimonials.service.ts b/backend/src/testimonials/testimonials.service.ts index 9909bba4..f118b6d8 100644 --- a/backend/src/testimonials/testimonials.service.ts +++ b/backend/src/testimonials/testimonials.service.ts @@ -12,6 +12,13 @@ export class TestimonialsService { }); } + async findHomepage() { + return this.prisma.testimonial.findMany({ + where: { isActive: true, showOnHome: true }, + orderBy: { order: 'asc' }, + }); + } + async create(data: Prisma.TestimonialCreateInput) { return this.prisma.testimonial.create({ data, diff --git a/frontend/admin-panel/eslint.config.js b/frontend/admin-panel/eslint.config.js index ef614d25..f1d11a18 100644 --- a/frontend/admin-panel/eslint.config.js +++ b/frontend/admin-panel/eslint.config.js @@ -18,5 +18,12 @@ export default defineConfig([ languageOptions: { globals: globals.browser, }, + rules: { + '@typescript-eslint/no-explicit-any': 'warn', + '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }], + 'react-hooks/set-state-in-effect': 'off', + 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], + }, }, ]) + diff --git a/frontend/admin-panel/src/components/Sidebar.tsx b/frontend/admin-panel/src/components/Sidebar.tsx index 273bd610..6d5de8c1 100644 --- a/frontend/admin-panel/src/components/Sidebar.tsx +++ b/frontend/admin-panel/src/components/Sidebar.tsx @@ -32,6 +32,8 @@ import { ChevronDown, Star, Layers, + HelpCircle, + Menu, } from 'lucide-react'; import api from '../services/api'; @@ -146,6 +148,8 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) { { icon: UserCheck, label: 'پزشکان و کادر علمی', path: '/doctors' }, { icon: MessageSquareQuote, label: 'نظرات و گواهی متخصصان', path: '/testimonials' }, { icon: Video, label: 'ویدئوها و آموزش‌ها', path: '/videos' }, + { icon: HelpCircle, label: 'سوالات متداول (FAQ)', path: '/faq' }, + { icon: Menu, label: 'مدیریت منو و فوتر', path: '/menu' }, { icon: Image, label: 'کتابخانه رسانه', path: '/media' }, ], }, diff --git a/frontend/admin-panel/src/pages/FAQManager.tsx b/frontend/admin-panel/src/pages/FAQManager.tsx new file mode 100644 index 00000000..ebf99212 --- /dev/null +++ b/frontend/admin-panel/src/pages/FAQManager.tsx @@ -0,0 +1,316 @@ +import { useState, useEffect, useCallback } from 'react'; +import { HelpCircle, Plus, Edit2, Trash2, X, GripVertical, ToggleLeft, ToggleRight } from 'lucide-react'; +import { toast } from 'react-hot-toast'; +import api from '../services/api'; +import Spinner from '../components/ui/Spinner'; +import ConfirmModal from '../components/ui/ConfirmModal'; + +interface FAQ { + id: string; + question: string; + answer: string; + order: number; + isActive: boolean; + createdAt: string; + updatedAt: string; +} + +export default function FAQManager() { + const [faqs, setFaqs] = useState([]); + const [isLoading, setIsLoading] = useState(true); + const [isModalOpen, setIsModalOpen] = useState(false); + const [editingFaq, setEditingFaq] = useState(null); + const [deleteTargetId, setDeleteTargetId] = useState(null); + const [isSaving, setIsSaving] = useState(false); + + const [formData, setFormData] = useState({ + question: '', + answer: '', + order: 0, + isActive: true, + }); + + const fetchFaqs = useCallback(async () => { + try { + setIsLoading(true); + const res = await api.get('/faq/admin'); + const data = Array.isArray(res.data) ? res.data : (res.data?.data || []); + setFaqs(data); + } catch (err) { + console.error('Failed to fetch FAQs:', err); + toast.error('خطا در دریافت سوالات متداول'); + } finally { + setIsLoading(false); + } + }, []); + + useEffect(() => { + fetchFaqs(); + }, [fetchFaqs]); + + const openModal = (item: FAQ | null = null) => { + if (item) { + setEditingFaq(item); + setFormData({ + question: item.question, + answer: item.answer, + order: item.order, + isActive: item.isActive, + }); + } else { + setEditingFaq(null); + setFormData({ + question: '', + answer: '', + order: faqs.length, + isActive: true, + }); + } + setIsModalOpen(true); + }; + + const handleSave = async (e: React.FormEvent) => { + e.preventDefault(); + if (!formData.question.trim() || !formData.answer.trim()) { + toast.error('سوال و جواب اجباری هستند'); + return; + } + try { + setIsSaving(true); + if (editingFaq) { + await api.put(`/faq/${editingFaq.id}`, formData); + toast.success('سوال با موفقیت بروزرسانی شد'); + } else { + await api.post('/faq', formData); + toast.success('سوال جدید اضافه شد'); + } + setIsModalOpen(false); + fetchFaqs(); + } catch (err) { + console.error('Failed to save FAQ:', err); + toast.error('خطا در ذخیره سوال'); + } finally { + setIsSaving(false); + } + }; + + const toggleActive = async (item: FAQ) => { + try { + await api.put(`/faq/${item.id}`, { isActive: !item.isActive }); + toast.success(item.isActive ? 'غیرفعال شد' : 'فعال شد'); + fetchFaqs(); + } catch { + toast.error('خطا در تغییر وضعیت'); + } + }; + + const confirmDelete = async () => { + if (!deleteTargetId) return; + try { + await api.delete(`/faq/${deleteTargetId}`); + toast.success('سوال حذف شد'); + fetchFaqs(); + } catch { + toast.error('خطا در حذف'); + } finally { + setDeleteTargetId(null); + } + }; + + return ( +
+
+
+

+ + سوالات متداول (FAQ) +

+

+ سوالات و پاسخ‌هایی که در صفحه اصلی سایت نمایش داده می‌شوند — با Schema.org FAQPage برای SEO +

+
+ +
+ + {/* Info Box */} +
+ 💡 نکته SEO: سوالات فعال به صورت خودکار با markup FAQPage در صفحه اصلی نمایش داده می‌شوند و در نتایج گوگل به عنوان Rich Snippet ظاهر می‌شوند. +
+ + {/* List */} +
+ {isLoading ? ( +
+ +
+ ) : faqs.length === 0 ? ( +
+ +

هیچ سوالی ثبت نشده است

+ +
+ ) : ( + faqs.map((faq, idx) => ( +
+
+
+ + {idx + 1} +
+
+
+ {faq.question} + {!faq.isActive && ( + + غیرفعال + + )} +
+

{faq.answer}

+
+
+ + + +
+
+
+ )) + )} +
+ + {/* Form Modal */} + {isModalOpen && ( +
+
+
+

+ {editingFaq ? 'ویرایش سوال متداول' : 'افزودن سوال جدید'} +

+ +
+ +
+
+ + setFormData({ ...formData, question: e.target.value })} + placeholder="مثال: آیا محصولات کنینا برای سگ‌های حساس مناسب است؟" + className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-orange-400 outline-none text-sm" + /> +
+ +
+ +