Spaces:
Sleeping
Sleeping
File size: 8,164 Bytes
db983c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | "use client";
import { useState, useEffect } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { X, Save, RotateCcw, Check } from "lucide-react";
import { Button } from "@/components/ui/Button";
import { CHATBOT_CONFIG, type ChatbotConfig, getChatbotConfig, saveChatbotConfig, resetChatbotConfig } from "@/lib/chatbotConfig";
import { cn } from "@/lib/utils";
interface SettingsModalProps {
isOpen: boolean;
onClose: () => void;
}
export function SettingsModal({ isOpen, onClose }: SettingsModalProps) {
const [config, setConfig] = useState<ChatbotConfig>(CHATBOT_CONFIG);
const [saved, setSaved] = useState(false);
// Load current config when modal opens
useEffect(() => {
if (isOpen) {
setConfig(getChatbotConfig());
setSaved(false);
}
}, [isOpen]);
const handleChange = (field: keyof ChatbotConfig, value: string) => {
setConfig((prev) => ({ ...prev, [field]: value }));
};
const handleSave = () => {
saveChatbotConfig(config);
setSaved(true);
// Close after showing success
setTimeout(() => {
onClose();
}, 800);
};
const handleReset = () => {
setConfig(CHATBOT_CONFIG);
resetChatbotConfig();
};
return (
<AnimatePresence>
{isOpen && (
<>
{/* Backdrop */}
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.2 }}
className="fixed inset-0 bg-black/40 backdrop-blur-sm z-50"
onClick={onClose}
/>
{/* Modal */}
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<motion.div
initial={{ opacity: 0, scale: 0.95, y: 8 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.95, y: 8 }}
transition={{ duration: 0.2, ease: "easeOut" }}
className="w-full max-w-md bg-white rounded-2xl shadow-2xl overflow-hidden"
onClick={(e) => e.stopPropagation()}
>
{/* Header */}
<div className="flex items-center justify-between px-6 py-4 border-b border-neutral-100">
<h2 className="text-lg font-semibold text-neutral-900">
Pengaturan Chatbot
</h2>
<button
onClick={onClose}
className="p-1.5 rounded-lg text-neutral-400 hover:bg-neutral-100 hover:text-neutral-700 transition-colors"
>
<X className="h-4 w-4" />
</button>
</div>
{/* Body */}
<div className="px-6 py-5 space-y-5">
{/* Name */}
<div className="flex flex-col gap-2">
<label className="text-sm font-medium text-neutral-700">
Nama Chatbot
</label>
<input
type="text"
value={config.name}
onChange={(e) => handleChange("name", e.target.value)}
maxLength={30}
className="w-full rounded-xl border border-neutral-200 bg-white px-4 py-2.5 text-sm text-neutral-900 placeholder:text-neutral-400 transition-all duration-200 outline-none focus:border-brand-green focus:ring-3 focus:ring-brand-green/10"
placeholder="Contoh: EMA"
/>
<p className="text-xs text-neutral-400">{config.name.length}/30 karakter</p>
</div>
{/* Caption */}
<div className="flex flex-col gap-2">
<label className="text-sm font-medium text-neutral-700">
Caption / Tagline
</label>
<input
type="text"
value={config.caption}
onChange={(e) => handleChange("caption", e.target.value)}
maxLength={50}
className="w-full rounded-xl border border-neutral-200 bg-white px-4 py-2.5 text-sm text-neutral-900 placeholder:text-neutral-400 transition-all duration-200 outline-none focus:border-brand-green focus:ring-3 focus:ring-brand-green/10"
placeholder="Contoh: Expert Mining Assistant"
/>
<p className="text-xs text-neutral-400">{config.caption.length}/50 karakter</p>
</div>
{/* Description */}
<div className="flex flex-col gap-2">
<label className="text-sm font-medium text-neutral-700">
Deskripsi
</label>
<textarea
value={config.description}
onChange={(e) => handleChange("description", e.target.value)}
maxLength={200}
rows={3}
className="w-full rounded-xl border border-neutral-200 bg-white px-4 py-2.5 text-sm text-neutral-900 placeholder:text-neutral-400 transition-all duration-200 outline-none focus:border-brand-green focus:ring-3 focus:ring-brand-green/10 resize-none"
placeholder="Deskripsi singkat tentang chatbot"
/>
<p className="text-xs text-neutral-400">{config.description.length}/200 karakter</p>
</div>
{/* Preview */}
<div className="p-3 rounded-xl bg-neutral-50 border border-neutral-100">
<p className="text-xs font-medium text-neutral-400 mb-2">Preview</p>
<p className="text-sm font-semibold text-neutral-900">{config.name}</p>
<p className="text-xs text-neutral-500">{config.caption}</p>
<p className="text-xs text-neutral-400 mt-1 leading-relaxed line-clamp-2">{config.description}</p>
</div>
</div>
{/* Footer */}
<div className="flex items-center justify-between px-6 py-4 border-t border-neutral-100 bg-neutral-50/50">
<Button
variant="ghost"
size="sm"
onClick={handleReset}
className="text-neutral-500"
>
<RotateCcw className="h-3.5 w-3.5" />
Reset
</Button>
<div className="flex items-center gap-2">
<Button
variant="secondary"
size="sm"
onClick={onClose}
>
Batal
</Button>
<AnimatePresence mode="wait">
{saved ? (
<motion.div
key="saved"
initial={{ opacity: 0, scale: 0.9 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.9 }}
className="inline-flex items-center gap-1.5 px-4 py-2 rounded-xl bg-green-500 text-white text-sm font-semibold"
>
<Check className="h-3.5 w-3.5" />
Tersimpan
</motion.div>
) : (
<motion.div
key="save"
initial={{ opacity: 0, scale: 0.9 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.9 }}
>
<Button
variant="primary"
size="sm"
onClick={handleSave}
>
<Save className="h-3.5 w-3.5" />
Simpan
</Button>
</motion.div>
)}
</AnimatePresence>
</div>
</div>
</motion.div>
</div>
</>
)}
</AnimatePresence>
);
}
|