diff --git a/src/app/dashboard/customers/new/actions.ts b/src/app/dashboard/customers/new/actions.ts index ce85fa3..51bb0ed 100644 --- a/src/app/dashboard/customers/new/actions.ts +++ b/src/app/dashboard/customers/new/actions.ts @@ -3,13 +3,24 @@ import { createClient } from "@/lib/supabase/server" import { revalidatePath } from "next/cache" -export async function createCustomer(data: { full_name: string; phone?: string; email?: string; notes?: string }) { +export async function createCustomer(data: { + full_name: string; + phone?: string; + email?: string; + city?: string; + district?: string; + address?: string; + notes?: string +}) { const supabase = await createClient() const { error } = await supabase.from('customers').insert({ full_name: data.full_name, phone: data.phone, email: data.email || null, + city: data.city, + district: data.district, + address: data.address, notes: data.notes, }) diff --git a/src/app/dashboard/customers/new/customer-form.tsx b/src/app/dashboard/customers/new/customer-form.tsx index 7ab83b2..4e54730 100644 --- a/src/app/dashboard/customers/new/customer-form.tsx +++ b/src/app/dashboard/customers/new/customer-form.tsx @@ -17,6 +17,7 @@ import { Textarea } from "@/components/ui/textarea" import { createCustomer } from "./actions" import { useRouter } from "next/navigation" import { useState } from "react" +import { toast } from "sonner" const formSchema = z.object({ full_name: z.string().min(2, { @@ -24,6 +25,9 @@ const formSchema = z.object({ }), phone: z.string().optional(), email: z.string().email({ message: "Geçersiz e-posta adresi." }).optional().or(z.literal('')), + city: z.string().optional(), + district: z.string().optional(), + address: z.string().optional(), notes: z.string().optional(), }) @@ -37,6 +41,9 @@ export function CustomerForm() { full_name: "", phone: "", email: "", + city: "", + district: "", + address: "", notes: "", }, }) @@ -47,9 +54,10 @@ export function CustomerForm() { await createCustomer(values) router.push('/dashboard/customers') router.refresh() + toast.success("Müşteri başarıyla oluşturuldu") } catch (error) { console.error(error) - alert("Bir hata oluştu") + toast.error("Bir hata oluştu") } finally { setLoading(false) } @@ -71,32 +79,78 @@ export function CustomerForm() { )} /> +
+ ( + + Telefon + + + + + + )} + /> + ( + + E-posta + + + + + + )} + /> +
+ +
+ ( + + İl + + + + + + )} + /> + ( + + İlçe + + + + + + )} + /> +
+ ( - Telefon + Adres - - - - - )} - /> - ( - - E-posta - - +