1+ import getNodeDefinitionsFromUser from "@/actions/shop/get-node-definition-previews-from-user" ;
2+ import { cookies } from "next/headers" ;
3+ import { createClient } from "@/utils/supabase/server" ;
4+ import { redirect } from "next/navigation" ;
5+ import { NodeDefinitionPreview } from "@/model/NodeDefinition" ;
6+ import { Card , CardContent , CardDescription , CardHeader , CardTitle } from "@/components/ui/card" ;
7+ import { Badge } from "@/components/ui/badge" ;
8+ import Link from "next/link" ;
9+ import { ArrowRight , Trash2 } from "lucide-react" ;
10+ import { Button } from "@/components/ui/button" ;
11+ import { getTranslations } from "next-intl/server" ;
12+ import { Tooltip , TooltipContent , TooltipTrigger } from "@/components/ui/tooltip" ;
13+ import removeNodeDefinitionPermanently from "@/actions/shop/remove-node-definition-permanently" ;
14+
15+ export default async function OwnNodesPage ( { params } : { params : { teamId : number } } ) {
16+
17+ const t = await getTranslations ( "shop" )
18+
19+ const cookieStore = cookies ( )
20+ const supabase = createClient ( cookieStore )
21+ const { data : userData , error} = await supabase . auth . getUser ( )
22+ if ( error || ! userData . user || ! userData . user . id ) {
23+ redirect ( "/authenticate" )
24+ }
25+
26+ const nodeDefinitions = await getNodeDefinitionsFromUser ( userData . user . id , params . teamId )
27+
28+ async function handleRemoveNode ( nodeId : number ) {
29+ "use server"
30+
31+ removeNodeDefinitionPermanently ( nodeId ) . then ( ( ) => {
32+ console . log ( "Node removed successfully" )
33+ } )
34+
35+ console . log ( "Removing node with id: " , nodeId )
36+ }
37+
38+ return < >
39+ < h2 className = "text-3xl font-bold" > { t ( "node.own-nodes" ) } </ h2 >
40+ < div className = "grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4" >
41+ { nodeDefinitions . map ( ( node : NodeDefinitionPreview ) => (
42+ < Card key = { node . id } className = "group hover:shadow-lg transition-shadow" >
43+ < CardHeader >
44+ < div className = "flex items-start justify-between" >
45+ < div >
46+ < CardTitle className = "text-lg" > { node . name } </ CardTitle >
47+ < CardDescription > { node . shortDescription } </ CardDescription >
48+ </ div >
49+ < Badge variant = "secondary" > { node . executionMode } </ Badge >
50+ </ div >
51+ </ CardHeader >
52+ < CardContent >
53+ < div className = "flex items-center justify-between" >
54+ < Link href = { `/${ params . teamId } /shop/node/${ node . id } ` }
55+ className = "inline-flex items-center text-sm text-primary hover:underline" >
56+ { t ( "node.viewDetails" ) }
57+ < ArrowRight className = "ml-1 h-4 w-4" />
58+ </ Link >
59+ { node . id && < form action = { handleRemoveNode . bind ( null , node . id ) } method = "POST" >
60+ < Tooltip delayDuration = { 0 } >
61+ < TooltipTrigger >
62+ < Button
63+ variant = "ghost"
64+ size = "icon"
65+ type = "submit"
66+ className = "h-8 w-8 text-muted-foreground hover:bg-destructive transition-colors"
67+ >
68+ < Trash2 className = "h-4 w-4" />
69+ < span className = "sr-only" > Remove node</ span >
70+ </ Button >
71+ </ TooltipTrigger >
72+ < TooltipContent >
73+ { t ( "node.removeNodePermanently" ) }
74+ </ TooltipContent >
75+ </ Tooltip >
76+ </ form > }
77+ </ div >
78+ </ CardContent >
79+ </ Card >
80+ ) ) }
81+ </ div >
82+ </ >
83+ }
0 commit comments