105 lines
6.7 KiB
HTML
105 lines
6.7 KiB
HTML
{{define "content"}}
|
|
<div class="p-8 max-w-6xl">
|
|
<div class="flex items-center justify-between mb-8">
|
|
<div>
|
|
<h1 class="text-2xl font-bold text-white mb-1">Projects</h1>
|
|
<p class="text-[#94a3b8] text-sm">All deals you have access to.</p>
|
|
</div>
|
|
<button id="newProjectBtn" class="hidden px-4 py-2 bg-[#c9a84c] hover:bg-[#b8973f] text-[#0a1628] font-semibold rounded-lg text-sm transition">+ New Project</button>
|
|
</div>
|
|
<div id="projectGrid" class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
|
|
<div class="text-[#94a3b8] text-sm col-span-3">Loading projects...</div>
|
|
</div>
|
|
<div id="emptyState" class="hidden text-center py-20">
|
|
<div class="text-5xl mb-4">📁</div>
|
|
<h2 class="text-xl font-semibold text-white mb-2">No projects yet</h2>
|
|
<p class="text-[#94a3b8]">You haven't been added to any deals yet.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- New Project Modal -->
|
|
<div id="newProjectModal" class="hidden fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4">
|
|
<div class="bg-[#0d1f3c] border border-white/[0.08] rounded-xl p-8 w-full max-w-md">
|
|
<h2 class="text-xl font-semibold text-white mb-6">New Project</h2>
|
|
<div id="modalError" class="hidden mb-4 p-3 bg-red-500/10 border border-red-500/20 rounded-lg text-red-400 text-sm"></div>
|
|
<div class="space-y-4">
|
|
<div><label class="block text-sm font-medium text-[#94a3b8] mb-1.5">Deal Name</label>
|
|
<input id="pName" type="text" placeholder="Project James" class="w-full px-4 py-2.5 bg-[#0a1628] border border-white/[0.08] rounded-lg text-white placeholder-[#475569] focus:outline-none focus:border-[#c9a84c] focus:ring-1 focus:ring-[#c9a84c]"></div>
|
|
<div><label class="block text-sm font-medium text-[#94a3b8] mb-1.5">Description</label>
|
|
<textarea id="pDesc" rows="2" placeholder="Brief description of this deal..." class="w-full px-4 py-2.5 bg-[#0a1628] border border-white/[0.08] rounded-lg text-white placeholder-[#475569] focus:outline-none focus:border-[#c9a84c] focus:ring-1 focus:ring-[#c9a84c] resize-none"></textarea></div>
|
|
<div><label class="block text-sm font-medium text-[#94a3b8] mb-1.5">Status</label>
|
|
<select id="pStatus" class="w-full px-4 py-2.5 bg-[#0a1628] border border-white/[0.08] rounded-lg text-white focus:outline-none focus:border-[#c9a84c]">
|
|
<option value="active">Active</option><option value="draft">Draft</option><option value="closed">Closed</option>
|
|
</select></div>
|
|
</div>
|
|
<div class="flex gap-3 mt-6">
|
|
<button onclick="closeModal()" class="flex-1 py-2.5 bg-white/[0.05] hover:bg-white/[0.08] text-white rounded-lg text-sm font-medium transition">Cancel</button>
|
|
<button id="createBtn" onclick="createProject()" class="flex-1 py-2.5 bg-[#c9a84c] hover:bg-[#b8973f] text-[#0a1628] font-semibold rounded-lg text-sm transition">Create</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{{end}}
|
|
|
|
{{define "scripts"}}
|
|
<script>
|
|
if (user.is_super_admin) {
|
|
document.getElementById('newProjectBtn').classList.remove('hidden');
|
|
}
|
|
|
|
const roleColors = { seller: 'bg-blue-500/20 text-blue-300', buyer: 'bg-green-500/20 text-green-300', ib: 'bg-[#c9a84c]/20 text-[#c9a84c]', advisor: 'bg-purple-500/20 text-purple-300' };
|
|
const statusColors = { active: 'bg-green-500/20 text-green-300', draft: 'bg-gray-500/20 text-gray-300', closed: 'bg-red-500/20 text-red-300', completed: 'bg-blue-500/20 text-blue-300' };
|
|
|
|
async function loadProjects() {
|
|
try {
|
|
const res = await fetchAPI('/api/projects');
|
|
const projects = await res.json();
|
|
const grid = document.getElementById('projectGrid');
|
|
if (!projects || projects.length === 0) {
|
|
grid.classList.add('hidden');
|
|
document.getElementById('emptyState').classList.remove('hidden');
|
|
return;
|
|
}
|
|
grid.innerHTML = projects.map(p => {
|
|
const d = parseData(p.data_text);
|
|
const status = d.status || 'active';
|
|
const sc = statusColors[status] || statusColors.active;
|
|
return `<a href="/app/projects/${p.entry_id}" class="card block bg-[#0d1f3c] border border-white/[0.08] rounded-xl p-6 transition cursor-pointer">
|
|
<div class="flex items-start justify-between mb-3">
|
|
<h3 class="text-white font-semibold text-lg leading-tight">${escHtml(d.name || p.summary || 'Untitled')}</h3>
|
|
<span class="ml-2 shrink-0 px-2 py-0.5 rounded-full text-xs font-medium ${sc} capitalize">${status}</span>
|
|
</div>
|
|
${d.description ? `<p class="text-[#94a3b8] text-sm mb-4 line-clamp-2">${escHtml(d.description)}</p>` : '<div class="mb-4"></div>'}
|
|
<div class="flex items-center gap-2 text-xs text-[#475569]">
|
|
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
|
|
${new Date(p.created_at).toLocaleDateString('en-US', {month:'short',day:'numeric',year:'numeric'})}
|
|
</div>
|
|
</a>`;
|
|
}).join('');
|
|
} catch(e) { document.getElementById('projectGrid').innerHTML = '<div class="text-red-400 text-sm col-span-3">Failed to load projects.</div>'; }
|
|
}
|
|
|
|
function openModal() { document.getElementById('newProjectModal').classList.remove('hidden'); document.getElementById('pName').focus(); }
|
|
function closeModal() { document.getElementById('newProjectModal').classList.add('hidden'); document.getElementById('modalError').classList.add('hidden'); }
|
|
document.getElementById('newProjectBtn').onclick = openModal;
|
|
|
|
async function createProject() {
|
|
const name = document.getElementById('pName').value.trim();
|
|
const desc = document.getElementById('pDesc').value.trim();
|
|
const status = document.getElementById('pStatus').value;
|
|
const errEl = document.getElementById('modalError');
|
|
const btn = document.getElementById('createBtn');
|
|
if (!name) { errEl.textContent = 'Deal name is required'; errEl.classList.remove('hidden'); return; }
|
|
btn.disabled = true; btn.textContent = 'Creating...';
|
|
errEl.classList.add('hidden');
|
|
try {
|
|
const res = await fetchAPI('/api/projects', { method: 'POST', body: JSON.stringify({ name, description: desc, status }) });
|
|
const data = await res.json();
|
|
if (!res.ok) throw new Error(data.error || 'Failed to create project');
|
|
window.location.href = '/app/projects/' + data.entry_id;
|
|
} catch(e) { errEl.textContent = e.message; errEl.classList.remove('hidden'); btn.disabled = false; btn.textContent = 'Create'; }
|
|
}
|
|
|
|
loadProjects();
|
|
</script>
|
|
{{end}}
|