Feat: Add city, district, and address fields to Customer

This commit is contained in:
2025-12-03 22:18:51 +03:00
parent db961c95a4
commit e5f7680393
3 changed files with 86 additions and 18 deletions

View File

@@ -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,
})

View File

@@ -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() {
</FormItem>
)}
/>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<FormField
control={form.control}
name="phone"
render={({ field }) => (
<FormItem>
<FormLabel>Telefon</FormLabel>
<FormControl>
<Input placeholder="0555 555 55 55" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>E-posta</FormLabel>
<FormControl>
<Input placeholder="ahmet@ornek.com" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<FormField
control={form.control}
name="city"
render={({ field }) => (
<FormItem>
<FormLabel>İl</FormLabel>
<FormControl>
<Input placeholder="İstanbul" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="district"
render={({ field }) => (
<FormItem>
<FormLabel>İlçe</FormLabel>
<FormControl>
<Input placeholder="Kadıköy" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
<FormField
control={form.control}
name="phone"
name="address"
render={({ field }) => (
<FormItem>
<FormLabel>Telefon</FormLabel>
<FormLabel>Adres</FormLabel>
<FormControl>
<Input placeholder="0555 555 55 55" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>E-posta</FormLabel>
<FormControl>
<Input placeholder="ahmet@ornek.com" {...field} />
<Textarea placeholder="Tam adres..." {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="notes"