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:
egecankomur
2026-05-05 12:03:48 +03:00
parent 2f17c342ca
commit 4ef0482732
34 changed files with 3174 additions and 36 deletions
+99
View File
@@ -0,0 +1,99 @@
"use server";
import { ID, Permission, Role } from "node-appwrite";
import { revalidatePath } from "next/cache";
import { customerSchema } from "@/lib/validation/customers";
import { DATABASE_ID, TABLES } from "./schema";
import { createAdminClient } from "./server";
import { requireTenant } from "@/lib/appwrite/tenant-guard";
type ActionState = { ok: boolean; error?: string; fieldErrors?: Record<string, string[]> };
export async function createCustomerAction(
_prev: ActionState,
formData: FormData,
): Promise<ActionState> {
const ctx = await requireTenant();
const raw = Object.fromEntries(formData.entries());
const parsed = customerSchema.safeParse(raw);
if (!parsed.success) {
return { ok: false, fieldErrors: parsed.error.flatten().fieldErrors };
}
const { tablesDB } = createAdminClient();
const data = parsed.data;
try {
await tablesDB.createRow(
DATABASE_ID,
TABLES.customers,
ID.unique(),
{
tenantId: ctx.tenantId,
name: data.name,
email: data.email,
phone: data.phone,
type: data.type,
notes: data.notes,
createdBy: ctx.user.id,
},
[
Permission.read(Role.team(ctx.tenantId)),
Permission.update(Role.team(ctx.tenantId)),
Permission.delete(Role.team(ctx.tenantId, "owner")),
Permission.delete(Role.team(ctx.tenantId, "admin")),
],
);
} catch {
return { ok: false, error: "Müşteri oluşturulamadı." };
}
revalidatePath("/customers");
return { ok: true };
}
export async function updateCustomerAction(
id: string,
_prev: ActionState,
formData: FormData,
): Promise<ActionState> {
await requireTenant();
const raw = Object.fromEntries(formData.entries());
const parsed = customerSchema.safeParse(raw);
if (!parsed.success) {
return { ok: false, fieldErrors: parsed.error.flatten().fieldErrors };
}
const { tablesDB } = createAdminClient();
const data = parsed.data;
try {
await tablesDB.updateRow(DATABASE_ID, TABLES.customers, id, {
name: data.name,
email: data.email,
phone: data.phone,
type: data.type,
notes: data.notes,
});
} catch {
return { ok: false, error: "Müşteri güncellenemedi." };
}
revalidatePath("/customers");
return { ok: true };
}
export async function deleteCustomerAction(id: string): Promise<ActionState> {
await requireTenant();
const { tablesDB } = createAdminClient();
try {
await tablesDB.deleteRow(DATABASE_ID, TABLES.customers, id);
} catch {
return { ok: false, error: "Müşteri silinemedi." };
}
revalidatePath("/customers");
return { ok: true };
}