File: /var/www/indoadvisory_new/webapp/src/routes/clients.js
import { jsx as _jsx, jsxs as _jsxs } from "hono/jsx/jsx-runtime";
import { Hono } from 'hono';
import { getCookie } from 'hono/cookie';
const clients = new Hono();
// Middleware to check authentication
async function requireAuth(c, next) {
const sessionId = getCookie(c, 'admin_session');
if (!sessionId) {
return c.redirect('/admin/login');
}
// Verify session
const session = await c.env.DB.prepare('SELECT * FROM admin_sessions WHERE id = ? AND expires_at > datetime("now")').bind(sessionId).first();
if (!session) {
return c.redirect('/admin/login');
}
return next();
}
clients.use('*', requireAuth);
// Client list page
clients.get('/', async (c) => {
try {
const page = parseInt(c.req.query('page') || '1');
const limit = 10;
const offset = (page - 1) * limit;
const search = c.req.query('search') || '';
const status = c.req.query('status') || 'all';
let query = 'SELECT * FROM clients';
let countQuery = 'SELECT COUNT(*) as total FROM clients';
const params = [];
const conditions = [];
if (search) {
conditions.push('(company_name LIKE ? OR industry LIKE ? OR project_type LIKE ?)');
const searchPattern = `%${search}%`;
params.push(searchPattern, searchPattern, searchPattern);
}
if (status !== 'all') {
if (status === 'active') {
conditions.push('is_active = 1');
}
else if (status === 'featured') {
conditions.push('is_featured = 1');
}
}
if (conditions.length > 0) {
const whereClause = ' WHERE ' + conditions.join(' AND ');
query += whereClause;
countQuery += whereClause;
}
query += ' ORDER BY sort_order ASC, created_at DESC LIMIT ? OFFSET ?';
params.push(limit, offset);
const [clientsResult, countResult] = await Promise.all([
c.env.DB.prepare(query).bind(...params).all(),
c.env.DB.prepare(countQuery).bind(...(params.slice(0, -2))).first()
]);
const totalPages = Math.ceil(countResult.total / limit);
return c.render(_jsxs("div", { class: "min-h-screen bg-gray-50", children: [_jsx("div", { class: "bg-white shadow-sm border-b border-gray-200", children: _jsx("div", { class: "max-w-7xl mx-auto px-4 sm:px-6 lg:px-8", children: _jsxs("div", { class: "flex justify-between items-center h-16", children: [_jsxs("div", { class: "flex items-center space-x-4", children: [_jsxs("a", { href: "/admin", class: "text-gray-500 hover:text-gray-700", children: [_jsx("i", { class: "fas fa-arrow-left mr-2" }), "Kembali ke Dashboard"] }), _jsx("div", { class: "text-gray-300", children: "\u2022" }), _jsx("h1", { class: "text-xl font-semibold text-gray-900", children: "Manajemen Klien" })] }), _jsxs("a", { href: "/admin/clients/create", class: "mckinsey-btn px-4 py-2 rounded-lg text-sm font-medium", children: [_jsx("i", { class: "fas fa-plus mr-2" }), "Tambah Klien"] })] }) }) }), _jsxs("div", { class: "max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8", children: [_jsx("div", { class: "bg-white rounded-lg shadow-sm p-6 mb-6", children: _jsxs("form", { method: "GET", class: "flex flex-wrap gap-4", children: [_jsxs("div", { class: "flex-1 min-w-64", children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Pencarian" }), _jsx("input", { type: "text", name: "search", value: search, placeholder: "Cari nama perusahaan, industri, atau jenis proyek...", class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent" })] }), _jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Status" }), _jsxs("select", { name: "status", class: "px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", children: [_jsx("option", { value: "all", selected: status === 'all', children: "Semua" }), _jsx("option", { value: "active", selected: status === 'active', children: "Aktif" }), _jsx("option", { value: "featured", selected: status === 'featured', children: "Featured" })] })] }), _jsx("div", { class: "flex items-end", children: _jsxs("button", { type: "submit", class: "mckinsey-btn px-4 py-2 rounded-md text-sm font-medium", children: [_jsx("i", { class: "fas fa-search mr-2" }), "Cari"] }) })] }) }), _jsx("div", { class: "bg-white rounded-lg shadow-sm overflow-hidden", children: _jsxs("table", { class: "min-w-full divide-y divide-gray-200", children: [_jsx("thead", { class: "bg-gray-50", children: _jsxs("tr", { children: [_jsx("th", { class: "px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider", children: "Perusahaan" }), _jsx("th", { class: "px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider", children: "Industri" }), _jsx("th", { class: "px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider", children: "Proyek" }), _jsx("th", { class: "px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider", children: "Nilai" }), _jsx("th", { class: "px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider", children: "Status" }), _jsx("th", { class: "px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider", children: "Aksi" })] }) }), _jsx("tbody", { class: "bg-white divide-y divide-gray-200", children: clientsResult.results.length > 0 ? clientsResult.results.map(client => (_jsxs("tr", { class: "hover:bg-gray-50", children: [_jsx("td", { class: "px-6 py-4 whitespace-nowrap", children: _jsxs("div", { class: "flex items-center", children: [_jsx("div", { class: "w-10 h-10 bg-mckinsey-blue rounded-lg flex items-center justify-center mr-3", children: _jsx("i", { class: "fas fa-building text-white text-sm" }) }), _jsxs("div", { children: [_jsx("div", { class: "text-sm font-medium text-gray-900", children: client.company_name }), _jsxs("div", { class: "text-sm text-gray-500", children: ["Urutan: ", client.sort_order] })] })] }) }), _jsx("td", { class: "px-6 py-4 whitespace-nowrap", children: _jsx("span", { class: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800", children: client.industry }) }), _jsxs("td", { class: "px-6 py-4 whitespace-nowrap", children: [_jsx("div", { class: "text-sm text-gray-900", children: client.project_type }), client.completion_date && (_jsx("div", { class: "text-sm text-gray-500", children: new Date(client.completion_date).toLocaleDateString('id-ID') }))] }), _jsx("td", { class: "px-6 py-4 whitespace-nowrap", children: _jsx("div", { class: "text-sm font-medium text-gray-900", children: client.project_value || '-' }) }), _jsx("td", { class: "px-6 py-4 whitespace-nowrap", children: _jsxs("div", { class: "flex flex-col space-y-1", children: [_jsx("span", { class: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${client.is_active
? 'bg-green-100 text-green-800'
: 'bg-red-100 text-red-800'}`, children: client.is_active ? 'Aktif' : 'Nonaktif' }), client.is_featured && (_jsx("span", { class: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800", children: "Featured" }))] }) }), _jsxs("td", { class: "px-6 py-4 whitespace-nowrap text-sm font-medium space-x-2", children: [_jsxs("a", { href: `/admin/clients/${client.id}/edit`, class: "text-mckinsey-blue hover:text-mckinsey-darkblue", children: [_jsx("i", { class: "fas fa-edit mr-1" }), "Edit"] }), _jsxs("button", { onclick: `deleteClient(${client.id})`, class: "text-red-600 hover:text-red-900 ml-2", children: [_jsx("i", { class: "fas fa-trash mr-1" }), "Hapus"] })] })] }))) : (_jsx("tr", { children: _jsxs("td", { colspan: "6", class: "px-6 py-12 text-center text-gray-500", children: [_jsx("i", { class: "fas fa-building text-gray-400 text-4xl mb-4" }), _jsx("div", { class: "text-lg font-medium text-gray-400 mb-2", children: "Belum ada klien" }), _jsx("p", { class: "text-gray-400", children: "Klik \"Tambah Klien\" untuk menambah klien pertama" })] }) })) })] }) }), totalPages > 1 && (_jsxs("div", { class: "bg-white px-4 py-3 flex items-center justify-between border-t border-gray-200 sm:px-6 mt-6 rounded-lg", children: [_jsxs("div", { class: "flex-1 flex justify-between sm:hidden", children: [page > 1 && (_jsx("a", { href: `/admin/clients?page=${page - 1}&search=${search}&status=${status}`, class: "relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50", children: "Previous" })), page < totalPages && (_jsx("a", { href: `/admin/clients?page=${page + 1}&search=${search}&status=${status}`, class: "ml-3 relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50", children: "Next" }))] }), _jsxs("div", { class: "hidden sm:flex-1 sm:flex sm:items-center sm:justify-between", children: [_jsx("div", { children: _jsxs("p", { class: "text-sm text-gray-700", children: ["Menampilkan", ' ', _jsx("span", { class: "font-medium", children: Math.min((page - 1) * limit + 1, countResult.total) }), ' ', "sampai", ' ', _jsx("span", { class: "font-medium", children: Math.min(page * limit, countResult.total) }), ' ', "dari", ' ', _jsx("span", { class: "font-medium", children: countResult.total }), ' ', "hasil"] }) }), _jsx("div", { children: _jsx("nav", { class: "relative z-0 inline-flex rounded-md shadow-sm -space-x-px", children: Array.from({ length: totalPages }, (_, i) => i + 1).map(pageNum => (_jsx("a", { href: `/admin/clients?page=${pageNum}&search=${search}&status=${status}`, class: `relative inline-flex items-center px-4 py-2 border text-sm font-medium ${pageNum === page
? 'z-10 bg-mckinsey-blue border-mckinsey-blue text-white'
: 'bg-white border-gray-300 text-gray-500 hover:bg-gray-50'}`, children: pageNum }))) }) })] })] }))] }), _jsx("script", { dangerouslySetInnerHTML: { __html: `
async function deleteClient(clientId) {
if (!confirm('Apakah Anda yakin ingin menghapus klien ini?')) {
return;
}
try {
const response = await fetch('/admin/clients/' + clientId, {
method: 'DELETE'
});
if (response.ok) {
location.reload();
} else {
alert('Gagal menghapus klien. Silakan coba lagi.');
}
} catch (error) {
alert('Terjadi kesalahan. Silakan coba lagi.');
}
}
` } })] }), {
title: 'Manajemen Klien - IndoAdvisory Admin'
});
}
catch (error) {
console.error('Clients list error:', error);
return c.render(_jsx("div", { children: "Error loading clients" }));
}
});
// Create client form
clients.get('/create', async (c) => {
return c.render(_jsxs("div", { class: "min-h-screen bg-gray-50", children: [_jsx("div", { class: "bg-white shadow-sm border-b border-gray-200", children: _jsx("div", { class: "max-w-4xl mx-auto px-4 sm:px-6 lg:px-8", children: _jsxs("div", { class: "flex items-center space-x-4 h-16", children: [_jsxs("a", { href: "/admin/clients", class: "text-gray-500 hover:text-gray-700", children: [_jsx("i", { class: "fas fa-arrow-left mr-2" }), "Kembali ke Daftar Klien"] }), _jsx("div", { class: "text-gray-300", children: "\u2022" }), _jsx("h1", { class: "text-xl font-semibold text-gray-900", children: "Tambah Klien Baru" })] }) }) }), _jsx("div", { class: "max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8", children: _jsxs("form", { method: "POST", action: "/admin/clients", class: "space-y-6", children: [_jsxs("div", { class: "bg-white rounded-lg shadow-sm p-6", children: [_jsx("h3", { class: "text-lg font-medium text-gray-900 mb-6", children: "Informasi Dasar" }), _jsxs("div", { class: "grid grid-cols-1 md:grid-cols-2 gap-6", children: [_jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Nama Perusahaan *" }), _jsx("input", { type: "text", name: "company_name", required: true, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", placeholder: "Contoh: PT Teknologi Nusantara" })] }), _jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Industri *" }), _jsxs("select", { name: "industry", required: true, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", children: [_jsx("option", { value: "", children: "Pilih industri" }), _jsx("option", { value: "Technology", children: "Technology" }), _jsx("option", { value: "Finance", children: "Finance" }), _jsx("option", { value: "Healthcare", children: "Healthcare" }), _jsx("option", { value: "Manufacturing", children: "Manufacturing" }), _jsx("option", { value: "Retail", children: "Retail" }), _jsx("option", { value: "Energy", children: "Energy" }), _jsx("option", { value: "Agriculture", children: "Agriculture" }), _jsx("option", { value: "Real Estate", children: "Real Estate" }), _jsx("option", { value: "E-commerce", children: "E-commerce" }), _jsx("option", { value: "Other", children: "Other" })] })] })] }), _jsxs("div", { class: "grid grid-cols-1 md:grid-cols-2 gap-6 mt-6", children: [_jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Jenis Proyek *" }), _jsxs("select", { name: "project_type", required: true, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", children: [_jsx("option", { value: "", children: "Pilih jenis proyek" }), _jsx("option", { value: "valuation", children: "Valuasi Perusahaan" }), _jsx("option", { value: "ipo", children: "Persiapan IPO" }), _jsx("option", { value: "ma", children: "M&A Advisory" }), _jsx("option", { value: "fundraising", children: "Fundraising" }), _jsx("option", { value: "restructuring", children: "Restructuring" }), _jsx("option", { value: "dd", children: "Due Diligence" })] })] }), _jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Nilai Proyek" }), _jsx("input", { type: "text", name: "project_value", class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", placeholder: "Contoh: $25M Series B, Rp 2.1T IPO" })] })] }), _jsxs("div", { class: "mt-6", children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Tanggal Penyelesaian" }), _jsx("input", { type: "date", name: "completion_date", class: "px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent" })] })] }), _jsxs("div", { class: "bg-white rounded-lg shadow-sm p-6", children: [_jsx("h3", { class: "text-lg font-medium text-gray-900 mb-6", children: "Deskripsi Proyek" }), _jsxs("div", { class: "space-y-4", children: [_jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Deskripsi (Bahasa Indonesia) *" }), _jsx("textarea", { name: "description_id", rows: "4", required: true, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", placeholder: "Jelaskan proyek dalam bahasa Indonesia..." })] }), _jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Deskripsi (English) *" }), _jsx("textarea", { name: "description_en", rows: "4", required: true, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", placeholder: "Describe the project in English..." })] })] })] }), _jsxs("div", { class: "bg-white rounded-lg shadow-sm p-6", children: [_jsx("h3", { class: "text-lg font-medium text-gray-900 mb-6", children: "Pengaturan Tampilan" }), _jsxs("div", { class: "space-y-4", children: [_jsxs("div", { class: "flex items-center", children: [_jsx("input", { type: "checkbox", name: "is_featured", id: "is_featured", class: "h-4 w-4 text-mckinsey-blue focus:ring-mckinsey-blue border-gray-300 rounded" }), _jsx("label", { for: "is_featured", class: "ml-2 block text-sm text-gray-700", children: "Tampilkan sebagai featured client" })] }), _jsxs("div", { class: "flex items-center", children: [_jsx("input", { type: "checkbox", name: "is_active", id: "is_active", checked: true, class: "h-4 w-4 text-mckinsey-blue focus:ring-mckinsey-blue border-gray-300 rounded" }), _jsx("label", { for: "is_active", class: "ml-2 block text-sm text-gray-700", children: "Aktif (tampil di website)" })] }), _jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Urutan Tampil" }), _jsx("input", { type: "number", name: "sort_order", min: "0", value: "0", class: "px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent w-32", placeholder: "0" }), _jsx("p", { class: "text-sm text-gray-500 mt-1", children: "Semakin kecil angka, semakin awal tampil" })] })] })] }), _jsxs("div", { class: "flex justify-end space-x-4", children: [_jsx("a", { href: "/admin/clients", class: "mckinsey-btn-outline px-6 py-2 rounded-md text-sm font-medium", children: "Batal" }), _jsxs("button", { type: "submit", class: "mckinsey-btn px-6 py-2 rounded-md text-sm font-medium", children: [_jsx("i", { class: "fas fa-save mr-2" }), "Simpan Klien"] })] })] }) })] }), {
title: 'Tambah Klien - IndoAdvisory Admin'
});
});
// Handle client creation
clients.post('/', async (c) => {
try {
const body = await c.req.parseBody();
const { company_name, industry, project_type, project_value, completion_date, description_id, description_en, is_featured, is_active, sort_order } = body;
await c.env.DB.prepare(`INSERT INTO clients (
company_name, industry, project_type, project_value, completion_date,
description_id, description_en, is_featured, is_active, sort_order
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).bind(company_name, industry, project_type, project_value || null, completion_date || null, description_id, description_en, is_featured ? 1 : 0, is_active ? 1 : 0, parseInt(sort_order) || 0).run();
return c.redirect('/admin/clients');
}
catch (error) {
console.error('Create client error:', error);
return c.render(_jsx("div", { children: "Error creating client" }));
}
});
// Edit client form
clients.get('/:id/edit', async (c) => {
try {
const id = c.req.param('id');
const client = await c.env.DB.prepare('SELECT * FROM clients WHERE id = ?').bind(id).first();
if (!client) {
return c.notFound();
}
return c.render(_jsxs("div", { class: "min-h-screen bg-gray-50", children: [_jsx("div", { class: "bg-white shadow-sm border-b border-gray-200", children: _jsx("div", { class: "max-w-4xl mx-auto px-4 sm:px-6 lg:px-8", children: _jsxs("div", { class: "flex items-center space-x-4 h-16", children: [_jsxs("a", { href: "/admin/clients", class: "text-gray-500 hover:text-gray-700", children: [_jsx("i", { class: "fas fa-arrow-left mr-2" }), "Kembali ke Daftar Klien"] }), _jsx("div", { class: "text-gray-300", children: "\u2022" }), _jsxs("h1", { class: "text-xl font-semibold text-gray-900", children: ["Edit Klien: ", client.company_name] })] }) }) }), _jsx("div", { class: "max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8", children: _jsxs("form", { method: "POST", action: `/admin/clients/${client.id}`, class: "space-y-6", children: [_jsxs("div", { class: "bg-white rounded-lg shadow-sm p-6", children: [_jsx("h3", { class: "text-lg font-medium text-gray-900 mb-6", children: "Informasi Dasar" }), _jsxs("div", { class: "grid grid-cols-1 md:grid-cols-2 gap-6", children: [_jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Nama Perusahaan *" }), _jsx("input", { type: "text", name: "company_name", required: true, value: client.company_name, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent" })] }), _jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Industri *" }), _jsxs("select", { name: "industry", required: true, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", children: [_jsx("option", { value: "", children: "Pilih industri" }), ['Technology', 'Finance', 'Healthcare', 'Manufacturing', 'Retail', 'Energy', 'Agriculture', 'Real Estate', 'E-commerce', 'Other'].map(ind => (_jsx("option", { value: ind, selected: client.industry === ind, children: ind })))] })] })] }), _jsxs("div", { class: "grid grid-cols-1 md:grid-cols-2 gap-6 mt-6", children: [_jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Jenis Proyek *" }), _jsxs("select", { name: "project_type", required: true, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", children: [_jsx("option", { value: "", children: "Pilih jenis proyek" }), [
{ value: 'valuation', label: 'Valuasi Perusahaan' },
{ value: 'ipo', label: 'Persiapan IPO' },
{ value: 'ma', label: 'M&A Advisory' },
{ value: 'fundraising', label: 'Fundraising' },
{ value: 'restructuring', label: 'Restructuring' },
{ value: 'dd', label: 'Due Diligence' }
].map(proj => (_jsx("option", { value: proj.value, selected: client.project_type === proj.value, children: proj.label })))] })] }), _jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Nilai Proyek" }), _jsx("input", { type: "text", name: "project_value", value: client.project_value || '', class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", placeholder: "Contoh: $25M Series B, Rp 2.1T IPO" })] })] }), _jsxs("div", { class: "mt-6", children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Tanggal Penyelesaian" }), _jsx("input", { type: "date", name: "completion_date", value: client.completion_date || '', class: "px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent" })] })] }), _jsxs("div", { class: "bg-white rounded-lg shadow-sm p-6", children: [_jsx("h3", { class: "text-lg font-medium text-gray-900 mb-6", children: "Deskripsi Proyek" }), _jsxs("div", { class: "space-y-4", children: [_jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Deskripsi (Bahasa Indonesia) *" }), _jsx("textarea", { name: "description_id", rows: "4", required: true, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", placeholder: "Jelaskan proyek dalam bahasa Indonesia...", children: client.description_id })] }), _jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Deskripsi (English) *" }), _jsx("textarea", { name: "description_en", rows: "4", required: true, class: "w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent", placeholder: "Describe the project in English...", children: client.description_en })] })] })] }), _jsxs("div", { class: "bg-white rounded-lg shadow-sm p-6", children: [_jsx("h3", { class: "text-lg font-medium text-gray-900 mb-6", children: "Pengaturan Tampilan" }), _jsxs("div", { class: "space-y-4", children: [_jsxs("div", { class: "flex items-center", children: [_jsx("input", { type: "checkbox", name: "is_featured", id: "is_featured", checked: client.is_featured, class: "h-4 w-4 text-mckinsey-blue focus:ring-mckinsey-blue border-gray-300 rounded" }), _jsx("label", { for: "is_featured", class: "ml-2 block text-sm text-gray-700", children: "Tampilkan sebagai featured client" })] }), _jsxs("div", { class: "flex items-center", children: [_jsx("input", { type: "checkbox", name: "is_active", id: "is_active", checked: client.is_active, class: "h-4 w-4 text-mckinsey-blue focus:ring-mckinsey-blue border-gray-300 rounded" }), _jsx("label", { for: "is_active", class: "ml-2 block text-sm text-gray-700", children: "Aktif (tampil di website)" })] }), _jsxs("div", { children: [_jsx("label", { class: "block text-sm font-medium text-gray-700 mb-2", children: "Urutan Tampil" }), _jsx("input", { type: "number", name: "sort_order", min: "0", value: client.sort_order, class: "px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-mckinsey-blue focus:border-transparent w-32" }), _jsx("p", { class: "text-sm text-gray-500 mt-1", children: "Semakin kecil angka, semakin awal tampil" })] })] })] }), _jsxs("div", { class: "flex justify-end space-x-4", children: [_jsx("a", { href: "/admin/clients", class: "mckinsey-btn-outline px-6 py-2 rounded-md text-sm font-medium", children: "Batal" }), _jsxs("button", { type: "submit", class: "mckinsey-btn px-6 py-2 rounded-md text-sm font-medium", children: [_jsx("i", { class: "fas fa-save mr-2" }), "Simpan Perubahan"] })] })] }) })] }), {
title: `Edit ${client.company_name} - IndoAdvisory Admin`
});
}
catch (error) {
console.error('Edit client error:', error);
return c.notFound();
}
});
// Handle client update
clients.post('/:id', async (c) => {
try {
const id = c.req.param('id');
const body = await c.req.parseBody();
const { company_name, industry, project_type, project_value, completion_date, description_id, description_en, is_featured, is_active, sort_order } = body;
await c.env.DB.prepare(`UPDATE clients SET
company_name = ?, industry = ?, project_type = ?, project_value = ?,
completion_date = ?, description_id = ?, description_en = ?,
is_featured = ?, is_active = ?, sort_order = ?, updated_at = datetime('now')
WHERE id = ?`).bind(company_name, industry, project_type, project_value || null, completion_date || null, description_id, description_en, is_featured ? 1 : 0, is_active ? 1 : 0, parseInt(sort_order) || 0, id).run();
return c.redirect('/admin/clients');
}
catch (error) {
console.error('Update client error:', error);
return c.render(_jsx("div", { children: "Error updating client" }));
}
});
// Handle client deletion
clients.delete('/:id', async (c) => {
try {
const id = c.req.param('id');
await c.env.DB.prepare('DELETE FROM clients WHERE id = ?').bind(id).run();
return c.json({ success: true });
}
catch (error) {
console.error('Delete client error:', error);
return c.json({ success: false }, 500);
}
});
export default clients;