"use client"; import * as React from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Separator } from "@/components/ui/separator"; import { Switch } from "@/components/ui/switch"; import { Textarea } from "@/components/ui/textarea"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { IconBell, IconBriefcase, IconKey, IconShield, IconUser, } from "@tabler/icons-react"; import { toast } from "sonner"; import { getAdminSettings, updateAdminSettings, } from "@/lib/actions/settings-actions"; type User = { id: string; name: string; email: string; role?: string; }; type AdminSettingsContentProps = { user: User; }; export function AdminSettingsContent({}: AdminSettingsContentProps) { const [isLoading, setIsLoading] = React.useState(false); // General Settings State const [clinicName, setClinicName] = React.useState("Dental U-Care"); const [clinicEmail, setClinicEmail] = React.useState("info@dentalucare.com"); const [clinicPhone, setClinicPhone] = React.useState("+1 (555) 123-4567"); const [clinicAddress, setClinicAddress] = React.useState( "123 Medical Plaza, Suite 100" ); const [timezone, setTimezone] = React.useState("America/New_York"); // Appointment Settings State const [appointmentDuration, setAppointmentDuration] = React.useState("60"); const [bufferTime, setBufferTime] = React.useState("15"); const [maxAdvanceBooking, setMaxAdvanceBooking] = React.useState("90"); const [cancellationDeadline, setCancellationDeadline] = React.useState("24"); const [autoConfirmAppointments, setAutoConfirmAppointments] = React.useState(false); // Notification Settings State const [emailNotifications, setEmailNotifications] = React.useState(true); const [smsNotifications, setSmsNotifications] = React.useState(true); const [appointmentReminders, setAppointmentReminders] = React.useState(true); const [reminderHoursBefore, setReminderHoursBefore] = React.useState("24"); const [newBookingNotifications, setNewBookingNotifications] = React.useState(true); const [cancellationNotifications, setCancellationNotifications] = React.useState(true); // Payment Settings State const [requirePaymentUpfront, setRequirePaymentUpfront] = React.useState(false); const [allowPartialPayment, setAllowPartialPayment] = React.useState(true); const [depositPercentage, setDepositPercentage] = React.useState("50"); const [acceptCash, setAcceptCash] = React.useState(true); const [acceptCard, setAcceptCard] = React.useState(true); const [acceptEWallet, setAcceptEWallet] = React.useState(true); // Security Settings State const [twoFactorAuth, setTwoFactorAuth] = React.useState(false); const [sessionTimeout, setSessionTimeout] = React.useState("60"); const [passwordExpiry, setPasswordExpiry] = React.useState("90"); const [loginAttempts, setLoginAttempts] = React.useState("5"); // Load settings on mount React.useEffect(() => { const loadSettings = async () => { try { const settings = await getAdminSettings(); if (settings) { setClinicName(settings.clinicName); setClinicEmail(settings.clinicEmail); setClinicPhone(settings.clinicPhone); setClinicAddress(settings.clinicAddress); setTimezone(settings.timezone); setAppointmentDuration(settings.appointmentDuration); setBufferTime(settings.bufferTime); setMaxAdvanceBooking(settings.maxAdvanceBooking); setCancellationDeadline(settings.cancellationDeadline); setAutoConfirmAppointments(settings.autoConfirmAppointments); setEmailNotifications(settings.emailNotifications); setSmsNotifications(settings.smsNotifications); setAppointmentReminders(settings.appointmentReminders); setReminderHoursBefore(settings.reminderHoursBefore); setNewBookingNotifications(settings.newBookingNotifications); setCancellationNotifications(settings.cancellationNotifications); setRequirePaymentUpfront(settings.requirePaymentUpfront); setAllowPartialPayment(settings.allowPartialPayment); setDepositPercentage(settings.depositPercentage); setAcceptCash(settings.acceptCash); setAcceptCard(settings.acceptCard); setAcceptEWallet(settings.acceptEWallet); setTwoFactorAuth(settings.twoFactorAuth); setSessionTimeout(settings.sessionTimeout); setPasswordExpiry(settings.passwordExpiry); setLoginAttempts(settings.loginAttempts); } } catch (error) { console.error("Failed to load admin settings:", error); toast.error("Failed to load settings"); } }; loadSettings(); }, []); const handleSaveGeneral = async () => { setIsLoading(true); try { const result = await updateAdminSettings({ clinicName, clinicEmail, clinicPhone, clinicAddress, timezone, }); if (result.success) { toast.success(result.message); } else { toast.error(result.message); } } catch (error) { toast.error("Failed to save general settings"); console.error(error); } finally { setIsLoading(false); } }; const handleSaveAppointments = async () => { setIsLoading(true); try { const result = await updateAdminSettings({ appointmentDuration, bufferTime, maxAdvanceBooking, cancellationDeadline, autoConfirmAppointments, }); if (result.success) { toast.success(result.message); } else { toast.error(result.message); } } catch (error) { toast.error("Failed to save appointment settings"); console.error(error); } finally { setIsLoading(false); } }; const handleSaveNotifications = async () => { setIsLoading(true); try { const result = await updateAdminSettings({ emailNotifications, smsNotifications, appointmentReminders, reminderHoursBefore, newBookingNotifications, cancellationNotifications, }); if (result.success) { toast.success(result.message); } else { toast.error(result.message); } } catch (error) { toast.error("Failed to save notification settings"); console.error(error); } finally { setIsLoading(false); } }; const handleSavePayments = async () => { setIsLoading(true); try { const result = await updateAdminSettings({ requirePaymentUpfront, allowPartialPayment, depositPercentage, acceptCash, acceptCard, acceptEWallet, }); if (result.success) { toast.success(result.message); } else { toast.error(result.message); } } catch (error) { toast.error("Failed to save payment settings"); console.error(error); } finally { setIsLoading(false); } }; const handleSaveSecurity = async () => { setIsLoading(true); try { const result = await updateAdminSettings({ twoFactorAuth, sessionTimeout, passwordExpiry, loginAttempts, }); if (result.success) { toast.success(result.message); } else { toast.error(result.message); } } catch (error) { toast.error("Failed to save security settings"); console.error(error); } finally { setIsLoading(false); } }; return (

Admin Settings

Manage your clinic settings and preferences

General Appointments Notifications Payments Security {/* General Settings */} Clinic Information Update your clinic's basic information and contact details
setClinicName(e.target.value)} placeholder="Dental U-Care" />
setClinicEmail(e.target.value)} placeholder="info@dentalucare.com" />
setClinicPhone(e.target.value)} placeholder="+1 (555) 123-4567" />