feat: complete exam lifecycle — AI generation, submission, student session, and results
- Backend: AI generation fallbacks when OpenAI not configured, full exam submission saving all params (difficulty, rubric, entity, grading system, approval workflow) and creating linked question records per section - Backend: new exam session controller with get_session, autosave, submit, status, and results endpoints; student attempt/answer/score models - Backend: new controllers for entities, approval workflows, exam schedules - Frontend: exam session split-layout with passage panel, question types (MCQ, T/F/NG, gap-fill, writing, speaking), timer, and review dialog - Frontend: results page with percentage score, per-answer breakdown table - Frontend: generation page dynamic dropdowns, full payload submission - Frontend: updated types for ExamSessionSection, ExamQuestion options Made-with: Cursor
This commit is contained in:
@@ -1,119 +1,556 @@
|
||||
import { useState } from "react";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Plus, CheckCircle, XCircle, Clock } from "lucide-react";
|
||||
import AiGradingAssistant from "@/components/ai/AiGradingAssistant";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
Plus,
|
||||
CheckCircle,
|
||||
XCircle,
|
||||
Clock,
|
||||
Loader2,
|
||||
Trash2,
|
||||
ChevronRight,
|
||||
ShieldCheck,
|
||||
FileText,
|
||||
} from "lucide-react";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { api } from "@/lib/api-client";
|
||||
|
||||
const workflows = [
|
||||
{
|
||||
id: 1, name: "Exam Content Review", status: "In Progress",
|
||||
steps: [
|
||||
{ name: "Initial Review", assignee: "Dr. Smith", status: "Approved" },
|
||||
{ name: "Quality Check", assignee: "Prof. Lee", status: "Pending" },
|
||||
{ name: "Final Approval", assignee: "Admin", status: "Waiting" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 2, name: "Rubric Approval", status: "Completed",
|
||||
steps: [
|
||||
{ name: "Draft Review", assignee: "Mr. Kim", status: "Approved" },
|
||||
{ name: "Academic Board", assignee: "Dr. Smith", status: "Approved" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 3, name: "New Exam Structure", status: "Rejected",
|
||||
steps: [
|
||||
{ name: "Content Review", assignee: "Prof. Lee", status: "Approved" },
|
||||
{ name: "Standards Check", assignee: "Dr. Smith", status: "Rejected" },
|
||||
],
|
||||
},
|
||||
];
|
||||
interface WorkflowStep {
|
||||
id: number;
|
||||
sequence: number;
|
||||
approver_id: number | null;
|
||||
approver_name: string;
|
||||
status: string;
|
||||
comment: string;
|
||||
auto_escalate: boolean;
|
||||
max_days: number;
|
||||
acted_at: string | null;
|
||||
}
|
||||
|
||||
interface Workflow {
|
||||
id: number;
|
||||
name: string;
|
||||
type: string;
|
||||
entity_id: number | null;
|
||||
entity_name: string | null;
|
||||
allow_bypass: boolean;
|
||||
active: boolean;
|
||||
steps: WorkflowStep[];
|
||||
created: string;
|
||||
}
|
||||
|
||||
interface ApprovalRequest {
|
||||
id: number;
|
||||
workflow_id: number | null;
|
||||
workflow_name: string;
|
||||
res_model: string;
|
||||
res_id: number;
|
||||
state: string;
|
||||
requester_id: number | null;
|
||||
requester_name: string;
|
||||
current_stage_id: number | null;
|
||||
current_stage_sequence: number | null;
|
||||
bypass_reason: string;
|
||||
created_at: string | null;
|
||||
}
|
||||
|
||||
interface UserItem {
|
||||
id: number;
|
||||
name: string;
|
||||
login: string;
|
||||
}
|
||||
|
||||
const statusIcon = (s: string) => {
|
||||
if (s === "Approved") return <CheckCircle className="h-4 w-4 text-success" />;
|
||||
if (s === "Rejected") return <XCircle className="h-4 w-4 text-destructive" />;
|
||||
return <Clock className="h-4 w-4 text-warning" />;
|
||||
if (s === "approved") return <CheckCircle className="h-4 w-4 text-green-600" />;
|
||||
if (s === "rejected") return <XCircle className="h-4 w-4 text-destructive" />;
|
||||
return <Clock className="h-4 w-4 text-amber-500" />;
|
||||
};
|
||||
|
||||
const stateBadge = (state: string) => {
|
||||
const map: Record<string, "default" | "secondary" | "destructive" | "outline"> = {
|
||||
approved: "default",
|
||||
in_progress: "secondary",
|
||||
rejected: "destructive",
|
||||
draft: "outline",
|
||||
};
|
||||
return (
|
||||
<Badge variant={map[state] || "outline"} className="capitalize">
|
||||
{state.replace(/_/g, " ")}
|
||||
</Badge>
|
||||
);
|
||||
};
|
||||
|
||||
export default function ApprovalWorkflowsPage() {
|
||||
const { toast } = useToast();
|
||||
const qc = useQueryClient();
|
||||
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [formName, setFormName] = useState("");
|
||||
const [formType, setFormType] = useState("custom");
|
||||
const [formSteps, setFormSteps] = useState<{ approver_id: string }[]>([
|
||||
{ approver_id: "" },
|
||||
{ approver_id: "" },
|
||||
]);
|
||||
|
||||
const [rejectDialog, setRejectDialog] = useState<number | null>(null);
|
||||
const [rejectComment, setRejectComment] = useState("");
|
||||
|
||||
const workflowsQ = useQuery({
|
||||
queryKey: ["approval-workflows"],
|
||||
queryFn: () => api.get<{ items: Workflow[]; total: number }>("/approval-workflows"),
|
||||
});
|
||||
|
||||
const requestsQ = useQuery({
|
||||
queryKey: ["approval-requests"],
|
||||
queryFn: () => api.get<{ items: ApprovalRequest[]; total: number }>("/approval-requests"),
|
||||
});
|
||||
|
||||
const usersQ = useQuery({
|
||||
queryKey: ["approval-users"],
|
||||
queryFn: () => api.get<{ items: UserItem[] }>("/approval-users"),
|
||||
});
|
||||
|
||||
const workflows = workflowsQ.data?.items ?? [];
|
||||
const requests = requestsQ.data?.items ?? [];
|
||||
const users = usersQ.data?.items ?? [];
|
||||
|
||||
const createMut = useMutation({
|
||||
mutationFn: (data: Record<string, unknown>) => api.post("/approval-workflows", data),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ["approval-workflows"] });
|
||||
setCreateOpen(false);
|
||||
resetForm();
|
||||
toast({ title: "Workflow created" });
|
||||
},
|
||||
onError: (e: Error) => toast({ variant: "destructive", title: "Create failed", description: e.message }),
|
||||
});
|
||||
|
||||
const deleteMut = useMutation({
|
||||
mutationFn: (id: number) => api.delete(`/approval-workflows/${id}`),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ["approval-workflows"] });
|
||||
toast({ title: "Workflow deleted" });
|
||||
},
|
||||
});
|
||||
|
||||
const approveMut = useMutation({
|
||||
mutationFn: (id: number) => api.post(`/approval-requests/${id}/approve`, {}),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ["approval-requests"] });
|
||||
qc.invalidateQueries({ queryKey: ["approval-workflows"] });
|
||||
toast({ title: "Request approved" });
|
||||
},
|
||||
onError: (e: Error) => toast({ variant: "destructive", title: "Approve failed", description: e.message }),
|
||||
});
|
||||
|
||||
const rejectMut = useMutation({
|
||||
mutationFn: ({ id, comment }: { id: number; comment: string }) =>
|
||||
api.post(`/approval-requests/${id}/reject`, { comment }),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ["approval-requests"] });
|
||||
qc.invalidateQueries({ queryKey: ["approval-workflows"] });
|
||||
setRejectDialog(null);
|
||||
setRejectComment("");
|
||||
toast({ title: "Request rejected" });
|
||||
},
|
||||
onError: (e: Error) => toast({ variant: "destructive", title: "Reject failed", description: e.message }),
|
||||
});
|
||||
|
||||
const resetForm = () => {
|
||||
setFormName("");
|
||||
setFormType("custom");
|
||||
setFormSteps([{ approver_id: "" }, { approver_id: "" }]);
|
||||
};
|
||||
|
||||
const handleCreate = () => {
|
||||
createMut.mutate({
|
||||
name: formName.trim(),
|
||||
type: formType,
|
||||
steps: formSteps
|
||||
.filter((s) => s.approver_id)
|
||||
.map((s) => ({ approver_id: Number(s.approver_id) })),
|
||||
});
|
||||
};
|
||||
|
||||
const pendingRequests = requests.filter((r) => r.state === "in_progress");
|
||||
const completedRequests = requests.filter((r) => r.state !== "in_progress");
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight">Approval Workflows</h1>
|
||||
<p className="text-muted-foreground">Manage multi-step approval processes for exam content.</p>
|
||||
<p className="text-muted-foreground">
|
||||
Manage multi-step approval processes for exam content.
|
||||
</p>
|
||||
</div>
|
||||
<Dialog>
|
||||
<Dialog
|
||||
open={createOpen}
|
||||
onOpenChange={(open) => {
|
||||
setCreateOpen(open);
|
||||
if (!open) resetForm();
|
||||
}}
|
||||
>
|
||||
<DialogTrigger asChild>
|
||||
<Button size="sm"><Plus className="h-4 w-4 mr-1" /> Create Workflow</Button>
|
||||
<Button size="sm">
|
||||
<Plus className="h-4 w-4 mr-1" /> Create Workflow
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader><DialogTitle>Create Workflow</DialogTitle></DialogHeader>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create Workflow</DialogTitle>
|
||||
<DialogDescription>Define a multi-step approval process.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2"><Label>Workflow Name</Label><Input placeholder="e.g. Exam Content Review" /></div>
|
||||
<div className="space-y-2">
|
||||
<Label>Step 1 — Assignee</Label>
|
||||
<Select><SelectTrigger><SelectValue placeholder="Select assignee" /></SelectTrigger>
|
||||
<SelectContent><SelectItem value="smith">Dr. Smith</SelectItem><SelectItem value="lee">Prof. Lee</SelectItem><SelectItem value="kim">Mr. Kim</SelectItem></SelectContent>
|
||||
</Select>
|
||||
<Label>
|
||||
Workflow Name <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
value={formName}
|
||||
onChange={(e) => setFormName(e.target.value)}
|
||||
placeholder="e.g. Exam Content Review"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Step 2 — Assignee</Label>
|
||||
<Select><SelectTrigger><SelectValue placeholder="Select assignee" /></SelectTrigger>
|
||||
<SelectContent><SelectItem value="smith">Dr. Smith</SelectItem><SelectItem value="lee">Prof. Lee</SelectItem><SelectItem value="admin">Admin</SelectItem></SelectContent>
|
||||
<Label>Type</Label>
|
||||
<Select value={formType} onValueChange={setFormType}>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="custom">Custom</SelectItem>
|
||||
<SelectItem value="exam_publish">Exam Publication</SelectItem>
|
||||
<SelectItem value="assignment_publish">Assignment Publication</SelectItem>
|
||||
<SelectItem value="content_publish">Content Publication</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<Button className="w-full">Create</Button>
|
||||
|
||||
{formSteps.map((step, i) => (
|
||||
<div key={i} className="space-y-1">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>Step {i + 1} — Approver</Label>
|
||||
{formSteps.length > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 text-muted-foreground hover:text-destructive"
|
||||
onClick={() =>
|
||||
setFormSteps((s) => s.filter((_, idx) => idx !== i))
|
||||
}
|
||||
>
|
||||
<Trash2 className="h-3 w-3" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Select
|
||||
value={step.approver_id}
|
||||
onValueChange={(v) =>
|
||||
setFormSteps((s) =>
|
||||
s.map((st, idx) => (idx === i ? { ...st, approver_id: v } : st))
|
||||
)
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select approver" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{users.map((u) => (
|
||||
<SelectItem key={u.id} value={String(u.id)}>
|
||||
{u.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full"
|
||||
onClick={() => setFormSteps((s) => [...s, { approver_id: "" }])}
|
||||
>
|
||||
<Plus className="h-3 w-3 mr-1" /> Add Step
|
||||
</Button>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setCreateOpen(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
disabled={!formName.trim() || createMut.isPending}
|
||||
onClick={handleCreate}
|
||||
>
|
||||
{createMut.isPending ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 animate-spin mr-2" />
|
||||
Creating...
|
||||
</>
|
||||
) : (
|
||||
"Create"
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
{/* Loading */}
|
||||
{(workflowsQ.isLoading || requestsQ.isLoading) && (
|
||||
<div className="flex justify-center py-12">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Pending Requests */}
|
||||
{pendingRequests.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h2 className="text-lg font-semibold flex items-center gap-2">
|
||||
<Clock className="h-5 w-5 text-amber-500" />
|
||||
Pending Approval ({pendingRequests.length})
|
||||
</h2>
|
||||
{pendingRequests.map((req) => {
|
||||
const wf = workflows.find((w) => w.id === req.workflow_id);
|
||||
return (
|
||||
<Card key={req.id} className="border-amber-200 bg-amber-50/30">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<div>
|
||||
<p className="font-semibold">{req.workflow_name}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Requested by {req.requester_name} ·{" "}
|
||||
{req.res_model.replace("encoach.", "")} #{req.res_id}
|
||||
</p>
|
||||
</div>
|
||||
{stateBadge(req.state)}
|
||||
</div>
|
||||
|
||||
{wf && (
|
||||
<div className="flex items-center gap-2 flex-wrap mb-3">
|
||||
{wf.steps.map((step, i) => {
|
||||
const isActive = step.id === req.current_stage_id;
|
||||
return (
|
||||
<div key={step.id} className="flex items-center gap-2">
|
||||
<div
|
||||
className={`flex items-center gap-2 rounded-lg border p-3 min-w-[160px] transition-all ${
|
||||
isActive
|
||||
? "border-amber-400 bg-amber-50 ring-2 ring-amber-200"
|
||||
: step.status === "approved"
|
||||
? "border-green-200 bg-green-50/50"
|
||||
: step.status === "rejected"
|
||||
? "border-red-200 bg-red-50/50"
|
||||
: "bg-muted/30"
|
||||
}`}
|
||||
>
|
||||
{statusIcon(step.status)}
|
||||
<div>
|
||||
<p className="text-sm font-medium">Step {i + 1}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{step.approver_name}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{i < wf.steps.length - 1 && (
|
||||
<ChevronRight className="h-4 w-4 text-muted-foreground shrink-0" />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
disabled={approveMut.isPending}
|
||||
onClick={() => approveMut.mutate(req.id)}
|
||||
>
|
||||
{approveMut.isPending ? (
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin mr-1" />
|
||||
) : (
|
||||
<CheckCircle className="h-3.5 w-3.5 mr-1" />
|
||||
)}
|
||||
Approve
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => setRejectDialog(req.id)}
|
||||
>
|
||||
<XCircle className="h-3.5 w-3.5 mr-1" />
|
||||
Reject
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Workflow Templates */}
|
||||
<div className="space-y-3">
|
||||
<h2 className="text-lg font-semibold flex items-center gap-2">
|
||||
<ShieldCheck className="h-5 w-5" />
|
||||
Workflow Templates ({workflows.length})
|
||||
</h2>
|
||||
{workflows.length === 0 && !workflowsQ.isLoading && (
|
||||
<Card className="border-dashed">
|
||||
<CardContent className="p-8 text-center text-muted-foreground">
|
||||
No workflows defined yet. Create one to get started.
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
{workflows.map((wf) => (
|
||||
<Card key={wf.id} className="border-0 shadow-sm">
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className="text-base font-semibold">{wf.name}</CardTitle>
|
||||
<Badge variant={wf.status === "Completed" ? "default" : wf.status === "Rejected" ? "destructive" : "secondary"}>{wf.status}</Badge>
|
||||
<div className="flex items-center gap-3">
|
||||
<CardTitle className="text-base font-semibold">{wf.name}</CardTitle>
|
||||
<Badge variant="outline" className="text-xs capitalize">
|
||||
{wf.type.replace(/_/g, " ")}
|
||||
</Badge>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => {
|
||||
if (confirm(`Delete workflow "${wf.name}"?`)) deleteMut.mutate(wf.id);
|
||||
}}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
{wf.steps.map((step, i) => (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<div key={step.id} className="flex items-center gap-2">
|
||||
<div className="flex items-center gap-2 rounded-lg border p-3 bg-muted/30 min-w-[160px]">
|
||||
{statusIcon(step.status)}
|
||||
<div className="h-6 w-6 rounded-full bg-primary/10 flex items-center justify-center text-xs font-semibold text-primary">
|
||||
{i + 1}
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium">{step.name}</p>
|
||||
<p className="text-xs text-muted-foreground">{step.assignee}</p>
|
||||
<p className="text-sm font-medium">{step.approver_name}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{step.max_days}d limit
|
||||
{step.auto_escalate ? " · auto-escalate" : ""}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{i < wf.steps.length - 1 && <div className="w-8 h-0.5 bg-border" />}
|
||||
{i < wf.steps.length - 1 && (
|
||||
<ChevronRight className="h-4 w-4 text-muted-foreground shrink-0" />
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{wf.status === "In Progress" && (
|
||||
<div className="space-y-4 mt-4">
|
||||
<AiGradingAssistant onAccept={(marks, feedback) => {
|
||||
toast({ title: "AI Grade Accepted", description: `Marks: ${marks}/100 applied with AI feedback.` });
|
||||
}} />
|
||||
<div className="flex gap-2">
|
||||
<Button size="sm" variant="default">Approve</Button>
|
||||
<Button size="sm" variant="outline">Reject</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Completed Requests */}
|
||||
{completedRequests.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h2 className="text-lg font-semibold flex items-center gap-2">
|
||||
<FileText className="h-5 w-5" />
|
||||
Recent Decisions ({completedRequests.length})
|
||||
</h2>
|
||||
{completedRequests.map((req) => (
|
||||
<Card key={req.id} className="border-0 shadow-sm">
|
||||
<CardContent className="p-4 flex items-center justify-between">
|
||||
<div>
|
||||
<p className="font-medium">{req.workflow_name}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{req.requester_name} · {req.res_model.replace("encoach.", "")} #
|
||||
{req.res_id}
|
||||
{req.created_at && (
|
||||
<>
|
||||
{" "}
|
||||
· {new Date(req.created_at).toLocaleDateString()}
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
{stateBadge(req.state)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Reject Dialog */}
|
||||
<Dialog
|
||||
open={rejectDialog !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
setRejectDialog(null);
|
||||
setRejectComment("");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Reject Request</DialogTitle>
|
||||
<DialogDescription>Provide a reason for rejection.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2">
|
||||
<Label>Comment</Label>
|
||||
<Textarea
|
||||
value={rejectComment}
|
||||
onChange={(e) => setRejectComment(e.target.value)}
|
||||
placeholder="Reason for rejection..."
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setRejectDialog(null)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
disabled={rejectMut.isPending}
|
||||
onClick={() => {
|
||||
if (rejectDialog !== null) {
|
||||
rejectMut.mutate({ id: rejectDialog, comment: rejectComment });
|
||||
}
|
||||
}}
|
||||
>
|
||||
{rejectMut.isPending ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin mr-2" />
|
||||
) : null}
|
||||
Reject
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user