Skip to content

Instantly share code, notes, and snippets.

@Noxsios
Created June 25, 2024 20:25
Show Gist options
  • Save Noxsios/47cd54b1cf3bae8b3e64e06b392bc653 to your computer and use it in GitHub Desktop.
Save Noxsios/47cd54b1cf3bae8b3e64e06b392bc653 to your computer and use it in GitHub Desktop.
--- main.go ---
type Lease struct {
AccountID string
}
type PageData struct {
Leases []Lease
AvailableAccounts []string
}
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
tpl, err := template.ParseFiles("index.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
pd := PageData{
Leases: []Lease{
{AccountID: "123"},
{AccountID: "456"},
},
AvailableAccounts: []string{"789", "101112"},
}
tpl.Execute(w, pd)
})
--- main.go ---
--- index.html ---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Subvert UI</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
body {
font-family: 'Inter', sans-serif;
background-color: #efecf3;
background-image: url("data:image/svg+xml,%3Csvg width='84' height='48' viewBox='0 0 84 48' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h12v6H0V0zm28 8h12v6H28V8zm14-8h12v6H42V0zm14 0h12v6H56V0zm0 8h12v6H56V8zM42 8h12v6H42V8zm0 16h12v6H42v-6zm14-8h12v6H56v-6zm14 0h12v6H70v-6zm0-16h12v6H70V0zM28 32h12v6H28v-6zM14 16h12v6H14v-6zM0 24h12v6H0v-6zm0 8h12v6H0v-6zm14 0h12v6H14v-6zm14 8h12v6H28v-6zm-14 0h12v6H14v-6zm28 0h12v6H42v-6zm14-8h12v6H56v-6zm0-8h12v6H56v-6zm14 8h12v6H70v-6zm0 8h12v6H70v-6zM14 24h12v6H14v-6zm14-8h12v6H28v-6zM14 8h12v6H14V8zM0 8h12v6H0V8z' fill='%239299ac' fill-opacity='0.18' fill-rule='evenodd'/%3E%3C/svg%3E");
}
</style>
<body class="bg-gray-50 flex items-center justify-center min-h-screen">
<div class="bg-white p-8 rounded-lg shadow-md max-w-md w-full">
<h1 class="text-2xl font-bold mb-6 text-gray-800">Virtual Hot Desk</h1>
<!-- Display Current User's Account Leases -->
<div id="account-leases" class="mb-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Your Account Leases</h2>
{{if .Leases}}
<table class="min-w-full bg-white">
<thead>
<tr>
<th class="py-2 px-4 border-b border-gray-200 bg-gray-50 text-left text-sm font-semibold text-gray-700">Account ID</th>
<th class="py-2 px-4 border-b border-gray-200 bg-gray-50"></th>
</tr>
</thead>
<tbody>
{{range .Leases}}
<tr>
<td class="py-2 px-4 border-b border-gray-200 text-sm text-gray-700">{{.AccountID}}</td>
<td class="py-2 px-4 border-b border-gray-200 text-sm text-right">
<form action="/leases/delete" method="POST">
<input type="hidden" name="account_id" value="{{.AccountID}}">
<button type="submit" class="text-red-600 hover:text-red-800 focus:outline-none">Delete</button>
</form>
</td>
</tr>
{{end}}
</tbody>
</table>
{{else}}
<p class="text-sm text-gray-600">You have no account leases.</p>
{{end}}
</div>
<form action="/leases" method="POST" class="space-y-4">
<!-- Account ID Dropdown -->
<div>
<label for="account_id" class="block text-sm font-medium text-gray-700">Account ID</label>
<select id="account_id" name="account_id" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
<option value="">Select an account</option>
<!-- Example Account IDs -->
{{range .AvailableAccounts}}
<option value="{{.}}">{{.}}</option>
{{end}}
</select>
</div>
<!-- Submit Button -->
<div>
<button type="submit" class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Submit</button>
</div>
</form>
</div>
</body>
</html>
--- index.html ---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment