From 1022b3df3a909c27d7d17c938395cbfeaa66508f Mon Sep 17 00:00:00 2001 From: "tejas.prakash" Date: Thu, 21 Aug 2025 15:28:43 +0530 Subject: [PATCH] Updated --- src/components/edit-template-form.tsx | 4 +- src/components/main-dashboard.tsx | 140 +++++++++++++------------- src/hooks/useTemplates.ts | 52 +++++++--- src/lib/template-service.ts | 9 +- 4 files changed, 116 insertions(+), 89 deletions(-) diff --git a/src/components/edit-template-form.tsx b/src/components/edit-template-form.tsx index 93b501e..1994bb4 100644 --- a/src/components/edit-template-form.tsx +++ b/src/components/edit-template-form.tsx @@ -203,7 +203,7 @@ export function EditTemplateForm({ template, onSubmit, onCancel }: EditTemplateF type="button" variant="outline" onClick={onCancel} - className="border-white/20 text-white hover:bg-white/10" + className="border-white/20 text-white hover:bg-white/10 cursor-pointer" disabled={loading} > @@ -211,7 +211,7 @@ export function EditTemplateForm({ template, onSubmit, onCancel }: EditTemplateF - + + @@ -618,11 +623,11 @@ function FeatureSelectionStep({
- + @@ -730,8 +735,8 @@ function BusinessQuestionsStep({ (selected as any[]).some((f: any) => f.complexity === 'high') ? 'high' : (selected as any[]).some((f: any) => f.complexity === 'medium') - ? 'medium' - : 'low', + ? 'medium' + : 'low', logicRules: (selected as any[]).flatMap((f: any) => f.logicRules || []), } @@ -826,18 +831,18 @@ function TechStackSummaryStep({

Core Feature

-
-
{functional.feature_name}
-
{functional.description}
+
+
{functional.feature_name}
+
{functional.description}
-

Complexity Level

-
+ {/*

Complexity Level

+
{(functional.complexity_level || 'medium').toUpperCase()} -
+
*/}
@@ -920,8 +925,8 @@ function TechStackSummaryStep({
- - + +
AI will design complete architecture
@@ -1007,21 +1012,19 @@ export function MainDashboard() {
  • = step.id + className={`flex items-center justify-center w-10 h-10 rounded-full border-2 transition-all ${currentStep >= step.id ? "bg-orange-500 border-orange-500 text-white shadow-lg" : currentStep === step.id - 1 ? "border-orange-300 text-orange-400" : "border-white/30 text-white/40" - }`} + }`} > {step.id}

    = step.id ? "text-orange-400" : "text-white/60" - }`} + className={`text-sm font-semibold ${currentStep >= step.id ? "text-orange-400" : "text-white/60" + }`} > {step.name}

    @@ -1152,11 +1155,10 @@ function ArchitectureDesignerStep({ recommendations, onBack }: { recommendations diff --git a/src/hooks/useTemplates.ts b/src/hooks/useTemplates.ts index de8502b..ae8d748 100644 --- a/src/hooks/useTemplates.ts +++ b/src/hooks/useTemplates.ts @@ -60,7 +60,7 @@ export function useTemplates() { } // Convert database templates to the format expected by the UI - const getTemplatesForUI = () => { + const getTemplatesForUI = async () => { const allTemplates: Array = [] - Object.entries(templates).forEach(([category, categoryTemplates]) => { - categoryTemplates.forEach((template) => { - // Convert database template to UI format - const uiTemplate = { - ...template, - features: [], // Will be populated when template is selected - complexity: 3, // Default complexity - timeEstimate: "2-4 weeks", // Default time estimate - techStack: ["Next.js", "PostgreSQL", "Tailwind CSS"], // Default tech stack - popularity: template.avg_rating ? Math.round(template.avg_rating * 20) : 75, // Convert rating to popularity - lastUpdated: template.updated_at ? new Date(template.updated_at).toISOString().split('T')[0] : undefined, - featureCount: (template as any).feature_count ?? 0 + for (const [category, categoryTemplates] of Object.entries(templates)) { + for (const template of categoryTemplates) { + try { + // Fetch features for this template + const features = await templateService.getFeaturesForTemplate(template.id) + const featureNames = features.map(f => f.name) + + // Convert database template to UI format + const uiTemplate = { + ...template, + features: featureNames, // Use actual features from API + complexity: 3, // Default complexity + timeEstimate: "2-4 weeks", // Default time estimate + techStack: ["Next.js", "PostgreSQL", "Tailwind CSS"], // Default tech stack + popularity: template.avg_rating ? Math.round(template.avg_rating * 20) : 75, // Convert rating to popularity + lastUpdated: template.updated_at ? new Date(template.updated_at).toISOString().split('T')[0] : undefined, + featureCount: featureNames.length + } + allTemplates.push(uiTemplate) + } catch (error) { + console.error(`Error fetching features for template ${template.id}:`, error) + // Fallback with empty features + const uiTemplate = { + ...template, + features: [], + complexity: 3, + timeEstimate: "2-4 weeks", + techStack: ["Next.js", "PostgreSQL", "Tailwind CSS"], + popularity: template.avg_rating ? Math.round(template.avg_rating * 20) : 75, + lastUpdated: template.updated_at ? new Date(template.updated_at).toISOString().split('T')[0] : undefined, + featureCount: 0 + } + allTemplates.push(uiTemplate) } - allTemplates.push(uiTemplate) - }) - }) + } + } return allTemplates } diff --git a/src/lib/template-service.ts b/src/lib/template-service.ts index 5593c4f..2596e70 100644 --- a/src/lib/template-service.ts +++ b/src/lib/template-service.ts @@ -149,15 +149,20 @@ class TemplateService { } try { - const merged = await this.makeRequest(`/api/features/templates/${templateId}/merged`) + const merged = await this.makeRequest(`/api/templates/${templateId}/features`) return dedupe(merged) } catch { // Fallback to default-only if merged endpoint unsupported - const defaults = await this.makeRequest(`/api/templates/${templateId}/features`) + const defaults = await this.makeRequest(`/api/features/templates/${templateId}/merged`) return dedupe(defaults) } } + // Default-only features for template (does not include custom/merged) + // async getDefaultFeaturesForTemplate(templateId: string): Promise { + // return this.makeRequest(`/api/templates/${templateId}/features`) + // } + async searchFeatures(searchTerm: string, templateId?: string): Promise { const q = encodeURIComponent(searchTerm) const extra = templateId ? `&template_id=${encodeURIComponent(templateId)}` : ''