feat(backend): migrate freelancer and portal runtimes

This commit is contained in:
poyrazavsever
2026-07-17 00:16:38 +03:00
parent 561af11b70
commit 678c0236db
41 changed files with 5293 additions and 2324 deletions
+15 -29
View File
@@ -1,36 +1,22 @@
"use server";
import { createClient } from "@/lib/supabase/server";
import { revalidatePath } from "next/cache";
import { cleanText } from "@/server/web/form-data";
import { requirePortalBackend } from "@/server/web/portal";
export async function createRevisionRequest(projectId: string, clientId: string, formData: FormData) {
const supabase = await createClient();
const { data: { user } } = await supabase.auth.getUser();
export async function createRevisionRequest(projectId: string, formData: FormData) {
try {
const { actor, service } = await requirePortalBackend();
const description = cleanText(formData.get("description"));
if (!description) return { error: "Revizyon açıklaması boş olamaz." };
if (!user) {
return { error: "Oturum süresi dolmuş." };
service.requestRevision(actor, { projectId, description });
revalidatePath(`/portal/projects/${projectId}`);
revalidatePath("/portal/revisions");
return { success: true };
} catch (error) {
return {
error: error instanceof Error ? error.message : "Revizyon talebi oluşturulamadı.",
};
}
const description = formData.get("description") as string;
if (!description?.trim()) {
return { error: "Revizyon açıklaması boş olamaz." };
}
const { error } = await supabase
.from("project_revisions")
.insert({
project_id: projectId,
client_id: clientId,
requested_by: user.id,
description,
status: "pending"
});
if (error) {
return { error: error.message };
}
revalidatePath(`/portal/projects/${projectId}`);
return { success: true };
}
+58 -55
View File
@@ -1,67 +1,70 @@
import { createClient } from "@/lib/supabase/server";
import { notFound } from "next/navigation";
import { PortalProjectClient } from "./portal-project-client";
import { DomainError } from "@/server/domain/errors";
import { requirePortalBackend } from "@/server/web/portal";
import {
PortalProjectClient,
type PortalPlanningSection,
type PortalProjectDetail,
type PortalRevision,
type PortalTask,
} from "./portal-project-client";
export default async function PortalProjectPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const supabase = await createClient();
const { data: { user } } = await supabase.auth.getUser();
const { actor, service } = await requirePortalBackend();
let data: {
project: PortalProjectDetail;
sections: PortalPlanningSection[];
tasks: PortalTask[];
revisions: PortalRevision[];
};
if (!user) return null;
// 1. Get Client Record
const { data: clientData } = await supabase
.from("clients")
.select("id")
.eq("client_auth_id", user.id)
.single();
if (!clientData) {
notFound();
try {
const row = service.getProject(actor, id);
const allowance = service.getRevisionAllowance(actor, id);
data = {
project: {
id: row.id,
name: row.name,
description: row.description,
status: row.status,
progress: row.progress,
due_date: row.dueDate,
revision_quota: allowance.remaining,
can_request_revision: allowance.canRequest,
},
sections: service.listPlanningSections(actor, id).map((section) => ({
id: section.id,
title: section.title,
content: section.content,
type: section.category,
})),
tasks: service.listTasks(actor, id)
.filter((task) => task.status !== "cancelled")
.map((task) => ({
id: task.id,
title: task.title,
status: task.status as PortalTask["status"],
date: task.dueAt?.toISOString() ?? task.scheduledDate,
})),
revisions: service.listRevisions(actor, id).map((revision) => ({
id: revision.id,
description: revision.description,
status: revision.status,
created_at: revision.createdAt.toISOString(),
})),
};
} catch (error) {
if (error instanceof DomainError && error.code === "NOT_FOUND") notFound();
throw error;
}
// 2. Get Project
const { data: project, error } = await supabase
.from("projects")
.select("id, name, description, status, progress, due_date, revision_quota")
.eq("id", id)
.eq("client_id", clientData.id)
.single();
if (error || !project) {
notFound();
}
// 3. Get Planning Sections (Milestones etc.)
const { data: sectionsData } = await supabase
.from("project_planning_sections")
.select("*")
.eq("project_id", id)
.order("order_index", { ascending: true });
// 4. Get Public Tasks
const { data: tasksData } = await supabase
.from("tasks")
.select("*")
.eq("project_id", id)
.eq("is_public_to_client", true)
.order("date", { ascending: false });
// 5. Get Revisions
const { data: revisionsData } = await supabase
.from("project_revisions")
.select("id, description, status, created_at, requested_by")
.eq("project_id", id)
.eq("client_id", clientData.id)
.order("created_at", { ascending: false });
return (
<PortalProjectClient
project={project}
sections={sectionsData || []}
tasks={tasksData || []}
revisions={revisionsData || []}
clientId={clientData.id}
project={data.project}
sections={data.sections}
tasks={data.tasks}
revisions={data.revisions}
/>
);
}
@@ -11,7 +11,46 @@ import { createRevisionRequest } from "./actions";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "poyraz-ui/molecules";
export function PortalProjectClient({ project, sections, tasks, revisions, clientId }: any) {
export type PortalProjectDetail = {
id: string;
name: string;
description: string | null;
status: "planning" | "active" | "paused" | "completed" | "cancelled";
progress: number;
due_date: string | null;
revision_quota: number;
can_request_revision: boolean;
};
export type PortalPlanningSection = {
id: string;
title: string;
content: string | null;
type: string;
};
export type PortalTask = {
id: string;
title: string;
status: "todo" | "in_progress" | "done";
date: string | null;
};
export type PortalRevision = {
id: string;
description: string;
status: "pending" | "in_progress" | "completed" | "rejected";
created_at: string;
};
type PortalProjectClientProps = {
project: PortalProjectDetail;
sections: PortalPlanningSection[];
tasks: PortalTask[];
revisions: PortalRevision[];
};
export function PortalProjectClient({ project, sections, tasks, revisions }: PortalProjectClientProps) {
const [isSubmitting, setIsSubmitting] = useState(false);
const [openRevision, setOpenRevision] = useState(false);
@@ -20,19 +59,19 @@ export function PortalProjectClient({ project, sections, tasks, revisions, clien
setIsSubmitting(true);
const formData = new FormData(e.currentTarget);
try {
const res = await createRevisionRequest(project.id, clientId, formData);
const res = await createRevisionRequest(project.id, formData);
if (res.error) throw new Error(res.error);
toast.success("Revizyon talebiniz başarıyla iletildi.");
setOpenRevision(false);
} catch (err: any) {
toast.error(err.message);
} catch (error: unknown) {
toast.error(error instanceof Error ? error.message : "Revizyon talebi oluşturulamadı.");
} finally {
setIsSubmitting(false);
}
};
const pendingRevisions = revisions.filter((r: any) => r.status === 'pending' || r.status === 'in_progress').length;
const hasRevisionQuota = project.revision_quota === null || project.revision_quota > 0;
const pendingRevisions = revisions.filter((revision) => revision.status === 'pending' || revision.status === 'in_progress').length;
const hasRevisionQuota = project.can_request_revision;
return (
<div className="mx-auto flex max-w-7xl flex-col gap-8 animate-in fade-in slide-in-from-bottom-4 duration-500">
@@ -64,8 +103,8 @@ export function PortalProjectClient({ project, sections, tasks, revisions, clien
</div>
)}
<div className="space-y-2">
<Label>Lütfen yapılmasını istediğiniz değişiklikleri detaylıca açıklayın</Label>
<Textarea name="description" required rows={5} placeholder="Şu kısmın rengi mavi olabilir mi? Ayrıca metinleri güncelleyelim..." />
<Label htmlFor="revision-description">Lütfen yapılmasını istediğiniz değişiklikleri detaylıca açıklayın</Label>
<Textarea id="revision-description" name="description" required rows={5} placeholder="Şu kısmın rengi mavi olabilir mi? Ayrıca metinleri güncelleyelim..." />
</div>
</div>
<DialogFooter>
@@ -138,15 +177,15 @@ export function PortalProjectClient({ project, sections, tasks, revisions, clien
<p className="text-sm text-muted-foreground italic">Listelenecek görev bulunmuyor.</p>
) : (
<ul className="space-y-3 max-h-60 overflow-y-auto tiny-scrollbar pr-2">
{tasks.map((task: any) => (
{tasks.map((task) => (
<li key={task.id} className="text-sm flex gap-3 p-2 rounded hover:bg-muted/30 transition-colors">
{task.status === 'completed' || task.status === 'done' ? (
{task.status === 'done' ? (
<CheckCircle2 className="h-4 w-4 text-emerald-500 shrink-0 mt-0.5" />
) : (
<div className="h-4 w-4 rounded-full border-2 border-muted-foreground/30 shrink-0 mt-0.5" />
)}
<div>
<span className={task.status === 'completed' || task.status === 'done' ? "text-muted-foreground" : "text-foreground font-medium"}>
<span className={task.status === 'done' ? "text-muted-foreground" : "text-foreground font-medium"}>
{task.title}
</span>
{task.date && (
@@ -171,7 +210,7 @@ export function PortalProjectClient({ project, sections, tasks, revisions, clien
</div>
) : (
<div className="space-y-4">
{sections.map((section: any) => (
{sections.map((section) => (
<Card key={section.id}>
<CardContent className="p-5 space-y-3">
<div className="flex items-center justify-between">
@@ -205,7 +244,7 @@ export function PortalProjectClient({ project, sections, tasks, revisions, clien
</div>
) : (
<div className="space-y-4">
{revisions.map((rev: any) => (
{revisions.map((rev) => (
<Card key={rev.id} className="transition-colors hover:border-primary/30">
<CardContent className="p-5">
<div className="flex justify-between items-start mb-3">