"use client" import { useState } from "react" import { useForm } from "react-hook-form" import { zodResolver } from "@hookform/resolvers/zod" import * as z from "zod" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { toast } from "sonner" import { Loader2, Send } from "lucide-react" import { updateSmsSettings, sendTestSms } from "@/lib/sms/actions" const smsSettingsSchema = z.object({ username: z.string().min(1, "Kullanıcı adı gereklidir."), password: z.string().optional(), header: z.string().min(1, "Başlık (Gönderici Adı) gereklidir."), }) type SmsSettingsValues = z.infer interface SmsSettingsFormProps { initialData: { username: string header: string } | null } export function SmsSettingsForm({ initialData }: SmsSettingsFormProps) { const [loading, setLoading] = useState(false) const [testLoading, setTestLoading] = useState(false) const [testPhone, setTestPhone] = useState("") const form = useForm({ resolver: zodResolver(smsSettingsSchema), defaultValues: { username: initialData?.username || "", header: initialData?.header || "", password: "", }, }) const onSubmit = async (data: SmsSettingsValues) => { setLoading(true) try { const result = await updateSmsSettings({ username: data.username, password: data.password, header: data.header, }) if (result.error) { toast.error(result.error) return } toast.success("SMS ayarları güncellendi.") // Don't reset form fully, keeps values visible except password form.setValue("password", "") } catch { toast.error("Bir sorun oluştu.") } finally { setLoading(false) } } const onTestSms = async () => { if (!testPhone) { toast.error("Lütfen bir test numarası girin.") return } setTestLoading(true) try { const result = await sendTestSms(testPhone) if (result.error) { toast.error("Test başarısız: " + result.error) } else { toast.success("Test SMS başarıyla gönderildi!") } } catch { toast.error("Test sırasında bir hata oluştu.") } finally { setTestLoading(false) } } return (
NetGSM Konfigürasyonu NetGSM API bilgilerinizi buradan yönetebilirsiniz. Şifre alanı sadece değiştirmek istediğinizde gereklidir.
( NetGSM Kullanıcı Adı (850...) )} /> ( Şifre Mevcut şifreyi korumak için boş bırakın. )} /> ( Mesaj Başlığı (Gönderici Adı) NetGSM panelinde tanımlı gönderici adınız. )} />
Bağlantı Testi Ayarların doğru çalıştığını doğrulamak için test SMS gönderin.
setTestPhone(e.target.value)} />

Başında 0 olmadan 10 hane giriniz.

) }