feat(governance): implement CEO approvals gate with sandbox test and Hermes bidirectional bridge
This commit is contained in:
1 parent
7f10dad448
commit
5486e746a2
8 files changed
+651
-1
No files matched your search
@@ -976,3 +976,26 @@ model SmsCampaign {
|
||||
@@index([createdAt])
|
||||
@@map("sms_campaigns")
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// 5. ApprovalRequest (CEO Governance & Decision Gate)
|
||||
// ------------------------------------------------------------------------------
|
||||
model ApprovalRequest {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
department String @db.VarChar(50)
|
||||
category String @db.VarChar(50)
|
||||
title String @db.VarChar(255)
|
||||
payload Json @db.JsonB
|
||||
testContext Json? @map("test_context") @db.JsonB
|
||||
status String @default("PENDING") @db.VarChar(30)
|
||||
ceoNotes String? @map("ceo_notes") @db.Text
|
||||
executedAt DateTime? @map("executed_at") @db.Timestamptz()
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
|
||||
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
|
||||
|
||||
@@index([department])
|
||||
@@index([category])
|
||||
@@index([status])
|
||||
@@index([createdAt])
|
||||
@@map("approval_requests")
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import { CompetitorPricingController } from "./competitor-pricing.controller";
|
||||
import { B2BLeadsController } from "./b2b-leads.controller";
|
||||
import { PricingSuggestionsController } from "./pricing-suggestions.controller";
|
||||
import { SmsCampaignsController } from "./sms-campaigns.controller";
|
||||
import { ApprovalsController } from "./approvals.controller";
|
||||
import { PrismaModule } from "../prisma/prisma.module";
|
||||
import { RedisModule } from "../redis/redis.module";
|
||||
import { SettingsModule } from "../settings/settings.module";
|
||||
@@ -41,6 +42,7 @@ import { SettingsModule } from "../settings/settings.module";
|
||||
B2BLeadsController,
|
||||
PricingSuggestionsController,
|
||||
SmsCampaignsController,
|
||||
ApprovalsController,
|
||||
],
|
||||
providers: [
|
||||
AdminService,
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
NotFoundException,
|
||||
BadRequestException,
|
||||
} from "@nestjs/common";
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from "@nestjs/swagger";
|
||||
import { JwtAuthGuard } from "../auth/jwt-auth.guard";
|
||||
import { RolesGuard } from "../common/guards/roles.guard";
|
||||
import { Roles } from "../common/decorators/roles.decorator";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
import {
|
||||
CreateApprovalRequestDto,
|
||||
DecideApprovalDto,
|
||||
QueryApprovalDto,
|
||||
} from "./dto/approval-request.dto";
|
||||
|
||||
@ApiTags("Admin - CEO Approvals & Governance")
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles("Admin", "SUPER_ADMIN")
|
||||
@Controller("admin/approvals")
|
||||
export class ApprovalsController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: "لیست موارد کارتابل تاییدات مدیریت" })
|
||||
async findAll(@Query() query: QueryApprovalDto) {
|
||||
const page = Number(query.page) || 1;
|
||||
const limit = Number(query.limit) || 20;
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const where: any = {};
|
||||
if (query.department) where.department = query.department;
|
||||
if (query.category) where.category = query.category;
|
||||
if (query.status) where.status = query.status;
|
||||
|
||||
const [total, items, pendingCount] = await Promise.all([
|
||||
(this.prisma as any).approvalRequest.count({ where }),
|
||||
(this.prisma as any).approvalRequest.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
}),
|
||||
(this.prisma as any).approvalRequest.count({
|
||||
where: { status: "PENDING" },
|
||||
}),
|
||||
]);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: items,
|
||||
meta: {
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
pendingCount,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "دریافت جزییات یک آیتم کارتابل" })
|
||||
async findOne(@Param("id") id: string) {
|
||||
const item = await (this.prisma as any).approvalRequest.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
if (!item) {
|
||||
throw new NotFoundException(`Approval request ${id} not found`);
|
||||
}
|
||||
return { success: true, data: item };
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: "ثبت آیتم جدید جهت تایید مدیریت (از طرف سیستم یا دپارتمانها)" })
|
||||
async create(@Body() dto: CreateApprovalRequestDto) {
|
||||
const item = await (this.prisma as any).approvalRequest.create({
|
||||
data: {
|
||||
department: dto.department,
|
||||
category: dto.category,
|
||||
title: dto.title,
|
||||
payload: dto.payload,
|
||||
testContext: dto.testContext || {},
|
||||
status: "PENDING",
|
||||
},
|
||||
});
|
||||
return { success: true, data: item };
|
||||
}
|
||||
|
||||
@Post(":id/test")
|
||||
@ApiOperation({ summary: "اجرای شبیهسازی تست زنده برای آیتم کارتابل" })
|
||||
async runTestSimulation(@Param("id") id: string) {
|
||||
const item = await (this.prisma as any).approvalRequest.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
if (!item) {
|
||||
throw new NotFoundException(`Approval request ${id} not found`);
|
||||
}
|
||||
|
||||
// شبیهسازی بسته به دستهبندی
|
||||
let testResult: any = { status: "SIMULATION_SUCCESS" };
|
||||
if (item.category === "PRICING") {
|
||||
const payload = item.payload as any;
|
||||
testResult = {
|
||||
impact: "Price change simulation",
|
||||
currentPrice: payload.currentPrice,
|
||||
newPrice: payload.newPrice,
|
||||
marginDiff: payload.newPrice && payload.buyPrice
|
||||
? (((payload.newPrice - payload.buyPrice) / payload.newPrice) * 100).toFixed(1) + "%"
|
||||
: "N/A",
|
||||
torobFeedReflectEstimate: "< 5 seconds",
|
||||
};
|
||||
} else if (item.category === "PURCHASE_ORDER") {
|
||||
const payload = item.payload as any;
|
||||
testResult = {
|
||||
document: "PO Pre-check",
|
||||
itemsCount: payload.items ? payload.items.length : 1,
|
||||
totalEstimatedCost: payload.totalCost || "محاسبه بر اساس نرخ خرید",
|
||||
fulfillmentCapacity: "انبار آماده پذیرش",
|
||||
};
|
||||
} else {
|
||||
testResult = {
|
||||
executionSafe: true,
|
||||
summary: "تست سلامت اولیه و اعتبارسنجی مقادیر با موفقیت انجام شد.",
|
||||
};
|
||||
}
|
||||
|
||||
return { success: true, testResult };
|
||||
}
|
||||
|
||||
@Put(":id/decide")
|
||||
@ApiOperation({ summary: "تصمیمگیری مدیرعامل (تایید یا رد همراه با یادداشت)" })
|
||||
async decide(@Param("id") id: string, @Body() dto: DecideApprovalDto) {
|
||||
if (!["APPROVED", "REJECTED"].includes(dto.decision)) {
|
||||
throw new BadRequestException("Decision must be either APPROVED or REJECTED");
|
||||
}
|
||||
|
||||
const item = await (this.prisma as any).approvalRequest.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
if (!item) {
|
||||
throw new NotFoundException(`Approval request ${id} not found`);
|
||||
}
|
||||
|
||||
const updated = await (this.prisma as any).approvalRequest.update({
|
||||
where: { id },
|
||||
data: {
|
||||
status: dto.decision,
|
||||
ceoNotes: dto.ceoNotes || null,
|
||||
executedAt: dto.decision === "APPROVED" ? new Date() : null,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: dto.decision === "APPROVED" ? "درخواست با موفقیت تایید شد." : "درخواست رد شد.",
|
||||
data: updated,
|
||||
};
|
||||
}
|
||||
|
||||
@Delete(":id")
|
||||
@ApiOperation({ summary: "حذف آیتم از کارتابل" })
|
||||
async remove(@Param("id") id: string) {
|
||||
await (this.prisma as any).approvalRequest.delete({ where: { id } });
|
||||
return { success: true, message: "Deleted successfully" };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsString, IsOptional, IsObject } from "class-validator";
|
||||
|
||||
export class CreateApprovalRequestDto {
|
||||
@ApiProperty({ description: "دپارتمان مبدا (DEV, SUPPLY, FINANCE, SEO, CRM, CONTENT)" })
|
||||
@IsString()
|
||||
department: string;
|
||||
|
||||
@ApiProperty({ description: "دستهبندی (PRICING, PURCHASE_ORDER, CAMPAIGN, DEPLOY, etc)" })
|
||||
@IsString()
|
||||
category: string;
|
||||
|
||||
@ApiProperty({ description: "عنوان مورد تایید" })
|
||||
@IsString()
|
||||
title: string;
|
||||
|
||||
@ApiProperty({ description: "دادههای تغییرات پیشنهادی" })
|
||||
@IsObject()
|
||||
payload: Record<string, any>;
|
||||
|
||||
@ApiPropertyOptional({ description: "دادههای سناریوی تست و ارزیابی" })
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
testContext?: Record<string, any>;
|
||||
}
|
||||
|
||||
export class DecideApprovalDto {
|
||||
@ApiProperty({ description: "تصمیم: APPROVED یا REJECTED" })
|
||||
@IsString()
|
||||
decision: "APPROVED" | "REJECTED";
|
||||
|
||||
@ApiPropertyOptional({ description: "توضیحات و یادداشت مدیرعامل" })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
ceoNotes?: string;
|
||||
}
|
||||
|
||||
export class QueryApprovalDto {
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
department?: string;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
category?: string;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
status?: string;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
page?: number;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
limit?: number;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { Injectable, Logger } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class HermesClientService {
|
||||
private readonly logger = new Logger(HermesClientService.name);
|
||||
private readonly baseUrl: string;
|
||||
private readonly apiKey: string;
|
||||
|
||||
constructor() {
|
||||
this.baseUrl = process.env.HERMES_GATEWAY_URL || "http://canina-bot:8642";
|
||||
this.apiKey = process.env.HERMES_API_KEY || process.env.API_SERVER_KEY || "";
|
||||
}
|
||||
|
||||
async checkHealth(): Promise<boolean> {
|
||||
try {
|
||||
const res = await fetch(`${this.baseUrl}/v1/health`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.apiKey}`,
|
||||
},
|
||||
});
|
||||
return res.status === 200;
|
||||
} catch (error: any) {
|
||||
this.logger.error(`Hermes health check failed: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async triggerEvent(eventName: string, payload: Record<string, any>) {
|
||||
try {
|
||||
this.logger.log(`Dispatching event ${eventName} to Hermes Gateway`);
|
||||
const res = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: "hermes-agent",
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: `[EVENT:${eventName}] ${JSON.stringify(payload)}`,
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
return { success: true, data };
|
||||
} catch (error: any) {
|
||||
this.logger.warn(`Could not dispatch event to Hermes: ${error.message}`);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
Activity,
|
||||
CheckSquare,
|
||||
BookOpen,
|
||||
Building2,
|
||||
ChevronDown,
|
||||
@@ -109,12 +110,22 @@ export default function Sidebar({ isOpen, setIsOpen, isCollapsed = false }: Side
|
||||
{ icon: TrendingUp, label: 'گزارشات و تحلیل فروش', path: '/reports' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'governance',
|
||||
title: 'حاکمیت و تاییدات مدیریت',
|
||||
icon: CheckSquare,
|
||||
items: [
|
||||
{ icon: CheckSquare, label: 'کارتابل تاییدات مدیریت', path: '/approvals' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'monitoring',
|
||||
title: 'مرکز مانیتورینگ و سلامت',
|
||||
icon: Activity,
|
||||
CheckSquare,
|
||||
items: [
|
||||
{ icon: Activity, label: 'مانیتورینگ زنده سرویسها', path: '/monitoring' },
|
||||
{ icon: Activity,
|
||||
CheckSquare, label: 'مانیتورینگ زنده سرویسها', path: '/monitoring' },
|
||||
{ icon: RotateCcw, label: 'پرتال مالی و استرداد زیبال', path: '/zibal-portal' },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import {
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
Play,
|
||||
AlertTriangle,
|
||||
RefreshCw,
|
||||
DollarSign,
|
||||
ShoppingCart,
|
||||
Send,
|
||||
Sliders,
|
||||
Check,
|
||||
X,
|
||||
MessageSquare,
|
||||
FileText
|
||||
} from 'lucide-react';
|
||||
import api from '../services/api';
|
||||
import Button from '../components/ui/Button';
|
||||
import Badge from '../components/ui/Badge';
|
||||
import Spinner from '../components/ui/Spinner';
|
||||
|
||||
interface ApprovalItem {
|
||||
id: string;
|
||||
department: string;
|
||||
category: string;
|
||||
title: string;
|
||||
payload: any;
|
||||
testContext?: any;
|
||||
status: 'PENDING' | 'APPROVED' | 'REJECTED';
|
||||
ceoNotes?: string;
|
||||
createdAt: string;
|
||||
executedAt?: string;
|
||||
}
|
||||
|
||||
export default function ApprovalsPage() {
|
||||
const [items, setItems] = useState<ApprovalItem[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [activeTab, setActiveTab] = useState<string>('ALL');
|
||||
const [testingId, setTestingId] = useState<string | null>(null);
|
||||
const [testResults, setTestResults] = useState<Record<string, any>>({});
|
||||
const [notes, setNotes] = useState<Record<string, string>>({});
|
||||
const [actionLoading, setActionLoading] = useState<string | null>(null);
|
||||
const [pendingCount, setPendingCount] = useState(0);
|
||||
|
||||
const fetchApprovals = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await api.get('/admin/approvals');
|
||||
if (res.data?.success) {
|
||||
setItems(res.data.data);
|
||||
setPendingCount(res.data.meta?.pendingCount || 0);
|
||||
// Pre-fill notes
|
||||
const initialNotes: Record<string, string> = {};
|
||||
res.data.data.forEach((item: ApprovalItem) => {
|
||||
if (item.ceoNotes) initialNotes[item.id] = item.ceoNotes;
|
||||
});
|
||||
setNotes(initialNotes);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error fetching approvals', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchApprovals();
|
||||
}, []);
|
||||
|
||||
const handleRunTest = async (id: string) => {
|
||||
setTestingId(id);
|
||||
try {
|
||||
const res = await api.post(`/admin/approvals/${id}/test`);
|
||||
if (res.data?.success) {
|
||||
setTestResults((prev) => ({ ...prev, [id]: res.data.testResult }));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Test simulation failed', err);
|
||||
} finally {
|
||||
setTestingId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDecision = async (id: string, decision: 'APPROVED' | 'REJECTED') => {
|
||||
setActionLoading(id);
|
||||
try {
|
||||
const res = await api.put(`/admin/approvals/${id}/decide`, {
|
||||
decision,
|
||||
ceoNotes: notes[id] || '',
|
||||
});
|
||||
if (res.data?.success) {
|
||||
await fetchApprovals();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Decision update failed', err);
|
||||
} finally {
|
||||
setActionLoading(null);
|
||||
}
|
||||
};
|
||||
|
||||
const filteredItems = items.filter((item) => {
|
||||
if (activeTab === 'ALL') return true;
|
||||
if (activeTab === 'PENDING') return item.status === 'PENDING';
|
||||
if (activeTab === 'PRICING') return item.category === 'PRICING';
|
||||
if (activeTab === 'PURCHASE_ORDER') return item.category === 'PURCHASE_ORDER';
|
||||
return item.department === activeTab;
|
||||
});
|
||||
|
||||
const getCategoryIcon = (category: string) => {
|
||||
switch (category) {
|
||||
case 'PRICING':
|
||||
return <DollarSign className="w-5 h-5 text-amber-500" />;
|
||||
case 'PURCHASE_ORDER':
|
||||
return <ShoppingCart className="w-5 h-5 text-blue-500" />;
|
||||
case 'CAMPAIGN':
|
||||
return <Send className="w-5 h-5 text-purple-500" />;
|
||||
default:
|
||||
return <Sliders className="w-5 h-5 text-emerald-500" />;
|
||||
}
|
||||
};
|
||||
|
||||
const getStatusBadge = (status: string) => {
|
||||
switch (status) {
|
||||
case 'PENDING':
|
||||
return <Badge variant="warning">در انتظار تایید شما</Badge>;
|
||||
case 'APPROVED':
|
||||
return <Badge variant="success">تایید و اعمال شد</Badge>;
|
||||
case 'REJECTED':
|
||||
return <Badge variant="danger">رد شده</Badge>;
|
||||
default:
|
||||
return <Badge variant="neutral">{status}</Badge>;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6 max-w-7xl mx-auto p-4 md:p-6" dir="rtl">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col md:flex-row justify-between items-start md:items-center gap-4 bg-white dark:bg-slate-900 p-6 rounded-2xl border border-slate-200 dark:border-slate-800 shadow-sm">
|
||||
<div>
|
||||
<div className="flex items-center gap-3">
|
||||
<h1 className="text-2xl font-bold text-slate-900 dark:text-white">
|
||||
میز کار تاییدات و حاکمیت سازمانی (CEO Approvals Gate)
|
||||
</h1>
|
||||
{pendingCount > 0 && (
|
||||
<span className="px-2.5 py-0.5 rounded-full text-xs font-semibold bg-amber-100 text-amber-800 dark:bg-amber-900/50 dark:text-amber-300">
|
||||
{pendingCount} مورد نیازمند بررسی
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400 mt-1">
|
||||
هیچ تغییر حساسی اعم از قیمتگذاری، صدور سفارش تامین یا ارسال پیامک بدون امضای دیجیتال شما در سیستم پروداکشن اجرایی نخواهد شد.
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={fetchApprovals}
|
||||
disabled={loading}
|
||||
icon={<RefreshCw className={`w-4 h-4 ${loading ? 'animate-spin' : ''}`} />}
|
||||
>
|
||||
بهروزرسانی کارتابل
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<div className="flex flex-wrap gap-2 border-b border-slate-200 dark:border-slate-800 pb-3">
|
||||
{[
|
||||
{ id: 'ALL', label: 'همه موارد' },
|
||||
{ id: 'PENDING', label: `در انتظار تایید (${pendingCount})` },
|
||||
{ id: 'PRICING', label: 'تغییرات قیمت و سود' },
|
||||
{ id: 'PURCHASE_ORDER', label: 'اسناد سفارش تامین' },
|
||||
{ id: 'SUPPLY', label: 'دپارتمان تامین و انبار' },
|
||||
{ id: 'FINANCE', label: 'دپارتمان مالی' },
|
||||
].map((tab) => (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setActiveTab(tab.id)}
|
||||
className={`px-4 py-2 rounded-xl text-sm font-medium transition-all ${
|
||||
activeTab === tab.id
|
||||
? 'bg-blue-600 text-white shadow-sm'
|
||||
: 'bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-300 hover:bg-slate-200 dark:hover:bg-slate-700'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
{loading ? (
|
||||
<div className="py-20 flex justify-center items-center">
|
||||
<Spinner className="w-8 h-8 text-blue-600" />
|
||||
</div>
|
||||
) : filteredItems.length === 0 ? (
|
||||
<div className="bg-white dark:bg-slate-900 p-12 text-center rounded-2xl border border-slate-200 dark:border-slate-800">
|
||||
<CheckCircle2 className="w-12 h-12 text-emerald-500 mx-auto mb-3" />
|
||||
<h3 className="text-lg font-bold text-slate-900 dark:text-white">هیچ موردی در این بخش وجود ندارد</h3>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400 mt-1">تمامی موارد قبلی رسیدگی شدهاند یا هنوز دستور جدیدی صادر نشده است.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid gap-6">
|
||||
{filteredItems.map((item) => (
|
||||
<div
|
||||
key={item.id}
|
||||
className={`bg-white dark:bg-slate-900 rounded-2xl border transition-all overflow-hidden ${
|
||||
item.status === 'PENDING'
|
||||
? 'border-amber-300 dark:border-amber-800/60 shadow-md ring-1 ring-amber-400/20'
|
||||
: 'border-slate-200 dark:border-slate-800 opacity-90'
|
||||
}`}
|
||||
>
|
||||
{/* Card Header */}
|
||||
<div className="p-5 border-b border-slate-100 dark:border-slate-800/80 flex flex-col md:flex-row justify-between items-start md:items-center gap-3 bg-slate-50/50 dark:bg-slate-800/30">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2.5 rounded-xl bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700">
|
||||
{getCategoryIcon(item.category)}
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-bold text-slate-900 dark:text-white text-base">
|
||||
{item.title}
|
||||
</h3>
|
||||
<div className="flex items-center gap-2 mt-1 text-xs text-slate-500 dark:text-slate-400">
|
||||
<span>دپارتمان: <strong>{item.department}</strong></span>
|
||||
<span>•</span>
|
||||
<span>دستهبندی: <strong>{item.category}</strong></span>
|
||||
<span>•</span>
|
||||
<span>تاریخ: {new Date(item.createdAt).toLocaleDateString('fa-IR')}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>{getStatusBadge(item.status)}</div>
|
||||
</div>
|
||||
|
||||
{/* Card Body */}
|
||||
<div className="p-5 space-y-4">
|
||||
{/* Proposed Data Payload Diff */}
|
||||
<div className="bg-slate-50 dark:bg-slate-950 p-4 rounded-xl border border-slate-200/80 dark:border-slate-800 text-xs font-mono text-slate-800 dark:text-slate-200 overflow-x-auto">
|
||||
<div className="font-sans font-bold text-xs text-slate-500 dark:text-slate-400 mb-2">
|
||||
جزئیات دادههای ارسالی (Payload Details):
|
||||
</div>
|
||||
<pre className="whitespace-pre-wrap">{JSON.stringify(item.payload, null, 2)}</pre>
|
||||
</div>
|
||||
|
||||
{/* Simulation / Sandbox Test */}
|
||||
<div className="bg-blue-50/40 dark:bg-blue-950/20 p-4 rounded-xl border border-blue-100 dark:border-blue-900/40 flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center gap-2 font-bold text-sm text-blue-900 dark:text-blue-300">
|
||||
<Play className="w-4 h-4 text-blue-600" />
|
||||
<span>محیط شبیهسازی و تست میدانی (Sandbox Preview)</span>
|
||||
</div>
|
||||
<p className="text-xs text-blue-700/80 dark:text-blue-400">
|
||||
پیش از تایید میتوانید نتایج محاسباتی و اثر این اقدام روی سایت و سرویسها را شبیهسازی کنید.
|
||||
</p>
|
||||
{testResults[item.id] && (
|
||||
<div className="mt-3 p-3 bg-white dark:bg-slate-900 rounded-lg border border-blue-200 dark:border-blue-800 text-xs text-slate-700 dark:text-slate-300">
|
||||
<span className="font-bold text-emerald-600 dark:text-emerald-400 block mb-1">
|
||||
✓ نتیجه شبیهسازی موفق:
|
||||
</span>
|
||||
<pre className="text-xs">{JSON.stringify(testResults[item.id], null, 2)}</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={() => handleRunTest(item.id)}
|
||||
disabled={testingId === item.id}
|
||||
icon={<Play className={`w-3.5 h-3.5 ${testingId === item.id ? 'animate-spin' : ''}`} />}
|
||||
>
|
||||
{testingId === item.id ? 'در حال شبیهسازی...' : 'اجرای تست آزمایشی'}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* CEO Feedback & Instructions Field */}
|
||||
<div className="space-y-2">
|
||||
<label className="flex items-center gap-1.5 text-xs font-bold text-slate-700 dark:text-slate-300">
|
||||
<MessageSquare className="w-3.5 h-3.5 text-blue-600" />
|
||||
<span>توضیحات و بازخورد مدیرعامل (دستورات تایید یا دلایل رد):</span>
|
||||
</label>
|
||||
<textarea
|
||||
rows={2}
|
||||
value={notes[item.id] || ''}
|
||||
onChange={(e) => setNotes({ ...notes, [item.id]: e.target.value })}
|
||||
placeholder="توضیحات، اصلاحات یا شروط لازم را بنویسید (مثلاً: قیمت تایید است ولی از فردا صبح اعمال شود)..."
|
||||
disabled={item.status !== 'PENDING' || actionLoading === item.id}
|
||||
className="w-full text-sm p-3 rounded-xl border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-900 dark:text-white focus:ring-2 focus:ring-blue-500 outline-none transition disabled:opacity-60"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Action Buttons */}
|
||||
{item.status === 'PENDING' && (
|
||||
<div className="flex flex-wrap items-center justify-end gap-3 pt-2">
|
||||
<Button
|
||||
variant="danger"
|
||||
onClick={() => handleDecision(item.id, 'REJECTED')}
|
||||
disabled={actionLoading === item.id}
|
||||
icon={<X className="w-4 h-4" />}
|
||||
>
|
||||
رد این مورد
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
onClick={() => handleDecision(item.id, 'APPROVED')}
|
||||
disabled={actionLoading === item.id}
|
||||
icon={<Check className="w-4 h-4" />}
|
||||
>
|
||||
تایید و اعمال نهایی در پروداکشن
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{item.status !== 'PENDING' && item.ceoNotes && (
|
||||
<div className="p-3 bg-slate-100 dark:bg-slate-800/60 rounded-xl text-xs text-slate-600 dark:text-slate-300">
|
||||
<strong>یادداشت ثبت شده مدیرعامل:</strong> {item.ceoNotes}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -46,6 +46,8 @@ const DoctorsManager = lazyWithRetry(() => import('../pages/DoctorsManager'));
|
||||
const FAQManager = lazyWithRetry(() => import('../pages/FAQManager'));
|
||||
const MenuManager = lazyWithRetry(() => import('../pages/MenuManager'));
|
||||
const MonitoringPage = lazyWithRetry(() => import('../pages/MonitoringPage'));
|
||||
const ApprovalsPage = lazyWithRetry(() => import('../pages/ApprovalsPage'));
|
||||
|
||||
|
||||
|
||||
export interface AdminRouteConfig {
|
||||
@@ -108,6 +110,8 @@ export const router = createBrowserRouter([
|
||||
{ path: 'faq/*', element: <FAQManager /> },
|
||||
{ path: 'menu/*', element: <MenuManager /> },
|
||||
{ path: 'monitoring/*', element: <MonitoringPage /> },
|
||||
{ path: 'approvals/*', element: <ApprovalsPage /> },
|
||||
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user