sms entegrasyonu ve ana sayfa işlemleri

This commit is contained in:
2026-01-26 00:19:09 +03:00
parent 1e1baa84ff
commit 5c34df0f09
19 changed files with 1018 additions and 17 deletions

View File

@@ -13,7 +13,7 @@ export async function submitContactForm(data: ContactFormValues) {
await new Promise((resolve) => setTimeout(resolve, 1000))
// In a real app, you would use Resend or Nodemailer here
console.log("Contact Form Submitted:", result.data)
return { success: true, message: "Mesajınız başarıyla gönderildi." }
}

88
lib/customers/actions.ts Normal file
View File

@@ -0,0 +1,88 @@
'use server'
import { createClient } from "@/lib/supabase-server"
import { Customer, CustomerInsert, CustomerUpdate } from "@/types/customer"
import { revalidatePath } from "next/cache"
// Get all customers
export async function getCustomers() {
const supabase = createClient()
const { data, error } = await supabase
.from('customers')
.select('*')
.order('created_at', { ascending: false })
if (error) {
console.error('Error fetching customers:', error)
return { success: false, error: error.message }
}
return { success: true, data: data as Customer[] }
}
// Get customer by ID
export async function getCustomerById(id: number) {
const supabase = createClient()
const { data, error } = await supabase
.from('customers')
.select('*')
.eq('id', id)
.single()
if (error) {
return { success: false, error: error.message }
}
return { success: true, data: data as Customer }
}
// Add new customer
export async function addCustomer(customer: CustomerInsert) {
const supabase = createClient()
const { data, error } = await supabase
.from('customers')
.insert(customer)
.select()
.single()
if (error) {
return { success: false, error: error.message }
}
revalidatePath('/dashboard/customers')
return { success: true, data: data as Customer }
}
// Update existing customer
export async function updateCustomer(id: number, customer: CustomerUpdate) {
const supabase = createClient()
const { data, error } = await supabase
.from('customers')
.update({ ...customer, updated_at: new Date().toISOString() })
.eq('id', id)
.select()
.single()
if (error) {
return { success: false, error: error.message }
}
revalidatePath('/dashboard/customers')
return { success: true, data: data as Customer }
}
// Delete customer
export async function deleteCustomer(id: number) {
const supabase = createClient()
const { error } = await supabase
.from('customers')
.delete()
.eq('id', id)
if (error) {
return { success: false, error: error.message }
}
revalidatePath('/dashboard/customers')
return { success: true }
}

View File

@@ -93,6 +93,7 @@ export async function updateSmsSettings(data: {
revalidatePath("/dashboard/settings")
return { success: true }
} catch (error) {
return { error: (error as Error).message }
}
@@ -133,3 +134,70 @@ export async function sendTestSms(phone: string) {
return { error: (error as Error).message }
}
}
export async function sendBulkSms(phones: string[], message: string) {
try {
await assertAdmin()
// Fetch credentials
const { data: settings } = await supabaseAdmin.from('sms_settings').select('*').single()
if (!settings) throw new Error("SMS ayarları yapılmamış.")
const mobileService = new NetGsmService({
username: settings.username,
password: settings.password,
header: settings.header,
apiUrl: settings.api_url
})
// Remove duplicates and empty
const uniquePhones = Array.from(new Set(phones.filter(p => p && p.trim() !== '')))
const results = []
for (const phone of uniquePhones) {
const result = await mobileService.sendSms(phone, message)
// Log result
await supabaseAdmin.from('sms_logs').insert({
phone,
message,
status: result.success ? 'success' : 'error',
response_code: result.code || result.error
})
results.push({ phone, ...result })
}
const successCount = results.filter(r => r.success).length
const total = uniquePhones.length
revalidatePath("/dashboard/sms")
return {
success: true,
message: `${total} kişiden ${successCount} kişiye başarıyla gönderildi.`,
details: results
}
} catch (error) {
return { error: (error as Error).message }
}
}
export async function getSmsLogs(limit: number = 50) {
try {
await assertAdmin()
const { data, error } = await supabaseAdmin
.from('sms_logs')
.select('*')
.order('created_at', { ascending: false })
.limit(limit)
if (error) throw error
return { success: true, data }
} catch (error) {
return { error: (error as Error).message }
}
}