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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user