Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
feat: Add question bank feature
Khuram Niaz7060a8590d78
diff --git a/prisma/migrations/20260305175020_add_question_model/migration.sql b/prisma/migrations/20260305175020_add_question_model/migration.sqlnew file mode 100644index 0000000..7c177c9--- /dev/null+++ b/prisma/migrations/20260305175020_add_question_model/migration.sql@@ -0,0 +1,27 @@+-- CreateTable+CREATE TABLE "Question" (+ "id" TEXT NOT NULL PRIMARY KEY,+ "question" TEXT NOT NULL,+ "answer" TEXT,+ "createdBy" TEXT NOT NULL,+ "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,+ "updatedAt" DATETIME NOT NULL,+ CONSTRAINT "Question_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE+);++-- CreateTable+CREATE TABLE "_QuestionToTag" (+ "A" TEXT NOT NULL,+ "B" TEXT NOT NULL,+ CONSTRAINT "_QuestionToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "Question" ("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "_QuestionToTag_B_fkey" FOREIGN KEY ("B") REFERENCES "Tag" ("id") ON DELETE CASCADE ON UPDATE CASCADE+);++-- CreateIndex+CREATE INDEX "Question_createdBy_idx" ON "Question"("createdBy");++-- CreateIndex+CREATE UNIQUE INDEX "_QuestionToTag_AB_unique" ON "_QuestionToTag"("A", "B");++-- CreateIndex+CREATE INDEX "_QuestionToTag_B_index" ON "_QuestionToTag"("B");diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex c5d5393..bb4b44e 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -33,6 +33,7 @@ model User {ApiKey ApiKey[]Note Note[]Tag Tag[]+ Question Question[]}model ApiKey {@@ -432,6 +433,20 @@ model Tag {createdBy Stringuser User @relation(fields: [createdBy], references: [id])jobs Job[]+ questions Question[]@@unique([value, createdBy])}++model Question {+ id String @id @default(uuid())+ question String+ answer String?+ createdBy String+ user User @relation(fields: [createdBy], references: [id])+ tags Tag[]+ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt++ @@index([createdBy])+}diff --git a/src/actions/question.actions.ts b/src/actions/question.actions.tsnew file mode 100644index 0000000..c298c09--- /dev/null+++ b/src/actions/question.actions.ts@@ -0,0 +1,184 @@+"use server";+import prisma from "@/lib/db";+import { handleError } from "@/lib/utils";+import { AddQuestionFormSchema } from "@/models/addQuestionForm.schema";+import { getCurrentUser } from "@/utils/user.utils";+import { APP_CONSTANTS } from "@/lib/constants";+import { z } from "zod";++export const getQuestionsList = async (+ page: number = 1,+ limit: number = APP_CONSTANTS.RECORDS_PER_PAGE,+ filter?: string,+ search?: string+): Promise<any | undefined> => {+ try {+ const user = await getCurrentUser();+ if (!user) throw new Error("Not authenticated");++ const offset = (page - 1) * limit;++ const whereClause: any = {+ createdBy: user.id,+ };++ if (filter) {+ whereClause.tags = { some: { id: filter } };+ }++ if (search) {+ whereClause.OR = [+ { question: { contains: search } },+ { answer: { contains: search } },+ ];+ }++ const [data, total] = await Promise.all([+ prisma.question.findMany({+ where: whereClause,+ include: {+ tags: true,+ },+ orderBy: [{ createdAt: "desc" }],+ skip: offset,+ take: limit,+ }),+ prisma.question.count({ where: whereClause }),+ ]);++ return { success: true, data, total };+ } catch (error) {+ return handleError(error, "Failed to fetch questions list.");+ }+};++export const getQuestionById = async (+ questionId: string+): Promise<any | undefined> => {+ try {+ const user = await getCurrentUser();+ if (!user) throw new Error("Not authenticated");++ const question = await prisma.question.findFirst({+ where: { id: questionId, createdBy: user.id },+ include: { tags: true },+ });++ if (!question) {+ return { success: false, message: "Question not found" };+ }++ return { success: true, data: question };+ } catch (error) {+ return handleError(error, "Failed to fetch question.");+ }+};++export const createQuestion = async (+ data: z.infer<typeof AddQuestionFormSchema>+): Promise<any | undefined> => {+ try {+ const user = await getCurrentUser();+ if (!user) throw new Error("Not authenticated");++ const validatedData = AddQuestionFormSchema.parse(data);++ const question = await prisma.question.create({+ data: {+ question: validatedData.question,+ answer: validatedData.answer || null,+ createdBy: user.id,+ tags: validatedData.tagIds?.length+ ? { connect: validatedData.tagIds.map((id) => ({ id })) }+ : undefined,+ },+ include: { tags: true },+ });++ return { success: true, data: question };+ } catch (error) {+ return handleError(error, "Failed to create question.");+ }+};++export const updateQuestion = async (+ data: z.infer<typeof AddQuestionFormSchema>+): Promise<any | undefined> => {+ try {+ const user = await getCurrentUser();+ if (!user) throw new Error("Not authenticated");++ if (!data.id) throw new Error("Question ID is required for update");++ const validatedData = AddQuestionFormSchema.parse(data);++ const question = await prisma.question.update({+ where: { id: data.id, createdBy: user.id },+ data: {+ question: validatedData.question,+ answer: validatedData.answer || null,+ tags: {+ set: validatedData.tagIds?.map((id) => ({ id })) || [],+ },+ },+ include: { tags: true },+ });++ return { success: true, data: question };+ } catch (error) {+ return handleError(error, "Failed to update question.");+ }+};++export const deleteQuestion = async (+ questionId: string+): Promise<any | undefined> => {+ try {+ const user = await getCurrentUser();+ if (!user) throw new Error("Not authenticated");++ await prisma.question.delete({+ where: { id: questionId, createdBy: user.id },+ });++ return { success: true };+ } catch (error) {+ return handleError(error, "Failed to delete question.");+ }+};++export const getTagsWithQuestionCounts = async (): Promise<+ any | undefined+> => {+ try {+ const user = await getCurrentUser();+ if (!user) throw new Error("Not authenticated");++ const tags = await prisma.tag.findMany({+ where: { createdBy: user.id },+ include: {+ _count: {+ select: { questions: true },+ },+ },+ orderBy: { label: "asc" },+ });++ const data = tags+ .filter((tag) => tag._count.questions > 0)+ .map((tag) => ({+ id: tag.id,+ label: tag.label,+ value: tag.value,+ questionCount: tag._count.questions,+ }));++ const totalQuestions = await prisma.question.count({+ where: { createdBy: user.id },+ });++ return { success: true, data, totalQuestions };+ } catch (error) {+ return handleError(error, "Failed to fetch tags with question counts.");+ }+};diff --git a/src/app/dashboard/questions/QuestionsPageClient.tsx b/src/app/dashboard/questions/QuestionsPageClient.tsxnew file mode 100644index 0000000..1ffa955--- /dev/null+++ b/src/app/dashboard/questions/QuestionsPageClient.tsx@@ -0,0 +1,62 @@+"use client";+import QuestionsContainer from "@/components/questions/QuestionsContainer";+import QuestionsSidebar from "@/components/questions/QuestionsSidebar";+import { Tag } from "@/models/job.model";+import { useState, useCallback } from "react";+import { getTagsWithQuestionCounts } from "@/actions/question.actions";++type TagWithCount = {+ id: string;+ label: string;+ value: string;+ questionCount: number;+};++type QuestionsPageClientProps = {+ allTags: Tag[];+ tagsWithCounts: TagWithCount[];+ totalQuestions: number;+};++function QuestionsPageClient({+ allTags,+ tagsWithCounts,+ totalQuestions,+}: QuestionsPageClientProps) {+ const [filterKey, setFilterKey] = useState<string | undefined>(undefined);+ const [sidebarCounts, setSidebarCounts] =+ useState<TagWithCount[]>(tagsWithCounts);+ const [sidebarTotal, setSidebarTotal] = useState<number>(totalQuestions);++ const onFilterChange = (filter: string | undefined) => {+ setFilterKey(filter);+ };++ const refreshSidebarCounts = useCallback(async () => {+ const result = await getTagsWithQuestionCounts();+ if (result?.success) {+ setSidebarCounts(result.data);+ setSidebarTotal(result.totalQuestions);+ }+ }, []);++ return (+ <div className="col-span-3 flex h-full">+ <QuestionsSidebar+ tags={sidebarCounts}+ totalQuestions={sidebarTotal}+ selectedFilter={filterKey}+ onFilterChange={onFilterChange}+ />+ <div className="flex-1">+ <QuestionsContainer+ availableTags={allTags}+ filterKey={filterKey}+ onQuestionsChanged={refreshSidebarCounts}+ />+ </div>+ </div>+ );+}++export default QuestionsPageClient;diff --git a/src/app/dashboard/questions/page.tsx b/src/app/dashboard/questions/page.tsxnew file mode 100644index 0000000..cbaa0e3--- /dev/null+++ b/src/app/dashboard/questions/page.tsx@@ -0,0 +1,21 @@+import QuestionsPageClient from "./QuestionsPageClient";+import { getTagsWithQuestionCounts } from "@/actions/question.actions";+import { getAllTags } from "@/actions/tag.actions";+import React from "react";++async function Questions() {+ const [allTags, tagsWithCounts] = await Promise.all([+ getAllTags(),+ getTagsWithQuestionCounts(),+ ]);++ return (+ <QuestionsPageClient+ allTags={allTags || []}+ tagsWithCounts={tagsWithCounts?.data || []}+ totalQuestions={tagsWithCounts?.totalQuestions || 0}+ />+ );+}++export default Questions;diff --git a/src/components/questions/QuestionCard.tsx b/src/components/questions/QuestionCard.tsxnew file mode 100644index 0000000..2fdfebf--- /dev/null+++ b/src/components/questions/QuestionCard.tsx@@ -0,0 +1,146 @@+"use client";+import { useState } from "react";+import { Question } from "@/models/question.model";+import { Badge } from "@/components/ui/badge";+import { Button } from "@/components/ui/button";+import { MoreHorizontal, Pencil, Trash2 } from "lucide-react";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";+import {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+} from "@/components/ui/alert-dialog";++type QuestionCardProps = {+ question: Question;+ onEdit: (question: Question) => void;+ onDelete: (questionId: string) => void;+};++function truncateHtml(html: string, maxLength: number): string {+ if (html.length <= maxLength) return html;+ return html.substring(0, maxLength) + "...";+}++export function QuestionCard({+ question,+ onEdit,+ onDelete,+}: QuestionCardProps) {+ const [expanded, setExpanded] = useState(false);+ const [showDeleteDialog, setShowDeleteDialog] = useState(false);++ const hasAnswer = question.answer && question.answer.trim().length > 0;+ const isLongAnswer = hasAnswer && question.answer!.length > 300;++ return (+ <>+ <div+ className="border rounded-lg p-4 hover:bg-accent/50 transition-colors cursor-pointer"+ onClick={() => setExpanded(!expanded)}+ >+ <div className="flex items-start justify-between gap-2">+ <h3 className="font-medium flex-1">{question.question}</h3>+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ variant="ghost"+ size="sm"+ className="h-8 w-8 p-0"+ onClick={(e) => e.stopPropagation()}+ >+ <MoreHorizontal className="h-4 w-4" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ onEdit(question);+ }}+ >+ <Pencil className="mr-2 h-4 w-4" />+ Edit+ </DropdownMenuItem>+ <DropdownMenuItem+ className="text-destructive"+ onClick={(e) => {+ e.stopPropagation();+ setShowDeleteDialog(true);+ }}+ >+ <Trash2 className="mr-2 h-4 w-4" />+ Delete+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>++ {hasAnswer && (+ <div+ className="mt-2 text-sm text-muted-foreground prose prose-sm max-w-none dark:prose-invert"+ dangerouslySetInnerHTML={{+ __html:+ expanded || !isLongAnswer+ ? question.answer!+ : truncateHtml(question.answer!, 300),+ }}+ />+ )}++ {question.tags && question.tags.length > 0 && (+ <div className="flex flex-wrap gap-1.5 mt-3">+ {question.tags.map((tag) => (+ <Badge key={tag.id} variant="secondary" className="text-xs">+ {tag.label}+ </Badge>+ ))}+ </div>+ )}++ {isLongAnswer && (+ <button+ className="text-xs text-primary mt-2 hover:underline"+ onClick={(e) => {+ e.stopPropagation();+ setExpanded(!expanded);+ }}+ >+ {expanded ? "Show less" : "Show more"}+ </button>+ )}+ </div>++ <AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>Delete Question</AlertDialogTitle>+ <AlertDialogDescription>+ Are you sure you want to delete this question? This action cannot+ be undone.+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogCancel>Cancel</AlertDialogCancel>+ <AlertDialogAction+ onClick={() => onDelete(question.id)}+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90"+ >+ Delete+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ </>+ );+}diff --git a/src/components/questions/QuestionForm.tsx b/src/components/questions/QuestionForm.tsxnew file mode 100644index 0000000..42fcb28--- /dev/null+++ b/src/components/questions/QuestionForm.tsx@@ -0,0 +1,192 @@+"use client";+import {+ Dialog,+ DialogContent,+ DialogHeader,+ DialogOverlay,+ DialogTitle,+ DialogFooter,+} from "@/components/ui/dialog";+import { createQuestion, updateQuestion } from "@/actions/question.actions";+import { Loader } from "lucide-react";+import { Button } from "../ui/button";+import { useForm } from "react-hook-form";+import { useEffect, useTransition } from "react";+import { AddQuestionFormSchema } from "@/models/addQuestionForm.schema";+import { zodResolver } from "@hookform/resolvers/zod";+import { Question } from "@/models/question.model";+import { Tag } from "@/models/job.model";+import { z } from "zod";+import { toast } from "../ui/use-toast";+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "../ui/form";+import { Input } from "../ui/input";+import TiptapEditor from "../TiptapEditor";+import { TagInput } from "../myjobs/TagInput";++type QuestionFormProps = {+ availableTags: Tag[];+ editQuestion?: Question | null;+ resetEditQuestion: () => void;+ onQuestionSaved: () => void;+ dialogOpen: boolean;+ setDialogOpen: (open: boolean) => void;+};++export function QuestionForm({+ availableTags,+ editQuestion,+ resetEditQuestion,+ onQuestionSaved,+ dialogOpen,+ setDialogOpen,+}: QuestionFormProps) {+ const [isPending, startTransition] = useTransition();+ const form = useForm<z.infer<typeof AddQuestionFormSchema>>({+ resolver: zodResolver(AddQuestionFormSchema),+ defaultValues: {+ question: "",+ answer: "",+ tagIds: [],+ },+ });++ const { reset } = form;++ useEffect(() => {+ if (editQuestion) {+ reset({+ id: editQuestion.id,+ question: editQuestion.question,+ answer: editQuestion.answer || "",+ tagIds: editQuestion.tags?.map((t) => t.id) || [],+ });+ } else {+ reset({+ question: "",+ answer: "",+ tagIds: [],+ });+ }+ }, [editQuestion, reset]);++ function onSubmit(data: z.infer<typeof AddQuestionFormSchema>) {+ startTransition(async () => {+ const { success, message } = editQuestion+ ? await updateQuestion(data)+ : await createQuestion(data);++ if (success) {+ toast({+ variant: "success",+ description: `Question has been ${editQuestion ? "updated" : "created"} successfully`,+ });+ reset();+ setDialogOpen(false);+ resetEditQuestion();+ onQuestionSaved();+ } else {+ toast({+ variant: "destructive",+ title: "Error!",+ description: message,+ });+ }+ });+ }++ const pageTitle = editQuestion ? "Edit Question" : "Add Question";++ const closeDialog = () => {+ reset();+ resetEditQuestion();+ setDialogOpen(false);+ };++ return (+ <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>+ <DialogOverlay>+ <DialogContent className="sm:max-w-[725px] max-h-[90vh] overflow-y-auto">+ <DialogHeader>+ <DialogTitle>{pageTitle}</DialogTitle>+ </DialogHeader>+ <Form {...form}>+ <form+ onSubmit={form.handleSubmit(onSubmit)}+ className="grid grid-cols-1 gap-4 p-4"+ >+ <FormField+ control={form.control}+ name="question"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <FormLabel>Question *</FormLabel>+ <FormControl>+ <Input placeholder="Enter interview question" {...field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ <FormField+ control={form.control}+ name="tagIds"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <FormLabel>Skill Tags</FormLabel>+ <FormControl>+ <TagInput+ availableTags={availableTags}+ selectedTagIds={field.value || []}+ onChange={field.onChange}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ <FormField+ control={form.control}+ name="answer"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <FormLabel>Answer</FormLabel>+ <FormControl>+ <TiptapEditor field={field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ <DialogFooter>+ <Button+ type="reset"+ variant="outline"+ className="mt-2 md:mt-0"+ onClick={closeDialog}+ >+ Cancel+ </Button>+ <Button type="submit">+ Save+ {isPending && (+ <Loader className="h-4 w-4 shrink-0 spinner ml-2" />+ )}+ </Button>+ </DialogFooter>+ </form>+ </Form>+ </DialogContent>+ </DialogOverlay>+ </Dialog>+ );+}diff --git a/src/components/questions/QuestionList.tsx b/src/components/questions/QuestionList.tsxnew file mode 100644index 0000000..54ad1e3--- /dev/null+++ b/src/components/questions/QuestionList.tsx@@ -0,0 +1,32 @@+"use client";+import { Question } from "@/models/question.model";+import { QuestionCard } from "./QuestionCard";++type QuestionListProps = {+ questions: Question[];+ onEdit: (question: Question) => void;+ onDelete: (questionId: string) => void;+};++export function QuestionList({ questions, onEdit, onDelete }: QuestionListProps) {+ if (questions.length === 0) {+ return (+ <div className="text-center py-8 text-muted-foreground">+ No questions found. Create your first question to get started.+ </div>+ );+ }++ return (+ <div className="space-y-3">+ {questions.map((question) => (+ <QuestionCard+ key={question.id}+ question={question}+ onEdit={onEdit}+ onDelete={onDelete}+ />+ ))}+ </div>+ );+}diff --git a/src/components/questions/QuestionsContainer.tsx b/src/components/questions/QuestionsContainer.tsxnew file mode 100644index 0000000..f120042--- /dev/null+++ b/src/components/questions/QuestionsContainer.tsx@@ -0,0 +1,228 @@+"use client";+import { useCallback, useEffect, useRef, useState } from "react";+import {+ Card,+ CardContent,+ CardFooter,+ CardHeader,+ CardTitle,+} from "../ui/card";+import { Button } from "../ui/button";+import { PlusCircle, Search } from "lucide-react";+import { Input } from "../ui/input";+import {+ deleteQuestion,+ getQuestionById,+ getQuestionsList,+} from "@/actions/question.actions";+import { toast } from "../ui/use-toast";+import { Question } from "@/models/question.model";+import { Tag } from "@/models/job.model";+import { RecordsPerPageSelector } from "../RecordsPerPageSelector";+import { RecordsCount } from "../RecordsCount";+import { APP_CONSTANTS } from "@/lib/constants";+import Loading from "../Loading";+import { QuestionList } from "./QuestionList";+import { QuestionForm } from "./QuestionForm";++type QuestionsContainerProps = {+ availableTags: Tag[];+ filterKey?: string;+ onQuestionsChanged?: () => void;+};++function QuestionsContainer({+ availableTags,+ filterKey,+ onQuestionsChanged,+}: QuestionsContainerProps) {+ const [questions, setQuestions] = useState<Question[]>([]);+ const [page, setPage] = useState(1);+ const [totalQuestions, setTotalQuestions] = useState(0);+ const [editQuestion, setEditQuestion] = useState<Question | null>(null);+ const [loading, setLoading] = useState(false);+ const [dialogOpen, setDialogOpen] = useState(false);+ const [recordsPerPage, setRecordsPerPage] = useState<number>(+ APP_CONSTANTS.RECORDS_PER_PAGE+ );+ const [searchTerm, setSearchTerm] = useState("");+ const hasSearched = useRef(false);++ const loadQuestions = useCallback(+ async (pageNum: number, filter?: string, search?: string) => {+ setLoading(true);+ const result = await getQuestionsList(+ pageNum,+ recordsPerPage,+ filter,+ search+ );+ if (result?.success && result.data) {+ setQuestions((prev) =>+ pageNum === 1 ? result.data : [...prev, ...result.data]+ );+ setTotalQuestions(result.total);+ setPage(pageNum);+ } else {+ toast({+ variant: "destructive",+ title: "Error!",+ description: result?.message || "Failed to load questions.",+ });+ }+ setLoading(false);+ },+ [recordsPerPage]+ );++ const reloadQuestions = useCallback(async () => {+ await loadQuestions(1, filterKey, searchTerm || undefined);+ onQuestionsChanged?.();+ }, [loadQuestions, filterKey, searchTerm, onQuestionsChanged]);++ const onDeleteQuestion = async (questionId: string) => {+ const { success, message } = await deleteQuestion(questionId);+ if (success) {+ toast({+ variant: "success",+ description: "Question has been deleted successfully",+ });+ reloadQuestions();+ } else {+ toast({+ variant: "destructive",+ title: "Error!",+ description: message,+ });+ }+ };++ const onEditQuestion = async (question: Question) => {+ const { data, success, message } = await getQuestionById(question.id);+ if (!success) {+ toast({+ variant: "destructive",+ title: "Error!",+ description: message,+ });+ return;+ }+ setEditQuestion(data);+ setDialogOpen(true);+ };++ const addQuestionForm = () => {+ setEditQuestion(null);+ setDialogOpen(true);+ };++ useEffect(() => {+ loadQuestions(1, filterKey, searchTerm || undefined);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [loadQuestions, filterKey, recordsPerPage]);++ // Debounced search+ useEffect(() => {+ if (searchTerm !== "") {+ hasSearched.current = true;+ }+ if (searchTerm === "" && !hasSearched.current) return;++ const timer = setTimeout(() => {+ loadQuestions(1, filterKey, searchTerm || undefined);+ }, 300);+ return () => clearTimeout(timer);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [searchTerm]);++ return (+ <>+ <Card className="h-full">+ <CardHeader className="flex-row justify-between items-center">+ <CardTitle>Question Bank</CardTitle>+ <div className="flex items-center">+ <div className="ml-auto flex items-center gap-2">+ <div className="relative">+ <Search className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground" />+ <Input+ type="search"+ placeholder="Search questions..."+ className="pl-8 h-8 w-[150px] lg:w-[200px]"+ value={searchTerm}+ onChange={(e) => setSearchTerm(e.target.value)}+ />+ </div>+ <Button+ size="sm"+ variant="outline"+ className="h-8 gap-1"+ onClick={addQuestionForm}+ >+ <PlusCircle className="h-3.5 w-3.5" />+ <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">+ New Question+ </span>+ </Button>+ </div>+ </div>+ </CardHeader>+ <CardContent>+ {loading && <Loading />}+ {!loading && (+ <>+ <QuestionList+ questions={questions}+ onEdit={onEditQuestion}+ onDelete={onDeleteQuestion}+ />+ {questions.length > 0 && (+ <div className="flex items-center justify-between mt-4">+ <RecordsCount+ count={questions.length}+ total={totalQuestions}+ label="questions"+ />+ {totalQuestions > APP_CONSTANTS.RECORDS_PER_PAGE && (+ <RecordsPerPageSelector+ value={recordsPerPage}+ onChange={setRecordsPerPage}+ />+ )}+ </div>+ )}+ </>+ )}+ {!loading && questions.length < totalQuestions && (+ <div className="flex justify-center p-4">+ <Button+ size="sm"+ variant="outline"+ onClick={() =>+ loadQuestions(+ page + 1,+ filterKey,+ searchTerm || undefined+ )+ }+ disabled={loading}+ >+ Load More+ </Button>+ </div>+ )}+ </CardContent>+ <CardFooter></CardFooter>+ </Card>+ <QuestionForm+ availableTags={availableTags}+ editQuestion={editQuestion}+ resetEditQuestion={() => setEditQuestion(null)}+ onQuestionSaved={reloadQuestions}+ dialogOpen={dialogOpen}+ setDialogOpen={setDialogOpen}+ />+ </>+ );+}++export default QuestionsContainer;diff --git a/src/components/questions/QuestionsSidebar.tsx b/src/components/questions/QuestionsSidebar.tsxnew file mode 100644index 0000000..9332448--- /dev/null+++ b/src/components/questions/QuestionsSidebar.tsx@@ -0,0 +1,70 @@+"use client";+import { cn } from "@/lib/utils";++type TagWithCount = {+ id: string;+ label: string;+ value: string;+ questionCount: number;+};++type QuestionsSidebarProps = {+ tags: TagWithCount[];+ totalQuestions: number;+ selectedFilter?: string;+ onFilterChange: (filter: string | undefined) => void;+};++function QuestionsSidebar({+ tags,+ totalQuestions,+ selectedFilter,+ onFilterChange,+}: QuestionsSidebarProps) {+ return (+ <div className="w-48 border-r py-4 hidden md:block h-full">+ <h3 className="font-semibold mb-4 text-sm">Skill Tags</h3>+ <ul className="space-y-1">+ <li>+ <button+ onClick={() => onFilterChange(undefined)}+ className={cn(+ "w-full text-left px-3 py-2 rounded-md text-sm transition-colors",+ "hover:bg-accent hover:text-accent-foreground",+ !selectedFilter && "bg-accent text-accent-foreground font-medium"+ )}+ >+ <span className="flex justify-between items-center">+ <span>All</span>+ <span className="text-muted-foreground text-xs">+ {totalQuestions}+ </span>+ </span>+ </button>+ </li>+ {tags.map((tag) => (+ <li key={tag.id}>+ <button+ onClick={() => onFilterChange(tag.id)}+ className={cn(+ "w-full text-left px-3 py-2 rounded-md text-sm transition-colors",+ "hover:bg-accent hover:text-accent-foreground",+ selectedFilter === tag.id &&+ "bg-accent text-accent-foreground font-medium"+ )}+ >+ <span className="flex justify-between items-center">+ <span className="truncate">{tag.label}</span>+ <span className="text-muted-foreground text-xs">+ {tag.questionCount}+ </span>+ </span>+ </button>+ </li>+ ))}+ </ul>+ </div>+ );+}++export default QuestionsSidebar;diff --git a/src/lib/constants.ts b/src/lib/constants.tsindex 52ab5e5..d5e392d 100644--- a/src/lib/constants.ts+++ b/src/lib/constants.ts@@ -7,6 +7,7 @@ import {Sheet,Wrench,Zap,+ BookOpen,} from "lucide-react";export const APP_CONSTANTS = {@@ -70,6 +71,11 @@ export const SIDEBAR_LINKS = [route: "/dashboard/activities",label: "Activities",},+ {+ icon: BookOpen,+ route: "/dashboard/questions",+ label: "Question Bank",+ },{icon: UserRound,route: "/dashboard/profile",diff --git a/src/models/addQuestionForm.schema.ts b/src/models/addQuestionForm.schema.tsnew file mode 100644index 0000000..22a9ff4--- /dev/null+++ b/src/models/addQuestionForm.schema.ts@@ -0,0 +1,17 @@+import { z } from "zod";++export const AddQuestionFormSchema = z.object({+ id: z.string().optional(),+ question: z+ .string({ error: "Question is required." })+ .min(2, { message: "Question must be at least 2 characters." }),+ answer: z+ .string()+ .max(5000, { message: "Answer cannot exceed 5000 characters." })+ .optional()+ .nullable(),+ tagIds: z+ .array(z.string())+ .max(10, { message: "Maximum 10 skill tags allowed." })+ .optional(),+});diff --git a/src/models/question.model.ts b/src/models/question.model.tsnew file mode 100644index 0000000..00a18d2--- /dev/null+++ b/src/models/question.model.ts@@ -0,0 +1,11 @@+import { Tag } from "./job.model";++export interface Question {+ id: string;+ question: string;+ answer?: string | null;+ createdBy: string;+ tags: Tag[];+ createdAt: Date;+ updatedAt: Date;+}