diff --git a/src/app/(investment)/deals/[id]/UpdateTab.tsx b/src/app/(investment)/deals/[id]/UpdateTab.tsx
new file mode 100644
index 0000000..bbe73c3
--- /dev/null
+++ b/src/app/(investment)/deals/[id]/UpdateTab.tsx
@@ -0,0 +1,72 @@
+import { createSupabaseClient } from "@/lib/supabase/serverComponentClient";
+import { getProjectLogByProjectId } from "@/lib/data/projectLogQuery";
+import { LogEntry, parseProjectLog } from "./logParser";
+import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from "@/components/ui/card";
+
+export const UpdateTab = async ({ projectId }: { projectId: number }) => {
+ const supabase = createSupabaseClient();
+ const { data, error } = await getProjectLogByProjectId(supabase, projectId);
+
+ if (error) {
+ return (
+
+
+
+
+ No updates available
+ There are no updates to display at this time. Please check back later.
+
+
+
+
+ );
+ }
+
+ const parsedLogs = parseProjectLog(data as unknown as LogEntry[]);
+
+ if (parsedLogs.length === 0) {
+ return (
+
+
+
+
+ No updates available
+ There are no updates to display at this time. Please check back later.
+
+
+
+
+ );
+ }
+
+ return (
+
+ {parsedLogs.map((log, index) => (
+
+
+
+ {log.table}
+ {log.changes.length} Changes
+
+
+ {log.changes.map((change, changeIndex) => (
+
+
{change.field}
+
+ From: {JSON.stringify(change.from)}
+
+
+ To: {JSON.stringify(change.to)}
+
+
+ ))}
+
+
+ Updated at: {new Date(log.changed_at).toLocaleString()}
+
+
+
+ ))}
+
+ );
+};
diff --git a/src/app/(investment)/deals/[id]/logParser.ts b/src/app/(investment)/deals/[id]/logParser.ts
new file mode 100644
index 0000000..52b8c31
--- /dev/null
+++ b/src/app/(investment)/deals/[id]/logParser.ts
@@ -0,0 +1,57 @@
+export interface LogEntry {
+ id: number;
+ operation_type: string;
+ record_id: number;
+ old_data: Record;
+ new_data: Record;
+ changed_at: string;
+ table_name: string;
+}
+
+type ChangeSummary = {
+ field: string;
+ from: any;
+ to: any;
+};
+
+function parseProjectLog(logs: LogEntry[]): { changes: ChangeSummary[]; table: string; changed_at: string }[] {
+ return logs.map((log) => {
+ const changes: ChangeSummary[] = [];
+
+ if (log.table_name === "project_investment_detail") {
+ if (log.operation_type === "UPDATE") {
+ for (const key in log.old_data) {
+ if (log.old_data[key] !== log.new_data[key]) {
+ changes.push({
+ field: key,
+ from: log.old_data[key],
+ to: log.new_data[key],
+ });
+ }
+ }
+ }
+ }
+
+ if (log.table_name === "project") {
+ if (log.operation_type === "UPDATE") {
+ for (const key in log.old_data) {
+ if (log.old_data[key] !== log.new_data[key]) {
+ changes.push({
+ field: key,
+ from: log.old_data[key],
+ to: log.new_data[key],
+ });
+ }
+ }
+ }
+ }
+
+ return {
+ table: log.table_name,
+ changed_at: log.changed_at,
+ changes,
+ };
+ });
+}
+
+export { parseProjectLog };
diff --git a/src/app/(investment)/deals/[id]/page.tsx b/src/app/(investment)/deals/[id]/page.tsx
index 2a422d4..08a1430 100644
--- a/src/app/(investment)/deals/[id]/page.tsx
+++ b/src/app/(investment)/deals/[id]/page.tsx
@@ -17,6 +17,7 @@ import { getDealList } from "@/app/api/dealApi";
import { sumByKey, toPercentage } from "@/lib/utils";
import { redirect } from "next/navigation";
import { isOwnerOfProject } from "./query";
+import { UpdateTab } from "./UpdateTab";
import remarkGfm from "remark-gfm";
const PHOTO_MATERIAL_ID = 2;
@@ -241,11 +242,11 @@ export default async function ProjectDealPage({ params }: { params: { id: number
{/* menu */}
-
-
+
+
Pitch
- General Data
+ {/* General Data */}
Updates
@@ -253,7 +254,8 @@ export default async function ProjectDealPage({ params }: { params: { id: number
{projectData.project_name}
-
+ Project Pitch
+
@@ -264,7 +266,7 @@ export default async function ProjectDealPage({ params }: { params: { id: number
-
+ {/*
general
@@ -274,15 +276,16 @@ export default async function ProjectDealPage({ params }: { params: { id: number
general Content
-
+ */}
- update
- update Description
+ Update
+ Project log and updates
+
- update Content
+
diff --git a/src/lib/data/projectLogQuery.ts b/src/lib/data/projectLogQuery.ts
new file mode 100644
index 0000000..6981995
--- /dev/null
+++ b/src/lib/data/projectLogQuery.ts
@@ -0,0 +1,19 @@
+import { SupabaseClient } from "@supabase/supabase-js";
+import { Database } from "@/types/database.types";
+
+export function getProjectLogByProjectId(client: SupabaseClient
, projectId: number) {
+ return client
+ .from("project_log")
+ .select(
+ `
+ id,
+ operation_type,
+ record_id,
+ old_data,
+ new_data,
+ changed_at,
+ table_name
+ `
+ )
+ .eq("record_id", projectId);
+}
diff --git a/src/types/database.types.ts b/src/types/database.types.ts
index 9169905..146cd05 100644
Binary files a/src/types/database.types.ts and b/src/types/database.types.ts differ