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