From 84adf514d1c986ed02f6998d333e7258ab88450f Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Wed, 12 Nov 2025 10:30:06 -0800 Subject: [PATCH 1/2] Fix v1 --- .../[workspaceId]/templates/[id]/page.tsx | 108 +------- .../[workspaceId]/templates/[id]/template.tsx | 158 ++++++----- .../[workspaceId]/templates/page.tsx | 21 +- .../[workspaceId]/templates/templates.tsx | 248 +++++++++--------- 4 files changed, 237 insertions(+), 298 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/templates/[id]/page.tsx b/apps/sim/app/workspace/[workspaceId]/templates/[id]/page.tsx index 90c3297c45..20d4c17388 100644 --- a/apps/sim/app/workspace/[workspaceId]/templates/[id]/page.tsx +++ b/apps/sim/app/workspace/[workspaceId]/templates/[id]/page.tsx @@ -1,105 +1,9 @@ -import { db } from '@sim/db' -import { templateCreators, templateStars, templates } from '@sim/db/schema' -import { and, eq } from 'drizzle-orm' -import { notFound } from 'next/navigation' -import { getSession } from '@/lib/auth' -import { createLogger } from '@/lib/logs/console/logger' import TemplateDetails from '@/app/workspace/[workspaceId]/templates/[id]/template' -const logger = createLogger('TemplatePage') - -interface TemplatePageProps { - params: Promise<{ - workspaceId: string - id: string - }> -} - -export default async function TemplatePage({ params }: TemplatePageProps) { - const { workspaceId, id } = await params - - try { - if (!id || typeof id !== 'string' || id.length !== 36) { - notFound() - } - - const session = await getSession() - - const templateData = await db - .select({ - template: templates, - creator: templateCreators, - }) - .from(templates) - .leftJoin(templateCreators, eq(templates.creatorId, templateCreators.id)) - .where(eq(templates.id, id)) - .limit(1) - - if (templateData.length === 0) { - notFound() - } - - const { template, creator } = templateData[0] - - if (!session?.user?.id && template.status !== 'approved') { - notFound() - } - - if (!template.id || !template.name) { - logger.error('Template missing required fields:', { - id: template.id, - name: template.name, - }) - notFound() - } - - let isStarred = false - if (session?.user?.id) { - try { - const starData = await db - .select({ id: templateStars.id }) - .from(templateStars) - .where( - and( - eq(templateStars.templateId, template.id), - eq(templateStars.userId, session.user.id) - ) - ) - .limit(1) - isStarred = starData.length > 0 - } catch { - isStarred = false - } - } - - const serializedTemplate = { - ...template, - creator: creator || null, - createdAt: template.createdAt.toISOString(), - updatedAt: template.updatedAt.toISOString(), - isStarred, - } - - return ( - - ) - } catch (error) { - logger.error('Error loading template:', error) - return ( -
-
-

Error Loading Template

-

There was an error loading this template.

-

Template ID: {id}

-

- {error instanceof Error ? error.message : 'Unknown error'} -

-
-
- ) - } +/** + * Workspace-scoped template detail page. + * Data fetching is handled client-side in the TemplateDetails component. + */ +export default function TemplatePage() { + return } diff --git a/apps/sim/app/workspace/[workspaceId]/templates/[id]/template.tsx b/apps/sim/app/workspace/[workspaceId]/templates/[id]/template.tsx index 82edd109a5..9c7dca100c 100644 --- a/apps/sim/app/workspace/[workspaceId]/templates/[id]/template.tsx +++ b/apps/sim/app/workspace/[workspaceId]/templates/[id]/template.tsx @@ -45,7 +45,7 @@ import { Wrench, Zap, } from 'lucide-react' -import { useRouter, useSearchParams } from 'next/navigation' +import { useParams, useRouter, useSearchParams } from 'next/navigation' import { Button } from '@/components/emcn' import { createLogger } from '@/lib/logs/console/logger' import { cn } from '@/lib/utils' @@ -55,12 +55,6 @@ import type { WorkflowState } from '@/stores/workflows/workflow/types' const logger = createLogger('TemplateDetails') -interface TemplateDetailsProps { - template: Template - workspaceId: string - currentUserId: string | null -} - // Icon mapping - reuse from template-card const iconMap = { FileText, @@ -115,22 +109,69 @@ const getIconComponent = (icon: string): React.ReactNode => { ) } -export default function TemplateDetails({ - template, - workspaceId, - currentUserId, -}: TemplateDetailsProps) { +/** + * Template detail page component + * Fetches and displays detailed information about a specific template + */ +export default function TemplateDetails() { const router = useRouter() const searchParams = useSearchParams() + const params = useParams() - // Initialize all state hooks first (hooks must be called unconditionally) - const [isStarred, setIsStarred] = useState(template?.isStarred || false) - const [starCount, setStarCount] = useState(template?.stars || 0) + const workspaceId = params?.workspaceId as string + const templateId = params?.id as string + + // State for template data + const [template, setTemplate] = useState