hata düzeltme 1
This commit is contained in:
53
components/dashboard/settings-tabs.tsx
Normal file
53
components/dashboard/settings-tabs.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
"use client"
|
||||
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
import { SiteSettingsForm } from "@/components/dashboard/site-settings-form"
|
||||
import { SmsSettingsForm } from "@/components/dashboard/sms-settings-form"
|
||||
import { AppearanceForm } from "@/components/dashboard/appearance-form"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
|
||||
interface SettingsTabsProps {
|
||||
siteSettings: Record<string, any> | null
|
||||
smsSettings: Record<string, any> | null
|
||||
}
|
||||
|
||||
export function SettingsTabs({ siteSettings, smsSettings }: SettingsTabsProps) {
|
||||
return (
|
||||
<Tabs defaultValue="general" className="space-y-4">
|
||||
<TabsList>
|
||||
<TabsTrigger value="general">Genel</TabsTrigger>
|
||||
<TabsTrigger value="sms">SMS / Bildirimler</TabsTrigger>
|
||||
<TabsTrigger value="appearance">Görünüm</TabsTrigger>
|
||||
<TabsTrigger value="security">Güvenlik</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="general" className="space-y-4">
|
||||
<SiteSettingsForm initialData={siteSettings} />
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="sms" className="space-y-4">
|
||||
<SmsSettingsForm initialData={smsSettings} />
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="appearance" className="space-y-4">
|
||||
<AppearanceForm />
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="security" className="space-y-4">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Hesap Güvenliği</CardTitle>
|
||||
<CardDescription>
|
||||
Şifre ve oturum yönetimi.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<Button variant="outline" className="w-full">Şifre Değiştir</Button>
|
||||
<Button variant="destructive" className="w-full">Hesabı Sil</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
)
|
||||
}
|
||||
198
components/dashboard/sms-settings-form.tsx
Normal file
198
components/dashboard/sms-settings-form.tsx
Normal file
@@ -0,0 +1,198 @@
|
||||
"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, CardFooter } from "@/components/ui/card"
|
||||
import { toast } from "sonner"
|
||||
import { Loader2, Smartphone, 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<typeof smsSettingsSchema>
|
||||
|
||||
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<SmsSettingsValues>({
|
||||
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 (
|
||||
<div className="grid gap-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>NetGSM Konfigürasyonu</CardTitle>
|
||||
<CardDescription>
|
||||
NetGSM API bilgilerinizi buradan yönetebilirsiniz. Şifre alanı sadece değiştirmek istediğinizde gereklidir.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="username"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>NetGSM Kullanıcı Adı (850...)</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="850xxxxxxx" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="password"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Şifre</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="password" placeholder="••••••••" {...field} />
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
Mevcut şifreyi korumak için boş bırakın.
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="header"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Mesaj Başlığı (Gönderici Adı)</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="PARAKASA" {...field} />
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
NetGSM panelinde tanımlı gönderici adınız.
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button type="submit" disabled={loading}>
|
||||
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
Ayarları Kaydet
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Bağlantı Testi</CardTitle>
|
||||
<CardDescription>
|
||||
Ayarların doğru çalıştığını doğrulamak için test SMS gönderin.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex gap-4">
|
||||
<div className="grid gap-2 flex-1">
|
||||
<Input
|
||||
placeholder="5551234567"
|
||||
value={testPhone}
|
||||
onChange={(e) => setTestPhone(e.target.value)}
|
||||
/>
|
||||
<p className="text-[0.8rem] text-muted-foreground">
|
||||
Başında 0 olmadan 10 hane giriniz.
|
||||
</p>
|
||||
</div>
|
||||
<Button variant="secondary" onClick={onTestSms} disabled={testLoading || !testPhone}>
|
||||
{testLoading ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Send className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
Test Gönder
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
55
components/ui/tabs.tsx
Normal file
55
components/ui/tabs.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Tabs = TabsPrimitive.Root
|
||||
|
||||
const TabsList = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.List>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.List
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsList.displayName = TabsPrimitive.List.displayName
|
||||
|
||||
const TabsTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
|
||||
|
||||
const TabsContent = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsContent.displayName = TabsPrimitive.Content.displayName
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
||||
Reference in New Issue
Block a user