New Proje

This commit is contained in:
2026-03-17 00:46:49 +03:00
parent fc7dd7a4b2
commit ee9896315b
21 changed files with 1347 additions and 61 deletions

View File

@@ -0,0 +1,65 @@
'use server'
import { createClient } from '@/utils/supabase/server'
import { revalidatePath } from 'next/cache'
export async function submitLeaveRequest(formData: FormData) {
const supabase = await createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) return { error: 'Oturum bulunamadı.' }
const startDate = formData.get('start_date') as string
const endDate = formData.get('end_date') as string
const reason = formData.get('reason') as string
const companyId = formData.get('company_id') as string // which company they are requesting leave for
if (!startDate || !endDate || !companyId || !reason) {
return { error: 'Tüm alanları doldurunuz.' }
}
// Find their employee record for this specific company
const { data: employeeData, error: empError } = await supabase
.from('employees')
.select('id')
.eq('user_id', user.id)
.eq('company_id', companyId)
.single()
if (empError || !employeeData) {
return { error: 'Seçili şirket için çalışan kaydınız bulunamadı.' }
}
const { error } = await supabase
.from('leave_requests')
.insert([{
employee_id: employeeData.id,
start_date: startDate,
end_date: endDate,
reason: reason,
status: 'pending' // default
}])
if (error) {
return { error: 'İzin talebi oluşturulurken hata: ' + error.message }
}
revalidatePath('/leave-requests')
return { success: true }
}
export async function updateLeaveStatus(id: string, newStatus: 'approved' | 'rejected') {
const supabase = await createClient()
const { error } = await supabase
.from('leave_requests')
.update({ status: newStatus })
.eq('id', id)
if (error) {
return { error: 'Durum güncellenirken hata oluştu: ' + error.message }
}
revalidatePath('/leave-requests')
return { success: true }
}