| 1 |
import React, { useState } from 'react'; |
| 2 |
import { templates } from '../constants/templates'; |
| 3 |
import Modal from './ui/Modal'; |
| 4 |
import { Button } from './ui/Button'; |
| 5 |
import { Plus, Lock, Sparkles } from 'lucide-react'; |
| 6 |
import AiWorkflowGenerator from './AiWorkflowGenerator'; |
| 7 |
|
| 8 |
const TemplatesModal = ({ isOpen, onClose, onSelect, isProActive }) => { |
| 9 |
const [tab, setTab] = useState('templates'); |
| 10 |
|
| 11 |
const handleSelect = (template) => { |
| 12 |
setTab('templates'); |
| 13 |
onSelect(template); |
| 14 |
}; |
| 15 |
|
| 16 |
return ( |
| 17 |
<Modal |
| 18 |
isOpen={isOpen} |
| 19 |
onClose={onClose} |
| 20 |
title="Create New Workflow" |
| 21 |
maxWidth="max-w-4xl" |
| 22 |
> |
| 23 |
<div className="space-y-5"> |
| 24 |
|
| 25 |
{/* Tab switcher */} |
| 26 |
<div className="flex gap-1 bg-muted/40 border border-border rounded-lg p-1 w-fit -mt-1"> |
| 27 |
<button |
| 28 |
onClick={() => setTab('templates')} |
| 29 |
className={`px-4 py-1.5 text-sm font-medium rounded-md transition-colors ${ |
| 30 |
tab === 'templates' |
| 31 |
? 'bg-background shadow-sm text-foreground' |
| 32 |
: 'text-muted-foreground hover:text-foreground' |
| 33 |
}`} |
| 34 |
> |
| 35 |
Templates |
| 36 |
</button> |
| 37 |
<button |
| 38 |
onClick={() => setTab('ai')} |
| 39 |
className={`flex items-center gap-1.5 px-4 py-1.5 text-sm font-medium rounded-md transition-colors ${ |
| 40 |
tab === 'ai' |
| 41 |
? 'bg-background shadow-sm text-foreground' |
| 42 |
: 'text-muted-foreground hover:text-foreground' |
| 43 |
}`} |
| 44 |
> |
| 45 |
<Sparkles className="w-3.5 h-3.5" /> |
| 46 |
AI Generator |
| 47 |
</button> |
| 48 |
</div> |
| 49 |
|
| 50 |
{tab === 'templates' ? ( |
| 51 |
<> |
| 52 |
<p className="text-sm text-muted-foreground -mt-2"> |
| 53 |
Start with a pre-configured workflow or start from scratch. |
| 54 |
</p> |
| 55 |
|
| 56 |
<div className="grid grid-cols-2 md:grid-cols-2 gap-4"> |
| 57 |
{/* Start from Scratch Option */} |
| 58 |
<div |
| 59 |
onClick={() => handleSelect(null)} |
| 60 |
className="flex flex-col items-center justify-center p-6 border-2 border-dashed border-border rounded-xl hover:border-primary hover:bg-primary/5 cursor-pointer transition-all group text-center" |
| 61 |
> |
| 62 |
<div className="w-12 h-12 rounded-full bg-muted flex items-center justify-center text-muted-foreground group-hover:bg-primary group-hover:text-primary-foreground transition-colors mb-3"> |
| 63 |
<Plus className="w-6 h-6" /> |
| 64 |
</div> |
| 65 |
<h3 className="font-bold text-lg text-foreground">Start from Scratch</h3> |
| 66 |
<p className="text-sm text-muted-foreground mt-1">Begin with an empty canvas and build your own workflow.</p> |
| 67 |
</div> |
| 68 |
|
| 69 |
{/* Prebuilt Templates */} |
| 70 |
{templates.map((template) => { |
| 71 |
const locked = template.isPro && !isProActive; |
| 72 |
return ( |
| 73 |
<div |
| 74 |
key={template.id} |
| 75 |
onClick={() => !locked && handleSelect(template)} |
| 76 |
className={`relative flex flex-col p-6 border rounded-xl transition-all bg-card/50 group ${ |
| 77 |
locked |
| 78 |
? 'border-border opacity-60 cursor-not-allowed select-none' |
| 79 |
: 'border-border hover:border-primary hover:shadow-lg cursor-pointer' |
| 80 |
}`} |
| 81 |
> |
| 82 |
{/* PRO badge */} |
| 83 |
{template.isPro && ( |
| 84 |
<span className="absolute top-3 right-3 flex items-center gap-1 text-[10px] font-bold uppercase tracking-wide bg-amber-100 text-amber-700 border border-amber-300 rounded px-1.5 py-0.5"> |
| 85 |
{locked && <Lock className="w-2.5 h-2.5" />} |
| 86 |
PRO |
| 87 |
</span> |
| 88 |
)} |
| 89 |
|
| 90 |
<div className="flex items-center space-x-4 mb-4"> |
| 91 |
<div className={`w-24 h-12 rounded-xl ${template.iconBg} flex items-center justify-center text-white text-sm font-bold shadow-sm ${!locked ? 'group-hover:scale-110' : ''} transition-transform`}> |
| 92 |
{template.icon} |
| 93 |
</div> |
| 94 |
<div className="pr-8"> |
| 95 |
<h3 className="font-bold text-foreground leading-tight">{template.name}</h3> |
| 96 |
<span className="text-[10px] uppercase tracking-wider text-muted-foreground font-semibold">Prebuilt</span> |
| 97 |
</div> |
| 98 |
</div> |
| 99 |
<p className="text-sm text-muted-foreground line-clamp-3"> |
| 100 |
{template.description} |
| 101 |
</p> |
| 102 |
|
| 103 |
{locked ? ( |
| 104 |
<div className="mt-6 flex items-center text-xs font-medium text-amber-600"> |
| 105 |
<Lock className="w-3.5 h-3.5 mr-1.5" /> |
| 106 |
<span>Requires Pro license</span> |
| 107 |
<a |
| 108 |
href="https://wpbot.pro" |
| 109 |
target="_blank" |
| 110 |
rel="noopener noreferrer" |
| 111 |
onClick={(e) => e.stopPropagation()} |
| 112 |
className="ml-1 underline hover:text-amber-800" |
| 113 |
> |
| 114 |
Upgrade |
| 115 |
</a> |
| 116 |
</div> |
| 117 |
) : ( |
| 118 |
<div className="mt-6 flex items-center text-xs font-medium text-primary opacity-0 group-hover:opacity-100 transition-opacity"> |
| 119 |
<span>Use this template</span> |
| 120 |
<svg className="ml-2 w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg> |
| 121 |
</div> |
| 122 |
)} |
| 123 |
</div> |
| 124 |
); |
| 125 |
})} |
| 126 |
</div> |
| 127 |
</> |
| 128 |
) : ( |
| 129 |
<AiWorkflowGenerator onSelect={handleSelect} /> |
| 130 |
)} |
| 131 |
|
| 132 |
<div className="flex justify-end pt-2"> |
| 133 |
<Button variant="ghost" onClick={onClose}> |
| 134 |
Close |
| 135 |
</Button> |
| 136 |
</div> |
| 137 |
</div> |
| 138 |
</Modal> |
| 139 |
); |
| 140 |
}; |
| 141 |
|
| 142 |
export default TemplatesModal; |
| 143 |
|