Add timezone selector to Admin settings with full-stack support

- Add `timezone` column to User model (VARCHAR 64, default UTC) with
  idempotent startup migration
- Expose and persist timezone via PATCH /api/users/me
- Fix TimerEvent.occurred_at serialization to include UTC offset marker
  (+00:00) so JavaScript correctly parses timestamps as UTC
- Add frontend utility (src/utils/time.js) with timezone-aware
  formatTime, getHHMM, getDateInTZ, tzDateTimeToUTC helpers and a
  curated IANA timezone list
- Add Settings section to Admin page with timezone dropdown; saves to
  both the API and localStorage for the unauthenticated TV view
- Update Activity Log to display and edit times in the user's timezone
- Update TV dashboard clock to respect the saved timezone
- Update README: features, setup steps, usage table, WebSocket events

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
derekcandClaude Sonnet 4.6 committed 2026-03-01 14:16:37 -08:00
1 parent fef03ec538
commit 823260cdd8
11 files changed
+230 -24

No files matched your search

+66
View File
@@ -250,6 +250,31 @@
</div>
</div>
</section>
<!-- Settings section -->
<section class="section">
<div class="section-header">
<h2>Settings</h2>
</div>
<div class="settings-card">
<div class="settings-row">
<div class="settings-label">
<div class="settings-title">Timezone</div>
<div class="settings-hint">Times in the activity log will display in this timezone.</div>
</div>
<div class="settings-control">
<select v-model="selectedTimezone" class="tz-select">
<option v-for="tz in TIMEZONES" :key="tz.value" :value="tz.value">
{{ tz.label }}
</option>
</select>
<button class="btn-primary btn-sm" @click="saveTimezone" :disabled="tzSaved">
{{ tzSaved ? 'Saved!' : 'Save' }}
</button>
</div>
</div>
</div>
</section>
</main>
</div>
</template>
@@ -257,12 +282,27 @@
<script setup>
import { ref, onMounted } from 'vue'
import { useChildrenStore } from '@/stores/children'
import { useAuthStore } from '@/stores/auth'
import api from '@/composables/useApi'
import NavBar from '@/components/NavBar.vue'
import { TIMEZONES } from '@/utils/time'
const childrenStore = useChildrenStore()
const authStore = useAuthStore()
const subjects = ref([])
// Settings — Timezone
const selectedTimezone = ref(authStore.timezone)
const tzSaved = ref(false)
async function saveTimezone() {
await api.patch('/api/users/me', { timezone: selectedTimezone.value })
await authStore.fetchMe()
localStorage.setItem('tz', selectedTimezone.value)
tzSaved.value = true
setTimeout(() => { tzSaved.value = false }, 2000)
}
// Children
const showChildForm = ref(false)
const newChild = ref({ name: '', color: '#4F46E5' })
@@ -471,6 +511,7 @@ async function saveDayHours(template, which, value) {
onMounted(async () => {
await childrenStore.fetchChildren()
await Promise.all([loadSubjects(), loadTemplates()])
selectedTimezone.value = authStore.timezone
})
</script>
@@ -664,6 +705,31 @@ h2 { font-size: 1.1rem; color: #94a3b8; text-transform: uppercase; letter-spacin
.empty-small { color: #64748b; font-size: 0.9rem; padding: 1rem 0; }
.settings-card {
background: #1e293b;
border-radius: 1rem;
padding: 1.25rem 1.5rem;
}
.settings-row {
display: flex;
align-items: center;
gap: 1.5rem;
flex-wrap: wrap;
}
.settings-label { flex: 1; min-width: 180px; }
.settings-title { font-size: 0.95rem; font-weight: 500; margin-bottom: 0.2rem; }
.settings-hint { font-size: 0.8rem; color: #64748b; }
.settings-control { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.tz-select {
padding: 0.5rem 0.75rem;
background: #0f172a;
border: 1px solid #334155;
border-radius: 0.5rem;
color: #f1f5f9;
font-size: 0.875rem;
min-width: 220px;
}
.btn-primary {
padding: 0.5rem 1rem;
background: #4f46e5;