Feat: Add city, district, and address fields to Customer
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
||||
|
||||
@@ -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,6 +79,7 @@ export function CustomerForm() {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="phone"
|
||||
@@ -97,6 +106,51 @@ export function CustomerForm() {
|
||||
</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
|
||||
control={form.control}
|
||||
name="notes"
|
||||
|
||||
@@ -15,6 +15,9 @@ create table customers (
|
||||
full_name text not null,
|
||||
phone text,
|
||||
email text,
|
||||
city text,
|
||||
district text,
|
||||
address text,
|
||||
notes text,
|
||||
created_at timestamp with time zone default timezone('utc'::text, now()) not null
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user