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 { createClient } from "@/lib/supabase/server"
import { revalidatePath } from "next/cache" 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 supabase = await createClient()
const { error } = await supabase.from('customers').insert({ const { error } = await supabase.from('customers').insert({
full_name: data.full_name, full_name: data.full_name,
phone: data.phone, phone: data.phone,
email: data.email || null, email: data.email || null,
city: data.city,
district: data.district,
address: data.address,
notes: data.notes, notes: data.notes,
}) })

View File

@@ -17,6 +17,7 @@ import { Textarea } from "@/components/ui/textarea"
import { createCustomer } from "./actions" import { createCustomer } from "./actions"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { useState } from "react" import { useState } from "react"
import { toast } from "sonner"
const formSchema = z.object({ const formSchema = z.object({
full_name: z.string().min(2, { full_name: z.string().min(2, {
@@ -24,6 +25,9 @@ const formSchema = z.object({
}), }),
phone: z.string().optional(), phone: z.string().optional(),
email: z.string().email({ message: "Geçersiz e-posta adresi." }).optional().or(z.literal('')), 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(), notes: z.string().optional(),
}) })
@@ -37,6 +41,9 @@ export function CustomerForm() {
full_name: "", full_name: "",
phone: "", phone: "",
email: "", email: "",
city: "",
district: "",
address: "",
notes: "", notes: "",
}, },
}) })
@@ -47,9 +54,10 @@ export function CustomerForm() {
await createCustomer(values) await createCustomer(values)
router.push('/dashboard/customers') router.push('/dashboard/customers')
router.refresh() router.refresh()
toast.success("Müşteri başarıyla oluşturuldu")
} catch (error) { } catch (error) {
console.error(error) console.error(error)
alert("Bir hata oluştu") toast.error("Bir hata oluştu")
} finally { } finally {
setLoading(false) setLoading(false)
} }
@@ -71,6 +79,7 @@ export function CustomerForm() {
</FormItem> </FormItem>
)} )}
/> />
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<FormField <FormField
control={form.control} control={form.control}
name="phone" name="phone"
@@ -97,6 +106,51 @@ export function CustomerForm() {
</FormItem> </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="address"
render={({ field }) => (
<FormItem>
<FormLabel>Adres</FormLabel>
<FormControl>
<Textarea placeholder="Tam adres..." {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField <FormField
control={form.control} control={form.control}
name="notes" name="notes"

View File

@@ -15,6 +15,9 @@ create table customers (
full_name text not null, full_name text not null,
phone text, phone text,
email text, email text,
city text,
district text,
address text,
notes text, notes text,
created_at timestamp with time zone default timezone('utc'::text, now()) not null created_at timestamp with time zone default timezone('utc'::text, now()) not null
); );