feat(go-crm): industrial terminal-core UI redesign
Complete visual overhaul of the go-crm web interface: - New shared layout system (internal/templates/ui.go) with dark zinc industrial theme, JetBrains Mono typography, grid/noise textures - Redesigned all pages: Dashboard, Login/Signup, Clients, Customers, Services, Scheduling, Payments, Questions, Answers, Leads, Review Queue, Report, Keyword Mapping - Tailwind CSS via CDN with custom color palette (amber/emerald/rose/sky) - HTMX-powered interactions with CSS swap animations - Status pills, KPI cards, data tables, empty states, inline forms - Mobile-responsive sidebar with collapsible navigation - All existing tests updated and passing - Zero new build dependencies — works with existing go run/air workflow
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go-crm/internal/db"
|
||||
"go-crm/internal/templates"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
@@ -53,36 +55,116 @@ func (a *App) ListSchedules(w http.ResponseWriter, r *http.Request) {
|
||||
customerNames := make(map[int64]string)
|
||||
serviceNames := make(map[int64]string)
|
||||
for _, c := range clients {
|
||||
clientOptions += `<option value="` + strconv.FormatInt(c.ClientID, 10) + `">` + c.Name + `</option>`
|
||||
clientOptions += fmt.Sprintf(`<option value="%d">%s</option>`, c.ClientID, htmlEscape(c.Name))
|
||||
clientNames[c.ClientID] = c.Name
|
||||
}
|
||||
for _, cu := range customers {
|
||||
customerOptions += `<option value="` + strconv.FormatInt(cu.CustomerID, 10) + `">` + cu.Name + `</option>`
|
||||
customerOptions += fmt.Sprintf(`<option value="%d">%s</option>`, cu.CustomerID, htmlEscape(cu.Name))
|
||||
customerNames[cu.CustomerID] = cu.Name
|
||||
}
|
||||
for _, s := range services {
|
||||
serviceOptions += `<option value="` + strconv.FormatInt(s.ServiceID, 10) + `">` + s.Name + `</option>`
|
||||
serviceOptions += fmt.Sprintf(`<option value="%d">%s</option>`, s.ServiceID, htmlEscape(s.Name))
|
||||
serviceNames[s.ServiceID] = s.Name
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Write([]byte(`<!DOCTYPE html><html><head><script src="https://unpkg.com/htmx.org@1.9.10"></script><style>.edit-row{display:none}</style></head><body><h1>Scheduling</h1><button class="btn" onclick="document.getElementById('scheduleForm').style.display='block'">Add Schedule</button><div id="scheduleForm" style="display:none; margin-top:1rem;"><form hx-post="/scheduling" hx-target="#scheduleList"><select name="client_id" required><option value="">Select Client</option>` + clientOptions + `</select><select name="customer_id" required><option value="">Select Customer</option>` + customerOptions + `</select><select name="service_id" required><option value="">Select Service</option>` + serviceOptions + `</select><input type="date" name="plan_date"><input type="time" name="time"><select name="status"><option value="pending">Pending</option><option value="confirmed">Confirmed</option><option value="cancelled">Cancelled</option></select><button type="submit">Add</button></form></div><table><thead><tr><th>Client</th><th>Customer</th><th>Service</th><th>Date</th><th>Hour</th><th>Status</th><th>Actions</th></tr></thead><tbody id="scheduleList">`))
|
||||
for _, s := range schedules {
|
||||
clientName := clientNames[s.ClientID]
|
||||
if clientName == "" {
|
||||
clientName = strconv.FormatInt(s.ClientID, 10)
|
||||
buf := templates.BufRender()
|
||||
actions := `<button type="button" onclick="document.getElementById('scheduleForm').classList.toggle('hidden')" class="btn-primary"><svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg> Add Schedule</button>`
|
||||
fmt.Fprint(buf, templates.PageHeader("Scheduling", "Appointments and calendar", actions))
|
||||
|
||||
fmt.Fprintf(buf, `
|
||||
<div id="scheduleForm" class="hidden mb-6 animate-slide-up">
|
||||
<div class="card-industrial p-5">
|
||||
<h3 class="text-sm font-semibold text-zinc-200 mb-4">New Appointment</h3>
|
||||
<form hx-post="/scheduling" hx-target="#scheduleList" hx-swap="innerHTML" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<select name="client_id" required class="input-industrial"><option value="">Select Client</option>%s</select>
|
||||
<select name="customer_id" required class="input-industrial"><option value="">Select Customer</option>%s</select>
|
||||
<select name="service_id" required class="input-industrial"><option value="">Select Service</option>%s</select>
|
||||
<input type="date" name="plan_date" class="input-industrial">
|
||||
<input type="time" name="time" class="input-industrial">
|
||||
<select name="status" class="input-industrial"><option value="pending">Pending</option><option value="confirmed">Confirmed</option><option value="cancelled">Cancelled</option></select>
|
||||
<div class="flex items-end"><button type="submit" class="btn-primary">Save</button></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>`, clientOptions, customerOptions, serviceOptions)
|
||||
|
||||
if len(schedules) == 0 {
|
||||
fmt.Fprint(buf, templates.EmptyState(`<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" 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"/>`, "No appointments scheduled yet."))
|
||||
} else {
|
||||
fmt.Fprintf(buf, `<div class="card-industrial overflow-hidden animate-slide-up stagger-1"><div class="overflow-x-auto">`)
|
||||
fmt.Fprint(buf, templates.TableStart([]string{"Client", "Customer", "Service", "Date", "Time", "Status", "Actions"}))
|
||||
for _, s := range schedules {
|
||||
clientName := clientNames[s.ClientID]
|
||||
if clientName == "" {
|
||||
clientName = strconv.FormatInt(s.ClientID, 10)
|
||||
}
|
||||
customerName := customerNames[s.CustomerID]
|
||||
if customerName == "" {
|
||||
customerName = strconv.FormatInt(s.CustomerID, 10)
|
||||
}
|
||||
serviceName := serviceNames[s.ServiceID]
|
||||
if serviceName == "" {
|
||||
serviceName = strconv.FormatInt(s.ServiceID, 10)
|
||||
}
|
||||
statusPill := statusPillForSchedule(s.Status)
|
||||
fmt.Fprintf(buf, `<tr>
|
||||
<td class="text-zinc-300 text-sm">%s</td>
|
||||
<td class="text-zinc-300 text-sm">%s</td>
|
||||
<td class="text-zinc-400 text-xs">%s</td>
|
||||
<td class="font-mono text-xs text-zinc-300">%s</td>
|
||||
<td class="font-mono text-xs text-zinc-300">%s</td>
|
||||
<td>%s</td>
|
||||
<td>
|
||||
<div class="flex items-center gap-2">
|
||||
<a href="/scheduling/%d" class="btn-ghost btn-sm">View</a>
|
||||
<button type="button" onclick="document.getElementById('editSched%d').classList.toggle('hidden')" class="btn-ghost btn-sm">Edit</button>
|
||||
<form hx-delete="/scheduling/%d" hx-target="closest tr" hx-swap="outerHTML" style="display:inline">
|
||||
<button type="submit" class="btn-danger btn-sm" onclick="return confirm('Delete?')">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>`, htmlEscape(clientName), htmlEscape(customerName), htmlEscape(serviceName), htmlEscape(s.PlanDate), htmlEscape(s.Time), statusPill, s.ScheduleID, s.ScheduleID, s.ScheduleID)
|
||||
}
|
||||
customerName := customerNames[s.CustomerID]
|
||||
if customerName == "" {
|
||||
customerName = strconv.FormatInt(s.CustomerID, 10)
|
||||
fmt.Fprint(buf, templates.TableEnd())
|
||||
fmt.Fprintf(buf, `</div></div>`)
|
||||
|
||||
for _, s := range schedules {
|
||||
clientName := clientNames[s.ClientID]
|
||||
customerName := customerNames[s.CustomerID]
|
||||
serviceName := serviceNames[s.ServiceID]
|
||||
fmt.Fprintf(buf, `
|
||||
<div id="editSched%d" class="hidden mt-4 animate-slide-up">
|
||||
<div class="card-industrial p-5 border-amber-400/10">
|
||||
<h3 class="text-sm font-semibold text-zinc-200 mb-3">Edit Appointment #%d</h3>
|
||||
<form hx-put="/scheduling/%d" hx-target="#scheduleList" hx-swap="innerHTML" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3">
|
||||
<select name="client_id" class="input-industrial text-xs"><option value="%d">%s</option>%s</select>
|
||||
<select name="customer_id" class="input-industrial text-xs"><option value="%d">%s</option>%s</select>
|
||||
<select name="service_id" class="input-industrial text-xs"><option value="%d">%s</option>%s</select>
|
||||
<input type="date" name="plan_date" value="%s" class="input-industrial text-xs">
|
||||
<input type="time" name="time" value="%s" class="input-industrial text-xs">
|
||||
<select name="status" class="input-industrial text-xs"><option value="%s">%s</option><option value="pending">Pending</option><option value="confirmed">Confirmed</option><option value="cancelled">Cancelled</option></select>
|
||||
<div class="flex items-end gap-2">
|
||||
<button type="submit" class="btn-primary btn-sm">Save</button>
|
||||
<button type="button" onclick="document.getElementById('editSched%d').classList.add('hidden')" class="btn-ghost btn-sm">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>`, s.ScheduleID, s.ScheduleID, s.ScheduleID, s.ClientID, htmlEscape(clientName), clientOptions, s.CustomerID, htmlEscape(customerName), customerOptions, s.ServiceID, htmlEscape(serviceName), serviceOptions, htmlEscape(s.PlanDate), htmlEscape(s.Time), s.Status, s.Status, s.ScheduleID)
|
||||
}
|
||||
serviceName := serviceNames[s.ServiceID]
|
||||
if serviceName == "" {
|
||||
serviceName = strconv.FormatInt(s.ServiceID, 10)
|
||||
}
|
||||
w.Write([]byte(`<tr><td>` + clientName + `</td><td>` + customerName + `</td><td>` + serviceName + `</td><td>` + s.PlanDate + `</td><td>` + s.Time + `</td><td>` + s.Status + `</td><td><a href="/scheduling/` + strconv.FormatInt(s.ScheduleID, 10) + `">View</a><button type="button" onclick="document.getElementById('editSched` + strconv.FormatInt(s.ScheduleID, 10) + `').style.display='table-row'">Edit</button><form method="DELETE" style="display:inline" hx-delete="/scheduling/` + strconv.FormatInt(s.ScheduleID, 10) + `" hx-target="closest tr"><button type="submit">Delete</button></form></td></tr><tr id="editSched` + strconv.FormatInt(s.ScheduleID, 10) + `" class="edit-row" style="display:none"><td colspan="7"><form hx-put="/scheduling/` + strconv.FormatInt(s.ScheduleID, 10) + `" hx-target="#scheduleList" hx-swap="innerHTML"><select name="client_id"><option value="` + strconv.FormatInt(s.ClientID, 10) + `">` + clientName + `</option>` + clientOptions + `</select><select name="customer_id"><option value="` + strconv.FormatInt(s.CustomerID, 10) + `">` + customerName + `</option>` + customerOptions + `</select><select name="service_id"><option value="` + strconv.FormatInt(s.ServiceID, 10) + `">` + serviceName + `</option>` + serviceOptions + `</select><input type="date" name="plan_date" value="` + s.PlanDate + `"><input type="time" name="time" value="` + s.Time + `"><select name="status"><option value="` + s.Status + `">` + s.Status + `</option><option value="pending">Pending</option><option value="confirmed">Confirmed</option><option value="cancelled">Cancelled</option></select><button type="submit">Save</button></form></td></tr>`))
|
||||
}
|
||||
w.Write([]byte(`</tbody></table></body></html>`))
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
templates.WritePage(w, buf, "Scheduling", "scheduling")
|
||||
}
|
||||
|
||||
func statusPillForSchedule(status string) string {
|
||||
switch status {
|
||||
case "confirmed":
|
||||
return `<span class="pill pill-emerald">confirmed</span>`
|
||||
case "cancelled":
|
||||
return `<span class="pill pill-rose">cancelled</span>`
|
||||
default:
|
||||
return `<span class="pill pill-amber">pending</span>`
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) CreateSchedule(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -127,8 +209,35 @@ func (a *App) ViewSchedule(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
buf := templates.BufRender()
|
||||
fmt.Fprint(buf, templates.PageHeader("Appointment", "Schedule details"))
|
||||
statusPill := statusPillForSchedule(sch.Status)
|
||||
fmt.Fprintf(buf, `
|
||||
<div class="max-w-lg animate-slide-up">
|
||||
<div class="card-industrial p-6">
|
||||
<div class="flex items-center gap-2 mb-6">%s</div>
|
||||
<div class="space-y-3">
|
||||
<div class="flex justify-between py-3 border-b border-white/[0.04]">
|
||||
<span class="text-xs font-mono uppercase text-zinc-500">Date</span>
|
||||
<span class="text-sm font-mono text-zinc-300">%s</span>
|
||||
</div>
|
||||
<div class="flex justify-between py-3 border-b border-white/[0.04]">
|
||||
<span class="text-xs font-mono uppercase text-zinc-500">Time</span>
|
||||
<span class="text-sm font-mono text-zinc-300">%s</span>
|
||||
</div>
|
||||
<div class="flex justify-between py-3">
|
||||
<span class="text-xs font-mono uppercase text-zinc-500">Client / Customer / Service</span>
|
||||
<span class="text-sm text-zinc-300 text-right font-mono">%d / %d / %d</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-6">
|
||||
<a href="/scheduling" class="btn-ghost btn-sm">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>`, statusPill, htmlEscape(sch.PlanDate), htmlEscape(sch.Time), sch.ClientID, sch.CustomerID, sch.ServiceID)
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Write([]byte(`<!DOCTYPE html><body><h1>Schedule</h1><p>Client ID: ` + strconv.FormatInt(sch.ClientID, 10) + `</p><p>Customer ID: ` + strconv.FormatInt(sch.CustomerID, 10) + `</p><p>Service ID: ` + strconv.FormatInt(sch.ServiceID, 10) + `</p><p>Date: ` + sch.PlanDate + `</p><p>Time: ` + sch.Time + `</p><p>Status: ` + sch.Status + `</p><a href="/scheduling">Back</a></body></html>`))
|
||||
templates.WritePage(w, buf, "Appointment", "scheduling")
|
||||
}
|
||||
|
||||
func (a *App) UpdateSchedule(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -160,7 +269,7 @@ func (a *App) DeleteSchedule(w http.ResponseWriter, r *http.Request) {
|
||||
a.DB.Exec("DELETE FROM scheduling WHERE schedule_id = ?", id)
|
||||
}
|
||||
|
||||
// --- package-level shims kept for existing tests ---
|
||||
// --- package-level shims ---
|
||||
|
||||
func ListSchedules(w http.ResponseWriter, r *http.Request) {
|
||||
(&App{DB: DB, WAConnector: WAConnector}).ListSchedules(w, r)
|
||||
|
||||
Reference in New Issue
Block a user