feat: FAQ controller made
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled

This commit is contained in:
2025-10-27 15:18:31 +05:45
parent db9315ad22
commit 48e089d3c8
13 changed files with 274 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 589 KiB

View File

@@ -0,0 +1,91 @@
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import AppLayout from '@/layouts/app-layout';
import dashboard from '@/routes/dashboard';
import { Head, useForm } from '@inertiajs/react';
import FilePondPluginImageExifOrientation from 'filepond-plugin-image-exif-orientation';
import FilePondPluginImagePreview from 'filepond-plugin-image-preview';
import 'filepond-plugin-image-preview/dist/filepond-plugin-image-preview.css';
import 'filepond/dist/filepond.min.css';
import { registerPlugin } from 'react-filepond';
import { toast } from 'sonner';
registerPlugin(FilePondPluginImageExifOrientation, FilePondPluginImagePreview);
export default function FaqAdd() {
const { data, setData, post, processing, errors, wasSuccessful } = useForm({
question: '',
answer: '',
});
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
post(dashboard.faq.addFaq().url, {
forceFormData: true,
});
if (wasSuccessful) {
toast.success('Product added successfully');
}
};
return (
<AppLayout>
<Head title="Add FAQ Questions" />
<section className="flex flex-col gap-8 px-8 py-8">
<h1 className="text-lg font-semibold tracking-tight">
Add FAQ Questions
</h1>
<form
onSubmit={handleSubmit}
method="POST"
encType="multipart/formdata"
className="flex flex-col items-start gap-4"
>
<div className="flex w-full flex-col gap-2">
<Label htmlFor="question">Question</Label>
<Input
type="text"
id="question"
value={data.question}
onChange={(e) =>
setData('question', e.target.value)
}
className="rounded border p-2"
/>
{errors.question && (
<span className="text-red-600">
{errors.question}
</span>
)}
</div>
<div className="flex w-full flex-col gap-2">
<Label htmlFor="answer">Answer</Label>
<Input
type="text"
id="answer"
value={data.answer}
onChange={(e) => setData('answer', e.target.value)}
className="rounded border p-2"
/>
{errors.answer && (
<span className="text-red-600">
{errors.answer}
</span>
)}
</div>
<Button
type="submit"
disabled={processing}
className="cursor-pointer"
>
{processing ? 'submitting...' : 'Submit'}
</Button>
</form>
</section>
</AppLayout>
);
}

View File

@@ -0,0 +1,76 @@
import { Button } from '@/components/ui/button';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
import AppLayout from '@/layouts/app-layout';
import dashboard from '@/routes/dashboard';
import { Head, Link } from '@inertiajs/react';
import { Pencil, Trash2 } from 'lucide-react';
export default function Faq({
faq,
}: {
faq: [{ question: string; answer: string }];
}) {
return (
<AppLayout
breadcrumbs={[
{ title: 'FAQs', href: dashboard.product.index().url },
]}
>
<Head title="FAQs" />
<section className="flex flex-col gap-8 px-8 py-8">
<div className="flex items-center justify-between">
<h1 className="text-xl font-semibold tracking-tight">
FAQs
</h1>
<Link href={dashboard.faq.add()}>
<Button className="cursor-pointer">
Add Questions
</Button>
</Link>
</div>
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-[80px]">S.N.</TableHead>
<TableHead>Question</TableHead>
<TableHead>Answer</TableHead>
<TableHead className="text-right">Action</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{faq.map((item, index) => (
<TableRow key={index}>
<TableCell className="font-medium">
{index + 1}
</TableCell>
<TableCell>{item.question}</TableCell>
<TableCell>{item.answer}</TableCell>
<TableCell className="text-right">
<div className="flex items-center justify-end gap-2">
<Link href="">
<Pencil size={18} />
</Link>
<Link href="">
<Trash2
size={18}
color={'#D2042D'}
/>
</Link>
</div>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</section>
</AppLayout>
);
}

View File

@@ -13,7 +13,11 @@ import img3 from '@asset/img/Bespoke/Shrek.jpg';
import img2 from '@asset/img/Bespoke/Swarovsky embedded wall hang.jpg';
import { Head, Link } from '@inertiajs/react';
export default function Faq() {
export default function Faq({
faq,
}: {
faq: [{ id: number; question: string; answer: string }];
}) {
return (
<>
<Layout>
@@ -67,7 +71,7 @@ export default function Faq() {
type="single"
collapsible
className="w-full"
defaultValue="item-1"
defaultValue="1"
>
{faq.map((item) => (
<AccordionItem value={`${item.id}`}>