feat: all core modules — properties, customers, searches, matches, presentations, activities, investors + public sunum page
- Server actions: property/customer/search/presentation/activity/investor CRUD - Matching engine: matchPropertyToSearches + syncMatchesForSearch on search save - UI: form sheets + table clients for all modules - Public /sunum/[token] page (no auth) with property card grid + expiry check - All pages force-dynamic for auth guard compatibility
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { MoreHorizontal, Plus, Pencil, Trash2, CheckCircle } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import {
|
||||
completeActivityAction,
|
||||
deleteActivityAction,
|
||||
} from "@/lib/appwrite/activity-actions";
|
||||
import { ActivityFormSheet } from "./activity-form-sheet";
|
||||
import type { Activity, Customer, Property } from "@/lib/appwrite/schema";
|
||||
import { ACTIVITY_TYPE_LABELS } from "@/lib/appwrite/schema";
|
||||
|
||||
interface ActivitiesClientProps {
|
||||
initialActivities: Activity[];
|
||||
customers: Customer[];
|
||||
properties: Property[];
|
||||
}
|
||||
|
||||
export function ActivitiesClient({
|
||||
initialActivities,
|
||||
customers,
|
||||
properties,
|
||||
}: ActivitiesClientProps) {
|
||||
const [activities, setActivities] = useState(initialActivities);
|
||||
const [sheetOpen, setSheetOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Activity | null>(null);
|
||||
|
||||
function customerName(id?: string | null) {
|
||||
if (!id) return "—";
|
||||
return customers.find((c) => c.$id === id)?.name ?? "—";
|
||||
}
|
||||
|
||||
function propertyTitle(id?: string | null) {
|
||||
if (!id) return "—";
|
||||
return properties.find((p) => p.$id === id)?.title ?? "—";
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
function openEdit(a: Activity) {
|
||||
setEditing(a);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
async function handleComplete(a: Activity) {
|
||||
const result = await completeActivityAction(a.$id);
|
||||
if (result.ok) {
|
||||
setActivities((prev) =>
|
||||
prev.map((x) => x.$id === a.$id ? { ...x, completedAt: new Date().toISOString() } : x),
|
||||
);
|
||||
toast.success("Aktivite tamamlandı.");
|
||||
} else {
|
||||
toast.error(result.error ?? "Tamamlanamadı.");
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(a: Activity) {
|
||||
if (!confirm("Bu aktivite silinsin mi?")) return;
|
||||
const result = await deleteActivityAction(a.$id);
|
||||
if (result.ok) {
|
||||
setActivities((prev) => prev.filter((x) => x.$id !== a.$id));
|
||||
toast.success("Aktivite silindi.");
|
||||
} else {
|
||||
toast.error(result.error ?? "Silinemedi.");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold">Aktiviteler</h1>
|
||||
<Button onClick={openCreate} size="sm">
|
||||
<Plus className="mr-1.5 size-4" />
|
||||
Yeni Aktivite
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Tip</TableHead>
|
||||
<TableHead>Başlık</TableHead>
|
||||
<TableHead>Müşteri</TableHead>
|
||||
<TableHead>İlan</TableHead>
|
||||
<TableHead>Tarih</TableHead>
|
||||
<TableHead>Durum</TableHead>
|
||||
<TableHead />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{activities.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7} className="text-muted-foreground text-center py-10">
|
||||
Henüz aktivite yok.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{activities.map((a) => (
|
||||
<TableRow key={a.$id}>
|
||||
<TableCell>
|
||||
<Badge variant="outline">
|
||||
{ACTIVITY_TYPE_LABELS[a.type] ?? a.type}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="font-medium max-w-[180px] truncate">{a.title}</TableCell>
|
||||
<TableCell>{customerName(a.customerId)}</TableCell>
|
||||
<TableCell className="max-w-[140px] truncate">{propertyTitle(a.propertyId)}</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{a.dueDate ? new Date(a.dueDate).toLocaleDateString("tr-TR") : "—"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{a.completedAt ? (
|
||||
<Badge variant="secondary">Tamamlandı</Badge>
|
||||
) : (
|
||||
<Badge>Açık</Badge>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="size-8">
|
||||
<MoreHorizontal className="size-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{!a.completedAt && (
|
||||
<DropdownMenuItem onClick={() => handleComplete(a)}>
|
||||
<CheckCircle className="mr-2 size-4" />
|
||||
Tamamla
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem onClick={() => openEdit(a)}>
|
||||
<Pencil className="mr-2 size-4" />
|
||||
Düzenle
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleDelete(a)}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="mr-2 size-4" />
|
||||
Sil
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<ActivityFormSheet
|
||||
open={sheetOpen}
|
||||
onOpenChange={setSheetOpen}
|
||||
activity={editing}
|
||||
customers={customers}
|
||||
properties={properties}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
"use client";
|
||||
|
||||
import { useActionState, useEffect } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetFooter,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import { createActivityAction, updateActivityAction } from "@/lib/appwrite/activity-actions";
|
||||
import type { Activity, Customer, Property } from "@/lib/appwrite/schema";
|
||||
|
||||
type ActionState = { ok: boolean; error?: string; fieldErrors?: Record<string, string[]> };
|
||||
const INITIAL: ActionState = { ok: false };
|
||||
|
||||
interface ActivityFormSheetProps {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
activity?: Activity | null;
|
||||
customers: Customer[];
|
||||
properties: Property[];
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
export function ActivityFormSheet({
|
||||
open,
|
||||
onOpenChange,
|
||||
activity,
|
||||
customers,
|
||||
properties,
|
||||
onSuccess,
|
||||
}: ActivityFormSheetProps) {
|
||||
const action = activity
|
||||
? updateActivityAction.bind(null, activity.$id)
|
||||
: createActivityAction;
|
||||
|
||||
const [state, formAction, isPending] = useActionState(action, INITIAL);
|
||||
|
||||
useEffect(() => {
|
||||
if (state.ok) {
|
||||
toast.success(activity ? "Aktivite güncellendi." : "Aktivite oluşturuldu.");
|
||||
onSuccess?.();
|
||||
onOpenChange(false);
|
||||
} else if (state.error) {
|
||||
toast.error(state.error);
|
||||
}
|
||||
}, [state]);
|
||||
|
||||
const fe = state.fieldErrors ?? {};
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||
<SheetContent className="sm:max-w-md">
|
||||
<SheetHeader>
|
||||
<SheetTitle>{activity ? "Aktiviteyi Düzenle" : "Yeni Aktivite"}</SheetTitle>
|
||||
</SheetHeader>
|
||||
|
||||
<form action={formAction} className="mt-4 space-y-4 pb-6">
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Tip *</Label>
|
||||
<select
|
||||
name="type"
|
||||
defaultValue={activity?.type ?? "gorusme"}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm"
|
||||
>
|
||||
<option value="gorusme">Görüşme</option>
|
||||
<option value="teklif">Teklif</option>
|
||||
<option value="ziyaret">Ziyaret</option>
|
||||
<option value="arama">Arama</option>
|
||||
<option value="not">Not</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="title">Başlık *</Label>
|
||||
<Input id="title" name="title" defaultValue={activity?.title} placeholder="Görüşme notu..." />
|
||||
{fe.title && <p className="text-destructive text-xs">{fe.title[0]}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Müşteri</Label>
|
||||
<select
|
||||
name="customerId"
|
||||
defaultValue={activity?.customerId ?? ""}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm"
|
||||
>
|
||||
<option value="">Seçiniz</option>
|
||||
{customers.map((c) => (
|
||||
<option key={c.$id} value={c.$id}>{c.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label>İlan</Label>
|
||||
<select
|
||||
name="propertyId"
|
||||
defaultValue={activity?.propertyId ?? ""}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm"
|
||||
>
|
||||
<option value="">Seçiniz</option>
|
||||
{properties.map((p) => (
|
||||
<option key={p.$id} value={p.$id}>{p.title}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="dueDate">Tarih</Label>
|
||||
<Input
|
||||
id="dueDate"
|
||||
name="dueDate"
|
||||
type="date"
|
||||
defaultValue={activity?.dueDate ? activity.dueDate.split("T")[0] : ""}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="description">Açıklama</Label>
|
||||
<Textarea id="description" name="description" rows={3} defaultValue={activity?.description ?? ""} />
|
||||
</div>
|
||||
|
||||
<SheetFooter>
|
||||
<Button type="submit" disabled={isPending} className="w-full">
|
||||
{isPending && <Loader2 className="mr-2 size-4 animate-spin" />}
|
||||
{activity ? "Güncelle" : "Oluştur"}
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</form>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
"use client";
|
||||
|
||||
import { useActionState, useEffect } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetFooter,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import { createCustomerAction, updateCustomerAction } from "@/lib/appwrite/customer-actions";
|
||||
import type { Customer } from "@/lib/appwrite/schema";
|
||||
|
||||
type ActionState = { ok: boolean; error?: string; fieldErrors?: Record<string, string[]> };
|
||||
const INITIAL: ActionState = { ok: false };
|
||||
|
||||
interface CustomerFormSheetProps {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
customer?: Customer | null;
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
export function CustomerFormSheet({ open, onOpenChange, customer, onSuccess }: CustomerFormSheetProps) {
|
||||
const action = customer
|
||||
? updateCustomerAction.bind(null, customer.$id)
|
||||
: createCustomerAction;
|
||||
|
||||
const [state, formAction, isPending] = useActionState(action, INITIAL);
|
||||
|
||||
useEffect(() => {
|
||||
if (state.ok) {
|
||||
toast.success(customer ? "Müşteri güncellendi." : "Müşteri oluşturuldu.");
|
||||
onSuccess?.();
|
||||
onOpenChange(false);
|
||||
} else if (state.error) {
|
||||
toast.error(state.error);
|
||||
}
|
||||
}, [state]);
|
||||
|
||||
const fe = state.fieldErrors ?? {};
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||
<SheetContent className="sm:max-w-md">
|
||||
<SheetHeader>
|
||||
<SheetTitle>{customer ? "Müşteriyi Düzenle" : "Yeni Müşteri"}</SheetTitle>
|
||||
</SheetHeader>
|
||||
|
||||
<form action={formAction} className="mt-4 space-y-4 pb-6">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="name">Ad Soyad *</Label>
|
||||
<Input id="name" name="name" defaultValue={customer?.name} placeholder="Ahmet Yılmaz" />
|
||||
{fe.name && <p className="text-destructive text-xs">{fe.name[0]}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Müşteri tipi *</Label>
|
||||
<select name="type" defaultValue={customer?.type ?? "alici"}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm">
|
||||
<option value="alici">Alıcı</option>
|
||||
<option value="kiraci">Kiracı</option>
|
||||
<option value="yatirimci">Yatırımcı</option>
|
||||
</select>
|
||||
{fe.type && <p className="text-destructive text-xs">{fe.type[0]}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="phone">Telefon</Label>
|
||||
<Input id="phone" name="phone" type="tel" defaultValue={customer?.phone ?? ""} placeholder="+90 555 123 45 67" />
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input id="email" name="email" type="email" defaultValue={customer?.email ?? ""} placeholder="ahmet@example.com" />
|
||||
{fe.email && <p className="text-destructive text-xs">{fe.email[0]}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="notes">Notlar</Label>
|
||||
<Textarea id="notes" name="notes" rows={3} defaultValue={customer?.notes ?? ""} placeholder="Müşteri hakkında notlar..." />
|
||||
</div>
|
||||
|
||||
<SheetFooter>
|
||||
<Button type="submit" disabled={isPending} className="w-full">
|
||||
{isPending && <Loader2 className="mr-2 size-4 animate-spin" />}
|
||||
{customer ? "Güncelle" : "Oluştur"}
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</form>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { MoreHorizontal, Plus, Pencil, Trash2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { deleteCustomerAction } from "@/lib/appwrite/customer-actions";
|
||||
import { CustomerFormSheet } from "./customer-form-sheet";
|
||||
import type { Customer } from "@/lib/appwrite/schema";
|
||||
import { CUSTOMER_TYPE_LABELS } from "@/lib/appwrite/schema";
|
||||
|
||||
interface CustomersClientProps {
|
||||
initialCustomers: Customer[];
|
||||
}
|
||||
|
||||
export function CustomersClient({ initialCustomers }: CustomersClientProps) {
|
||||
const [customers, setCustomers] = useState(initialCustomers);
|
||||
const [sheetOpen, setSheetOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Customer | null>(null);
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
function openEdit(c: Customer) {
|
||||
setEditing(c);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
async function handleDelete(c: Customer) {
|
||||
if (!confirm(`"${c.name}" silinsin mi?`)) return;
|
||||
const result = await deleteCustomerAction(c.$id);
|
||||
if (result.ok) {
|
||||
setCustomers((prev) => prev.filter((x) => x.$id !== c.$id));
|
||||
toast.success("Müşteri silindi.");
|
||||
} else {
|
||||
toast.error(result.error ?? "Silinemedi.");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold">Müşteriler</h1>
|
||||
<Button onClick={openCreate} size="sm">
|
||||
<Plus className="mr-1.5 size-4" />
|
||||
Yeni Müşteri
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Ad Soyad</TableHead>
|
||||
<TableHead>Tip</TableHead>
|
||||
<TableHead>Telefon</TableHead>
|
||||
<TableHead>Email</TableHead>
|
||||
<TableHead />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{customers.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="text-muted-foreground text-center py-10">
|
||||
Henüz müşteri yok.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{customers.map((c) => (
|
||||
<TableRow key={c.$id}>
|
||||
<TableCell className="font-medium">{c.name}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="outline">
|
||||
{CUSTOMER_TYPE_LABELS[c.type] ?? c.type}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">{c.phone ?? "—"}</TableCell>
|
||||
<TableCell className="text-muted-foreground">{c.email ?? "—"}</TableCell>
|
||||
<TableCell>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="size-8">
|
||||
<MoreHorizontal className="size-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => openEdit(c)}>
|
||||
<Pencil className="mr-2 size-4" />
|
||||
Düzenle
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleDelete(c)}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="mr-2 size-4" />
|
||||
Sil
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<CustomerFormSheet
|
||||
open={sheetOpen}
|
||||
onOpenChange={setSheetOpen}
|
||||
customer={editing}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
"use client";
|
||||
|
||||
import { useActionState, useEffect } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetFooter,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import {
|
||||
createCustomerSearchAction,
|
||||
updateCustomerSearchAction,
|
||||
} from "@/lib/appwrite/customer-search-actions";
|
||||
import type { Customer, CustomerSearch } from "@/lib/appwrite/schema";
|
||||
|
||||
type ActionState = { ok: boolean; error?: string; fieldErrors?: Record<string, string[]> };
|
||||
const INITIAL: ActionState = { ok: false };
|
||||
|
||||
interface SearchFormSheetProps {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
search?: CustomerSearch | null;
|
||||
customers: Customer[];
|
||||
defaultCustomerId?: string;
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
export function SearchFormSheet({
|
||||
open,
|
||||
onOpenChange,
|
||||
search,
|
||||
customers,
|
||||
defaultCustomerId,
|
||||
onSuccess,
|
||||
}: SearchFormSheetProps) {
|
||||
const action = search
|
||||
? updateCustomerSearchAction.bind(null, search.$id)
|
||||
: createCustomerSearchAction;
|
||||
|
||||
const [state, formAction, isPending] = useActionState(action, INITIAL);
|
||||
|
||||
useEffect(() => {
|
||||
if (state.ok) {
|
||||
toast.success(search ? "Arama kriteri güncellendi." : "Arama kriteri oluşturuldu.");
|
||||
onSuccess?.();
|
||||
onOpenChange(false);
|
||||
} else if (state.error) {
|
||||
toast.error(state.error);
|
||||
}
|
||||
}, [state]);
|
||||
|
||||
const fe = state.fieldErrors ?? {};
|
||||
|
||||
// Parse existing JSON array fields back to comma-separated strings for display
|
||||
function parseJsonToInput(json?: string | null): string {
|
||||
if (!json) return "";
|
||||
try {
|
||||
const arr = JSON.parse(json) as string[];
|
||||
return arr.join(", ");
|
||||
} catch {
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||
<SheetContent className="sm:max-w-md overflow-y-auto">
|
||||
<SheetHeader>
|
||||
<SheetTitle>{search ? "Aramayı Düzenle" : "Yeni Arama Kriteri"}</SheetTitle>
|
||||
</SheetHeader>
|
||||
|
||||
<form action={formAction} className="mt-4 space-y-4 pb-6">
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Müşteri *</Label>
|
||||
<select
|
||||
name="customerId"
|
||||
defaultValue={search?.customerId ?? defaultCustomerId ?? ""}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm"
|
||||
>
|
||||
<option value="">Müşteri seçin</option>
|
||||
{customers.map((c) => (
|
||||
<option key={c.$id} value={c.$id}>
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{fe.customerId && <p className="text-destructive text-xs">{fe.customerId[0]}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label>İlan türü</Label>
|
||||
<select
|
||||
name="listingType"
|
||||
defaultValue={search?.listingType ?? ""}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm"
|
||||
>
|
||||
<option value="">Tümü</option>
|
||||
<option value="satilik">Satılık</option>
|
||||
<option value="kiralik">Kiralık</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="propertyTypes">Emlak tipleri</Label>
|
||||
<p className="text-muted-foreground text-xs">Virgülle ayırın. Örn: daire, villa</p>
|
||||
<Input
|
||||
id="propertyTypes"
|
||||
name="propertyTypes"
|
||||
defaultValue={parseJsonToInput(search?.propertyTypes)}
|
||||
placeholder="daire, villa"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="roomCounts">Oda sayıları</Label>
|
||||
<p className="text-muted-foreground text-xs">Virgülle ayırın. Örn: 2+1, 3+1</p>
|
||||
<Input
|
||||
id="roomCounts"
|
||||
name="roomCounts"
|
||||
defaultValue={parseJsonToInput(search?.roomCounts)}
|
||||
placeholder="2+1, 3+1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="minPrice">Min fiyat</Label>
|
||||
<Input id="minPrice" name="minPrice" type="number" min="0" defaultValue={search?.minPrice ?? ""} />
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="maxPrice">Max fiyat</Label>
|
||||
<Input id="maxPrice" name="maxPrice" type="number" min="0" defaultValue={search?.maxPrice ?? ""} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="minM2">Min m²</Label>
|
||||
<Input id="minM2" name="minM2" type="number" min="0" defaultValue={search?.minM2 ?? ""} />
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="maxM2">Max m²</Label>
|
||||
<Input id="maxM2" name="maxM2" type="number" min="0" defaultValue={search?.maxM2 ?? ""} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="cities">Şehirler</Label>
|
||||
<Input
|
||||
id="cities"
|
||||
name="cities"
|
||||
defaultValue={parseJsonToInput(search?.cities)}
|
||||
placeholder="İstanbul, Ankara"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="districts">İlçeler</Label>
|
||||
<Input
|
||||
id="districts"
|
||||
name="districts"
|
||||
defaultValue={parseJsonToInput(search?.districts)}
|
||||
placeholder="Kadıköy, Beşiktaş"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="notes">Notlar</Label>
|
||||
<Textarea id="notes" name="notes" rows={2} defaultValue={search?.notes ?? ""} />
|
||||
</div>
|
||||
|
||||
<SheetFooter>
|
||||
<Button type="submit" disabled={isPending} className="w-full">
|
||||
{isPending && <Loader2 className="mr-2 size-4 animate-spin" />}
|
||||
{search ? "Güncelle" : "Oluştur"}
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</form>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { MoreHorizontal, Plus, Pencil, Trash2, ToggleLeft } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import {
|
||||
deleteCustomerSearchAction,
|
||||
toggleCustomerSearchActiveAction,
|
||||
} from "@/lib/appwrite/customer-search-actions";
|
||||
import { SearchFormSheet } from "./search-form-sheet";
|
||||
import type { Customer, CustomerSearch } from "@/lib/appwrite/schema";
|
||||
|
||||
interface SearchesClientProps {
|
||||
initialSearches: CustomerSearch[];
|
||||
customers: Customer[];
|
||||
}
|
||||
|
||||
export function SearchesClient({ initialSearches, customers }: SearchesClientProps) {
|
||||
const [searches, setSearches] = useState(initialSearches);
|
||||
const [sheetOpen, setSheetOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<CustomerSearch | null>(null);
|
||||
|
||||
function customerName(id: string) {
|
||||
return customers.find((c) => c.$id === id)?.name ?? id;
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
function openEdit(s: CustomerSearch) {
|
||||
setEditing(s);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
async function handleToggle(s: CustomerSearch) {
|
||||
const next = !s.isActive;
|
||||
const result = await toggleCustomerSearchActiveAction(s.$id, next);
|
||||
if (result.ok) {
|
||||
setSearches((prev) => prev.map((x) => x.$id === s.$id ? { ...x, isActive: next } : x));
|
||||
} else {
|
||||
toast.error(result.error ?? "Durum güncellenemedi.");
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(s: CustomerSearch) {
|
||||
if (!confirm("Bu arama kriteri silinsin mi?")) return;
|
||||
const result = await deleteCustomerSearchAction(s.$id);
|
||||
if (result.ok) {
|
||||
setSearches((prev) => prev.filter((x) => x.$id !== s.$id));
|
||||
toast.success("Arama kriteri silindi.");
|
||||
} else {
|
||||
toast.error(result.error ?? "Silinemedi.");
|
||||
}
|
||||
}
|
||||
|
||||
function formatRange(min?: number | null, max?: number | null, unit = "") {
|
||||
if (min && max) return `${min.toLocaleString("tr-TR")}–${max.toLocaleString("tr-TR")} ${unit}`.trim();
|
||||
if (min) return `≥ ${min.toLocaleString("tr-TR")} ${unit}`.trim();
|
||||
if (max) return `≤ ${max.toLocaleString("tr-TR")} ${unit}`.trim();
|
||||
return "—";
|
||||
}
|
||||
|
||||
function parseJsonList(json?: string | null): string {
|
||||
if (!json) return "—";
|
||||
try {
|
||||
const arr = JSON.parse(json) as string[];
|
||||
return arr.length ? arr.join(", ") : "—";
|
||||
} catch {
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold">Arama Kriterleri</h1>
|
||||
<Button onClick={openCreate} size="sm">
|
||||
<Plus className="mr-1.5 size-4" />
|
||||
Yeni Kriter
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Müşteri</TableHead>
|
||||
<TableHead>Tür</TableHead>
|
||||
<TableHead>Oda</TableHead>
|
||||
<TableHead>Fiyat Aralığı</TableHead>
|
||||
<TableHead>Şehir / İlçe</TableHead>
|
||||
<TableHead>Durum</TableHead>
|
||||
<TableHead />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{searches.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7} className="text-muted-foreground text-center py-10">
|
||||
Henüz arama kriteri yok.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{searches.map((s) => (
|
||||
<TableRow key={s.$id}>
|
||||
<TableCell className="font-medium">{customerName(s.customerId)}</TableCell>
|
||||
<TableCell>{s.listingType ?? "Tümü"}</TableCell>
|
||||
<TableCell>{parseJsonList(s.roomCounts)}</TableCell>
|
||||
<TableCell className="tabular-nums">{formatRange(s.minPrice, s.maxPrice, "₺")}</TableCell>
|
||||
<TableCell>
|
||||
{[parseJsonList(s.cities), parseJsonList(s.districts)]
|
||||
.filter((v) => v !== "—")
|
||||
.join(" / ") || "—"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={s.isActive ? "default" : "secondary"}>
|
||||
{s.isActive ? "Aktif" : "Pasif"}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="size-8">
|
||||
<MoreHorizontal className="size-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => openEdit(s)}>
|
||||
<Pencil className="mr-2 size-4" />
|
||||
Düzenle
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => handleToggle(s)}>
|
||||
<ToggleLeft className="mr-2 size-4" />
|
||||
{s.isActive ? "Pasif yap" : "Aktif yap"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleDelete(s)}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="mr-2 size-4" />
|
||||
Sil
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<SearchFormSheet
|
||||
open={sheetOpen}
|
||||
onOpenChange={setSheetOpen}
|
||||
search={editing}
|
||||
customers={customers}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
"use client";
|
||||
|
||||
import { useActionState, useEffect } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetFooter,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import { createInvestorAction, updateInvestorAction } from "@/lib/appwrite/investor-actions";
|
||||
import type { Investor } from "@/lib/appwrite/schema";
|
||||
|
||||
type ActionState = { ok: boolean; error?: string; fieldErrors?: Record<string, string[]> };
|
||||
const INITIAL: ActionState = { ok: false };
|
||||
|
||||
interface InvestorFormSheetProps {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
investor?: Investor | null;
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
export function InvestorFormSheet({ open, onOpenChange, investor, onSuccess }: InvestorFormSheetProps) {
|
||||
const action = investor
|
||||
? updateInvestorAction.bind(null, investor.$id)
|
||||
: createInvestorAction;
|
||||
|
||||
const [state, formAction, isPending] = useActionState(action, INITIAL);
|
||||
|
||||
useEffect(() => {
|
||||
if (state.ok) {
|
||||
toast.success(investor ? "Yatırımcı güncellendi." : "Yatırımcı oluşturuldu.");
|
||||
onSuccess?.();
|
||||
onOpenChange(false);
|
||||
} else if (state.error) {
|
||||
toast.error(state.error);
|
||||
}
|
||||
}, [state]);
|
||||
|
||||
const fe = state.fieldErrors ?? {};
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||
<SheetContent className="sm:max-w-md">
|
||||
<SheetHeader>
|
||||
<SheetTitle>{investor ? "Yatırımcıyı Düzenle" : "Yeni Yatırımcı"}</SheetTitle>
|
||||
</SheetHeader>
|
||||
|
||||
<form action={formAction} className="mt-4 space-y-4 pb-6">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="name">Ad Soyad *</Label>
|
||||
<Input id="name" name="name" defaultValue={investor?.name} placeholder="Mehmet Demir" />
|
||||
{fe.name && <p className="text-destructive text-xs">{fe.name[0]}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="email">Email *</Label>
|
||||
<Input id="email" name="email" type="email" defaultValue={investor?.email} placeholder="mehmet@example.com" />
|
||||
{fe.email && <p className="text-destructive text-xs">{fe.email[0]}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="phone">Telefon</Label>
|
||||
<Input id="phone" name="phone" type="tel" defaultValue={investor?.phone ?? ""} placeholder="+90 555 123 45 67" />
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="budget">Bütçe</Label>
|
||||
<Input id="budget" name="budget" type="number" min="0" defaultValue={investor?.budget ?? ""} placeholder="5000000" />
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Para birimi</Label>
|
||||
<select
|
||||
name="currency"
|
||||
defaultValue={investor?.currency ?? "TRY"}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm"
|
||||
>
|
||||
<option value="TRY">TRY</option>
|
||||
<option value="USD">USD</option>
|
||||
<option value="EUR">EUR</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="notes">Notlar</Label>
|
||||
<Textarea id="notes" name="notes" rows={3} defaultValue={investor?.notes ?? ""} placeholder="Yatırım tercihleri..." />
|
||||
</div>
|
||||
|
||||
<SheetFooter>
|
||||
<Button type="submit" disabled={isPending} className="w-full">
|
||||
{isPending && <Loader2 className="mr-2 size-4 animate-spin" />}
|
||||
{investor ? "Güncelle" : "Oluştur"}
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</form>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { MoreHorizontal, Plus, Pencil, Trash2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { deleteInvestorAction } from "@/lib/appwrite/investor-actions";
|
||||
import { InvestorFormSheet } from "./investor-form-sheet";
|
||||
import type { Investor } from "@/lib/appwrite/schema";
|
||||
|
||||
interface InvestorsClientProps {
|
||||
initialInvestors: Investor[];
|
||||
}
|
||||
|
||||
export function InvestorsClient({ initialInvestors }: InvestorsClientProps) {
|
||||
const [investors, setInvestors] = useState(initialInvestors);
|
||||
const [sheetOpen, setSheetOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Investor | null>(null);
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
function openEdit(i: Investor) {
|
||||
setEditing(i);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
async function handleDelete(i: Investor) {
|
||||
if (!confirm(`"${i.name}" silinsin mi?`)) return;
|
||||
const result = await deleteInvestorAction(i.$id);
|
||||
if (result.ok) {
|
||||
setInvestors((prev) => prev.filter((x) => x.$id !== i.$id));
|
||||
toast.success("Yatırımcı silindi.");
|
||||
} else {
|
||||
toast.error(result.error ?? "Silinemedi.");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold">Yatırımcılar</h1>
|
||||
<Button onClick={openCreate} size="sm">
|
||||
<Plus className="mr-1.5 size-4" />
|
||||
Yeni Yatırımcı
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Ad Soyad</TableHead>
|
||||
<TableHead>Email</TableHead>
|
||||
<TableHead>Telefon</TableHead>
|
||||
<TableHead className="text-right">Bütçe</TableHead>
|
||||
<TableHead />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{investors.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="text-muted-foreground text-center py-10">
|
||||
Henüz yatırımcı yok.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{investors.map((i) => (
|
||||
<TableRow key={i.$id}>
|
||||
<TableCell className="font-medium">{i.name}</TableCell>
|
||||
<TableCell>{i.email}</TableCell>
|
||||
<TableCell className="text-muted-foreground">{i.phone ?? "—"}</TableCell>
|
||||
<TableCell className="text-right tabular-nums">
|
||||
{i.budget ? `${i.budget.toLocaleString("tr-TR")} ${i.currency ?? "TRY"}` : "—"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="size-8">
|
||||
<MoreHorizontal className="size-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => openEdit(i)}>
|
||||
<Pencil className="mr-2 size-4" />
|
||||
Düzenle
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleDelete(i)}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="mr-2 size-4" />
|
||||
Sil
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<InvestorFormSheet
|
||||
open={sheetOpen}
|
||||
onOpenChange={setSheetOpen}
|
||||
investor={editing}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
"use client";
|
||||
|
||||
import { useActionState, useEffect } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetFooter,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import {
|
||||
createPresentationAction,
|
||||
updatePresentationAction,
|
||||
} from "@/lib/appwrite/presentation-actions";
|
||||
import type { Customer, Presentation, Property } from "@/lib/appwrite/schema";
|
||||
|
||||
type ActionState = { ok: boolean; error?: string; fieldErrors?: Record<string, string[]>; id?: string };
|
||||
const INITIAL: ActionState = { ok: false };
|
||||
|
||||
interface PresentationFormSheetProps {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
presentation?: Presentation | null;
|
||||
customers: Customer[];
|
||||
properties: Property[];
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
export function PresentationFormSheet({
|
||||
open,
|
||||
onOpenChange,
|
||||
presentation,
|
||||
customers,
|
||||
properties,
|
||||
onSuccess,
|
||||
}: PresentationFormSheetProps) {
|
||||
const action = presentation
|
||||
? updatePresentationAction.bind(null, presentation.$id)
|
||||
: createPresentationAction;
|
||||
|
||||
const [state, formAction, isPending] = useActionState(action, INITIAL);
|
||||
|
||||
const selectedIds: string[] = presentation
|
||||
? (JSON.parse(presentation.propertyIds || "[]") as string[])
|
||||
: [];
|
||||
|
||||
useEffect(() => {
|
||||
if (state.ok) {
|
||||
toast.success(presentation ? "Sunum güncellendi." : "Sunum oluşturuldu.");
|
||||
onSuccess?.();
|
||||
onOpenChange(false);
|
||||
} else if (state.error) {
|
||||
toast.error(state.error);
|
||||
}
|
||||
}, [state]);
|
||||
|
||||
const fe = state.fieldErrors ?? {};
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||
<SheetContent className="sm:max-w-md overflow-y-auto">
|
||||
<SheetHeader>
|
||||
<SheetTitle>{presentation ? "Sunumu Düzenle" : "Yeni Sunum"}</SheetTitle>
|
||||
</SheetHeader>
|
||||
|
||||
<form action={formAction} className="mt-4 space-y-4 pb-6">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="title">Sunum başlığı *</Label>
|
||||
<Input id="title" name="title" defaultValue={presentation?.title} placeholder="Kadıköy 3+1 Seçenekleri" />
|
||||
{fe.title && <p className="text-destructive text-xs">{fe.title[0]}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Müşteri</Label>
|
||||
<select
|
||||
name="customerId"
|
||||
defaultValue={presentation?.customerId ?? ""}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm"
|
||||
>
|
||||
<option value="">Müşteri seçin (opsiyonel)</option>
|
||||
{customers.map((c) => (
|
||||
<option key={c.$id} value={c.$id}>{c.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label>İlanlar *</Label>
|
||||
{fe.propertyIds && <p className="text-destructive text-xs">{fe.propertyIds[0]}</p>}
|
||||
<PropertyCheckboxList
|
||||
properties={properties}
|
||||
selectedIds={selectedIds}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="expiresAt">Geçerlilik tarihi</Label>
|
||||
<Input
|
||||
id="expiresAt"
|
||||
name="expiresAt"
|
||||
type="date"
|
||||
defaultValue={presentation?.expiresAt ? presentation.expiresAt.split("T")[0] : ""}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="notes">Notlar</Label>
|
||||
<Textarea id="notes" name="notes" rows={2} defaultValue={presentation?.notes ?? ""} />
|
||||
</div>
|
||||
|
||||
<SheetFooter>
|
||||
<Button type="submit" disabled={isPending} className="w-full">
|
||||
{isPending && <Loader2 className="mr-2 size-4 animate-spin" />}
|
||||
{presentation ? "Güncelle" : "Oluştur"}
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</form>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
|
||||
function PropertyCheckboxList({
|
||||
properties,
|
||||
selectedIds,
|
||||
}: {
|
||||
properties: Property[];
|
||||
selectedIds: string[];
|
||||
}) {
|
||||
// We encode selected propertyIds as a JSON array in a hidden input
|
||||
// and use checkboxes with the same name to collect values
|
||||
return (
|
||||
<div className="max-h-48 overflow-y-auto rounded-md border p-2 space-y-1">
|
||||
{properties.length === 0 && (
|
||||
<p className="text-muted-foreground text-sm">Aktif ilan bulunamadı.</p>
|
||||
)}
|
||||
{properties.map((p) => (
|
||||
<label key={p.$id} className="flex items-center gap-2 cursor-pointer rounded px-2 py-1 hover:bg-muted/50">
|
||||
<Checkbox
|
||||
name="propertyIdsRaw"
|
||||
value={p.$id}
|
||||
defaultChecked={selectedIds.includes(p.$id)}
|
||||
/>
|
||||
<span className="text-sm truncate">
|
||||
{p.title} — {p.city}{p.district ? `, ${p.district}` : ""}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
{/* Hidden field placeholder — server action reads propertyIdsRaw[] and joins them */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { MoreHorizontal, Plus, Pencil, Trash2, ExternalLink, Copy } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { deletePresentationAction } from "@/lib/appwrite/presentation-actions";
|
||||
import { PresentationFormSheet } from "./presentation-form-sheet";
|
||||
import type { Customer, Presentation, Property } from "@/lib/appwrite/schema";
|
||||
|
||||
interface PresentationsClientProps {
|
||||
initialPresentations: Presentation[];
|
||||
customers: Customer[];
|
||||
properties: Property[];
|
||||
}
|
||||
|
||||
export function PresentationsClient({
|
||||
initialPresentations,
|
||||
customers,
|
||||
properties,
|
||||
}: PresentationsClientProps) {
|
||||
const [presentations, setPresentations] = useState(initialPresentations);
|
||||
const [sheetOpen, setSheetOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Presentation | null>(null);
|
||||
|
||||
const appUrl = typeof window !== "undefined" ? window.location.origin : "";
|
||||
|
||||
function getShareUrl(p: Presentation) {
|
||||
return `${appUrl}/sunum/${p.shareToken}`;
|
||||
}
|
||||
|
||||
function customerName(id?: string | null) {
|
||||
if (!id) return "—";
|
||||
return customers.find((c) => c.$id === id)?.name ?? id;
|
||||
}
|
||||
|
||||
function propertyCount(p: Presentation) {
|
||||
try {
|
||||
return (JSON.parse(p.propertyIds) as string[]).length;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
function openEdit(p: Presentation) {
|
||||
setEditing(p);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
async function copyLink(p: Presentation) {
|
||||
await navigator.clipboard.writeText(getShareUrl(p));
|
||||
toast.success("Link kopyalandı.");
|
||||
}
|
||||
|
||||
async function handleDelete(p: Presentation) {
|
||||
if (!confirm(`"${p.title}" sunumu silinsin mi?`)) return;
|
||||
const result = await deletePresentationAction(p.$id);
|
||||
if (result.ok) {
|
||||
setPresentations((prev) => prev.filter((x) => x.$id !== p.$id));
|
||||
toast.success("Sunum silindi.");
|
||||
} else {
|
||||
toast.error(result.error ?? "Silinemedi.");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold">Sunumlar</h1>
|
||||
<Button onClick={openCreate} size="sm">
|
||||
<Plus className="mr-1.5 size-4" />
|
||||
Yeni Sunum
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Başlık</TableHead>
|
||||
<TableHead>Müşteri</TableHead>
|
||||
<TableHead>İlanlar</TableHead>
|
||||
<TableHead>Görüntülenme</TableHead>
|
||||
<TableHead>Geçerlilik</TableHead>
|
||||
<TableHead />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{presentations.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-muted-foreground text-center py-10">
|
||||
Henüz sunum yok.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{presentations.map((p) => (
|
||||
<TableRow key={p.$id}>
|
||||
<TableCell className="font-medium">{p.title}</TableCell>
|
||||
<TableCell>{customerName(p.customerId)}</TableCell>
|
||||
<TableCell>{propertyCount(p)} ilan</TableCell>
|
||||
<TableCell>{p.viewCount ?? 0}</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{p.expiresAt ? new Date(p.expiresAt).toLocaleDateString("tr-TR") : "—"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="size-8">
|
||||
<MoreHorizontal className="size-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => copyLink(p)}>
|
||||
<Copy className="mr-2 size-4" />
|
||||
Linki kopyala
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild>
|
||||
<a href={getShareUrl(p)} target="_blank" rel="noopener noreferrer">
|
||||
<ExternalLink className="mr-2 size-4" />
|
||||
Önizleme
|
||||
</a>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => openEdit(p)}>
|
||||
<Pencil className="mr-2 size-4" />
|
||||
Düzenle
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleDelete(p)}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="mr-2 size-4" />
|
||||
Sil
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<PresentationFormSheet
|
||||
open={sheetOpen}
|
||||
onOpenChange={setSheetOpen}
|
||||
presentation={editing}
|
||||
customers={customers}
|
||||
properties={properties}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { MoreHorizontal, Plus, Pencil, Trash2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { deletePropertyAction } from "@/lib/appwrite/property-actions";
|
||||
import { PropertyFormSheet } from "./property-form-sheet";
|
||||
import type { Property } from "@/lib/appwrite/schema";
|
||||
import {
|
||||
PROPERTY_STATUS_LABELS,
|
||||
PROPERTY_TYPE_LABELS,
|
||||
LISTING_TYPE_LABELS,
|
||||
} from "@/lib/appwrite/schema";
|
||||
|
||||
interface PropertiesClientProps {
|
||||
initialProperties: Property[];
|
||||
}
|
||||
|
||||
export function PropertiesClient({ initialProperties }: PropertiesClientProps) {
|
||||
const [properties, setProperties] = useState(initialProperties);
|
||||
const [sheetOpen, setSheetOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Property | null>(null);
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
function openEdit(p: Property) {
|
||||
setEditing(p);
|
||||
setSheetOpen(true);
|
||||
}
|
||||
|
||||
async function handleDelete(p: Property) {
|
||||
if (!confirm(`"${p.title}" silinsin mi?`)) return;
|
||||
const result = await deletePropertyAction(p.$id);
|
||||
if (result.ok) {
|
||||
setProperties((prev) => prev.filter((x) => x.$id !== p.$id));
|
||||
toast.success("İlan silindi.");
|
||||
} else {
|
||||
toast.error(result.error ?? "Silinemedi.");
|
||||
}
|
||||
}
|
||||
|
||||
function handleSuccess() {
|
||||
// Revalidation handles the data refresh; re-fetching in client is not
|
||||
// necessary since the page will reload on next navigation.
|
||||
// For immediate local update we just remove the item or close the sheet.
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold">İlanlar</h1>
|
||||
<Button onClick={openCreate} size="sm">
|
||||
<Plus className="mr-1.5 size-4" />
|
||||
Yeni İlan
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Başlık</TableHead>
|
||||
<TableHead>Tip</TableHead>
|
||||
<TableHead>Tür</TableHead>
|
||||
<TableHead>Şehir</TableHead>
|
||||
<TableHead className="text-right">Fiyat</TableHead>
|
||||
<TableHead>Durum</TableHead>
|
||||
<TableHead />
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{properties.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7} className="text-muted-foreground text-center py-10">
|
||||
Henüz ilan yok.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{properties.map((p) => (
|
||||
<TableRow key={p.$id}>
|
||||
<TableCell className="font-medium max-w-[200px] truncate">{p.title}</TableCell>
|
||||
<TableCell>{PROPERTY_TYPE_LABELS[p.propertyType] ?? p.propertyType}</TableCell>
|
||||
<TableCell>{LISTING_TYPE_LABELS[p.listingType] ?? p.listingType}</TableCell>
|
||||
<TableCell>{[p.city, p.district].filter(Boolean).join(", ")}</TableCell>
|
||||
<TableCell className="text-right tabular-nums">
|
||||
{p.price.toLocaleString("tr-TR")} {p.currency ?? "TRY"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<StatusBadge status={p.status} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="size-8">
|
||||
<MoreHorizontal className="size-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => openEdit(p)}>
|
||||
<Pencil className="mr-2 size-4" />
|
||||
Düzenle
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleDelete(p)}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="mr-2 size-4" />
|
||||
Sil
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<PropertyFormSheet
|
||||
open={sheetOpen}
|
||||
onOpenChange={setSheetOpen}
|
||||
property={editing}
|
||||
onSuccess={handleSuccess}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StatusBadge({ status }: { status: string }) {
|
||||
const map: Record<string, "default" | "secondary" | "outline" | "destructive"> = {
|
||||
aktif: "default",
|
||||
pasif: "secondary",
|
||||
satildi: "outline",
|
||||
kiralandit: "outline",
|
||||
};
|
||||
return (
|
||||
<Badge variant={map[status] ?? "secondary"}>
|
||||
{PROPERTY_STATUS_LABELS[status as keyof typeof PROPERTY_STATUS_LABELS] ?? status}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
"use client";
|
||||
|
||||
import { useActionState, useEffect } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetFooter,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import { createPropertyAction, updatePropertyAction } from "@/lib/appwrite/property-actions";
|
||||
import type { Property } from "@/lib/appwrite/schema";
|
||||
|
||||
type ActionState = { ok: boolean; error?: string; fieldErrors?: Record<string, string[]> };
|
||||
const INITIAL: ActionState = { ok: false };
|
||||
|
||||
interface PropertyFormSheetProps {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
property?: Property | null;
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
export function PropertyFormSheet({ open, onOpenChange, property, onSuccess }: PropertyFormSheetProps) {
|
||||
const action = property
|
||||
? updatePropertyAction.bind(null, property.$id)
|
||||
: createPropertyAction;
|
||||
|
||||
const [state, formAction, isPending] = useActionState(action, INITIAL);
|
||||
|
||||
useEffect(() => {
|
||||
if (state.ok) {
|
||||
toast.success(property ? "İlan güncellendi." : "İlan oluşturuldu.");
|
||||
onSuccess?.();
|
||||
onOpenChange(false);
|
||||
} else if (state.error) {
|
||||
toast.error(state.error);
|
||||
}
|
||||
}, [state]);
|
||||
|
||||
const fe = state.fieldErrors ?? {};
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||
<SheetContent className="w-full sm:max-w-xl overflow-y-auto">
|
||||
<SheetHeader>
|
||||
<SheetTitle>{property ? "İlanı Düzenle" : "Yeni İlan"}</SheetTitle>
|
||||
</SheetHeader>
|
||||
|
||||
<form action={formAction} className="mt-4 space-y-4 pb-6">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="title">Başlık *</Label>
|
||||
<Input id="title" name="title" defaultValue={property?.title} placeholder="3+1 Daire, Kadıköy" />
|
||||
{fe.title && <p className="text-destructive text-xs">{fe.title[0]}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Emlak tipi *</Label>
|
||||
<select name="propertyType" defaultValue={property?.propertyType ?? "daire"}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm">
|
||||
<option value="daire">Daire</option>
|
||||
<option value="villa">Villa</option>
|
||||
<option value="arsa">Arsa</option>
|
||||
<option value="dukkan">Dükkan</option>
|
||||
<option value="ofis">Ofis</option>
|
||||
<option value="depo">Depo</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label>İlan türü *</Label>
|
||||
<select name="listingType" defaultValue={property?.listingType ?? "satilik"}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm">
|
||||
<option value="satilik">Satılık</option>
|
||||
<option value="kiralik">Kiralık</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="price">Fiyat *</Label>
|
||||
<Input id="price" name="price" type="number" min="0" defaultValue={property?.price} placeholder="0" />
|
||||
{fe.price && <p className="text-destructive text-xs">{fe.price[0]}</p>}
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label>Durum</Label>
|
||||
<select name="status" defaultValue={property?.status ?? "aktif"}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm">
|
||||
<option value="aktif">Aktif</option>
|
||||
<option value="pasif">Pasif</option>
|
||||
<option value="satildi">Satıldı</option>
|
||||
<option value="kiralandit">Kiralandı</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="city">Şehir *</Label>
|
||||
<Input id="city" name="city" defaultValue={property?.city} placeholder="İstanbul" />
|
||||
{fe.city && <p className="text-destructive text-xs">{fe.city[0]}</p>}
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="district">İlçe</Label>
|
||||
<Input id="district" name="district" defaultValue={property?.district ?? ""} placeholder="Kadıköy" />
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="neighborhood">Mahalle</Label>
|
||||
<Input id="neighborhood" name="neighborhood" defaultValue={property?.neighborhood ?? ""} placeholder="Moda" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="roomCount">Oda sayısı</Label>
|
||||
<select name="roomCount" defaultValue={property?.roomCount ?? ""}
|
||||
className="border-input bg-background h-9 rounded-md border px-3 text-sm">
|
||||
<option value="">Seçiniz</option>
|
||||
<option value="Stüdyo">Stüdyo</option>
|
||||
<option value="1+0">1+0</option>
|
||||
<option value="1+1">1+1</option>
|
||||
<option value="2+1">2+1</option>
|
||||
<option value="3+1">3+1</option>
|
||||
<option value="4+1">4+1</option>
|
||||
<option value="4+2">4+2</option>
|
||||
<option value="5+1">5+1</option>
|
||||
<option value="5+2">5+2</option>
|
||||
<option value="6+">6+</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="netM2">Net m²</Label>
|
||||
<Input id="netM2" name="netM2" type="number" min="0" defaultValue={property?.netM2 ?? ""} placeholder="90" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="floor">Kat</Label>
|
||||
<Input id="floor" name="floor" type="number" defaultValue={property?.floor ?? ""} />
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="totalFloors">Top. kat</Label>
|
||||
<Input id="totalFloors" name="totalFloors" type="number" defaultValue={property?.totalFloors ?? ""} />
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="buildingAge">Bina yaşı</Label>
|
||||
<Input id="buildingAge" name="buildingAge" type="number" min="0" defaultValue={property?.buildingAge ?? ""} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="address">Tam adres</Label>
|
||||
<Textarea id="address" name="address" rows={2} defaultValue={property?.address ?? ""} placeholder="Sokak, kapı no..." />
|
||||
</div>
|
||||
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="description">Açıklama</Label>
|
||||
<Textarea id="description" name="description" rows={3} defaultValue={property?.description ?? ""} placeholder="İlan detayları..." />
|
||||
</div>
|
||||
|
||||
<SheetFooter>
|
||||
<Button type="submit" disabled={isPending} className="w-full">
|
||||
{isPending && <Loader2 className="mr-2 size-4 animate-spin" />}
|
||||
{property ? "Güncelle" : "Oluştur"}
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</form>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user