Skip to content

Commit 763eaf0

Browse files
committed
redirect to specific task modal via home/kanban/ticket/[ticket code]
1 parent 44bb10f commit 763eaf0

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"use server";
2+
3+
import { createClientServerComponent } from "@/utils/supabase/server";
4+
5+
interface GetTaskDetailsResult {
6+
success: boolean;
7+
error?: string;
8+
data?: {
9+
project_id: string;
10+
board_id: string;
11+
task_id: string;
12+
};
13+
}
14+
15+
export const getTaskDetailsByTicketCode = async (
16+
ticket_code: string
17+
): Promise<GetTaskDetailsResult> => {
18+
const supabase = await createClientServerComponent();
19+
20+
if (!ticket_code) {
21+
return { success: false, error: "Ticket code is required" };
22+
}
23+
24+
// 1️⃣ Get task_id from task_ticket_codes
25+
const { data: taskTicket, error: taskTicketError } = await supabase
26+
.from("task_ticket_codes")
27+
.select("task_id")
28+
.eq("ticket_code", ticket_code)
29+
.single();
30+
31+
if (taskTicketError || !taskTicket) {
32+
return { success: false, error: taskTicketError?.message || "Ticket not found" };
33+
}
34+
35+
const task_id = taskTicket.task_id;
36+
37+
// 2️⃣ Get kanban_column_id from tasks
38+
const { data: task, error: taskError } = await supabase
39+
.from("tasks")
40+
.select("kanban_column_id")
41+
.eq("id", task_id)
42+
.single();
43+
44+
if (taskError || !task) {
45+
return { success: false, error: taskError?.message || "Task not found" };
46+
}
47+
48+
const kanban_column_id = task.kanban_column_id;
49+
50+
// 3️⃣ Get board_id and project_id from kanban_columns
51+
const { data: column, error: columnError } = await supabase
52+
.from("kanban_columns")
53+
.select("board_id")
54+
.eq("id", kanban_column_id)
55+
.single();
56+
57+
if (columnError || !column) {
58+
return { success: false, error: columnError?.message || "Column not found" };
59+
}
60+
61+
const board_id = column.board_id;
62+
63+
// 4️⃣ Get project_id from kanban_boards
64+
const { data: board, error: boardError } = await supabase
65+
.from("kanban_boards")
66+
.select("project_id")
67+
.eq("id", board_id)
68+
.single();
69+
70+
if (boardError || !board) {
71+
return { success: false, error: boardError?.message || "Board not found" };
72+
}
73+
74+
const project_id = board.project_id;
75+
76+
return {
77+
success: true,
78+
data: { task_id, board_id, project_id },
79+
};
80+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { redirect } from 'next/navigation';
2+
import { getTaskDetailsByTicketCode } from './actions';
3+
4+
interface PageProps {
5+
params: {
6+
ticketCode: string;
7+
};
8+
}
9+
10+
export default async function TicketPage({ params }: PageProps) {
11+
const { ticketCode } = params;
12+
13+
const ticketInfo = await getTaskDetailsByTicketCode(ticketCode);
14+
15+
// Determine where to redirect
16+
const destination = `/home/kanban/${ticketInfo.data?.project_id}/${ticketInfo.data?.board_id}?taskId=${ticketInfo.data?.task_id}`;
17+
18+
redirect(destination);
19+
}

0 commit comments

Comments
 (0)