From 1a2241c40e10193c5ff7008a7b7b36cc1d855d96 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Tue, 25 Mar 2025 15:55:45 +0900 Subject: initial commit --- components/faq/FaqCard.tsx | 36 ++++++++ components/faq/FaqManager.tsx | 192 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100644 components/faq/FaqCard.tsx create mode 100644 components/faq/FaqManager.tsx (limited to 'components/faq') diff --git a/components/faq/FaqCard.tsx b/components/faq/FaqCard.tsx new file mode 100644 index 00000000..ef622e67 --- /dev/null +++ b/components/faq/FaqCard.tsx @@ -0,0 +1,36 @@ +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" + +export interface FaqItem { + title: string; + content: string[]; +} + +export interface FaqCategory { + label: string; // 카테고리 이름 (식별자로도 사용) + items: { + title: string; + content: string[]; + }[]; +} + +interface FaqCardProps { + item: FaqItem; +} + +export function FaqCard({ item }: FaqCardProps) { + return ( + + + {item.title} + + + {item.content.map((line, index) => ( + + {line} + {index < item.content.length - 1 && } + + ))} + + + ) +} \ No newline at end of file diff --git a/components/faq/FaqManager.tsx b/components/faq/FaqManager.tsx new file mode 100644 index 00000000..27755270 --- /dev/null +++ b/components/faq/FaqManager.tsx @@ -0,0 +1,192 @@ +'use client'; + +import { useState } from 'react'; +import { FaqCategory } from './FaqCard'; +import { Button } from '@/components/ui/button'; +import { Card, CardContent } from '@/components/ui/card'; +import { Input } from '@/components/ui/input'; +import { Textarea } from '@/components/ui/textarea'; +import { Plus, Trash, Save, Settings } from 'lucide-react'; +import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; +import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; +import { useRouter } from 'next/navigation'; + +interface FaqManagerProps { + initialData: FaqCategory[]; + onSave: (data: FaqCategory[]) => Promise; + lng: string; +} + +export function FaqManager({ initialData, onSave, lng }: FaqManagerProps) { + const [categories, setCategories] = useState(initialData); + const [activeTab, setActiveTab] = useState(categories[0]?.label || ''); + const [isSettingsView, setIsSettingsView] = useState(false); + const [showSaveDialog, setShowSaveDialog] = useState(false); + const router = useRouter(); + + const addCategory = () => { + const newCategory = { + label: 'New Category', + items: [] + }; + setCategories([...categories, newCategory]); + setActiveTab(newCategory.label); + }; + + const addItem = (categoryIndex: number) => { + const newCategories = [...categories]; + newCategories[categoryIndex].items.push({ + title: 'New FAQ Item', + content: ['Enter content here'] + }); + setCategories(newCategories); + }; + + const handleSave = async () => { + await onSave(categories); + setShowSaveDialog(false); + router.push(`/${lng}/evcp/faq`); + }; + + const updateCategory = (index: number, label: string) => { + const newCategories = [...categories]; + newCategories[index] = { ...newCategories[index], label }; + setCategories(newCategories); + if (activeTab === categories[index].label) { + setActiveTab(label); + } + }; + + const updateItem = (categoryIndex: number, itemIndex: number, field: 'title' | 'content', value: string | string[]) => { + const newCategories = [...categories]; + if (field === 'content') { + newCategories[categoryIndex].items[itemIndex][field] = (value as string).split('\n'); + } else { + newCategories[categoryIndex].items[itemIndex][field] = value as string; + } + setCategories(newCategories); + }; + + const removeCategory = (index: number) => { + const newCategories = categories.filter((_, i) => i !== index); + setCategories(newCategories); + setActiveTab(newCategories[0]?.label || ''); + }; + + const removeItem = (categoryIndex: number, itemIndex: number) => { + const newCategories = [...categories]; + newCategories[categoryIndex].items = newCategories[categoryIndex].items.filter((_, i) => i !== itemIndex); + setCategories(newCategories); + }; + + return ( + + + + setIsSettingsView(true)} + > + + Category Settings + + setIsSettingsView(false)} + > + FAQ Management + + + setShowSaveDialog(true)}> + + Save Changes + + + + {isSettingsView ? ( + + {categories.map((category, index) => ( + + + updateCategory(index, e.target.value)} + className="flex-1" + placeholder="Category Name" + /> + removeCategory(index)}> + + + + + ))} + + + Add Category + + + ) : ( + + + {categories.map((category) => ( + + {category.label} + + ))} + + + {categories.map((category, categoryIndex) => ( + + {category.items.map((item, itemIndex) => ( + + + + updateItem(categoryIndex, itemIndex, 'title', e.target.value)} + className="flex-1 mr-2" + placeholder="Question" + /> + removeItem(categoryIndex, itemIndex)}> + + + + updateItem(categoryIndex, itemIndex, 'content', e.target.value)} + placeholder="Answer (separate lines with Enter)" + rows={3} + /> + + + ))} + addItem(categoryIndex)} className="w-full"> + + Add FAQ Item + + + ))} + + )} + + + + + Save Changes + + Are you sure you want to save the changes? This will update the FAQ data. + + + + setShowSaveDialog(false)}> + Cancel + + + Save + + + + + + ); +} \ No newline at end of file -- cgit v1.2.3