|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref, watch } from 'vue' |
| 3 | +import { useMailStore } from '@/stores/mail' |
| 4 | +import { mailApi } from '@/api/mail' |
| 5 | +
|
| 6 | +const store = useMailStore() |
| 7 | +
|
| 8 | +const displayName = ref('') |
| 9 | +const loading = ref(false) |
| 10 | +const saving = ref(false) |
| 11 | +const error = ref('') |
| 12 | +const success = ref('') |
| 13 | +
|
| 14 | +async function load(address: string) { |
| 15 | + loading.value = true |
| 16 | + error.value = '' |
| 17 | + try { |
| 18 | + const res = await mailApi.getMailboxPreferences(address) |
| 19 | + displayName.value = res.data.display_name || '' |
| 20 | + } catch { |
| 21 | + error.value = 'Failed to load profile.' |
| 22 | + } finally { |
| 23 | + loading.value = false |
| 24 | + } |
| 25 | +} |
| 26 | +
|
| 27 | +watch(() => store.currentMailbox, (addr) => { if (addr) load(addr) }, { immediate: true }) |
| 28 | +
|
| 29 | +async function save() { |
| 30 | + if (!store.currentMailbox) return |
| 31 | + saving.value = true |
| 32 | + error.value = '' |
| 33 | + success.value = '' |
| 34 | + try { |
| 35 | + await mailApi.updateMailboxPreferences(store.currentMailbox, { display_name: displayName.value }) |
| 36 | + const mb = store.mailboxes.find(m => m.address === store.currentMailbox) |
| 37 | + if (mb) mb.display_name = displayName.value |
| 38 | + success.value = 'Display name updated.' |
| 39 | + } catch { |
| 40 | + error.value = 'Failed to save.' |
| 41 | + } finally { |
| 42 | + saving.value = false |
| 43 | + } |
| 44 | +} |
| 45 | +</script> |
| 46 | + |
| 47 | +<template> |
| 48 | + <div class="space-y-6"> |
| 49 | + <div> |
| 50 | + <h2 class="text-base font-semibold">Profile</h2> |
| 51 | + <p class="text-sm text-muted-foreground mt-1">Your display name appears in the From field of emails you send.</p> |
| 52 | + </div> |
| 53 | + |
| 54 | + <div v-if="!store.currentMailbox" class="text-sm text-muted-foreground">No mailbox selected.</div> |
| 55 | + |
| 56 | + <template v-else> |
| 57 | + <div v-if="loading" class="text-sm text-muted-foreground">Loading…</div> |
| 58 | + |
| 59 | + <template v-else> |
| 60 | + <div class="rounded-lg border p-4 space-y-4"> |
| 61 | + <div class="space-y-1.5"> |
| 62 | + <label class="text-sm font-medium">Email address</label> |
| 63 | + <p class="text-sm font-mono text-muted-foreground">{{ store.currentMailbox }}</p> |
| 64 | + </div> |
| 65 | + |
| 66 | + <div class="space-y-1.5"> |
| 67 | + <label class="text-sm font-medium" for="display-name-input">Display name</label> |
| 68 | + <input |
| 69 | + id="display-name-input" |
| 70 | + v-model="displayName" |
| 71 | + type="text" |
| 72 | + placeholder="Your Name" |
| 73 | + maxlength="100" |
| 74 | + class="w-full rounded-md border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring" |
| 75 | + @keydown.enter="save" |
| 76 | + /> |
| 77 | + <p class="text-xs text-muted-foreground">Sent as: {{ displayName ? `${displayName} <${store.currentMailbox}>` : store.currentMailbox }}</p> |
| 78 | + </div> |
| 79 | + |
| 80 | + <p v-if="error" class="text-xs text-destructive">{{ error }}</p> |
| 81 | + <p v-if="success" class="text-xs text-green-600 dark:text-green-400">{{ success }}</p> |
| 82 | + |
| 83 | + <button |
| 84 | + :disabled="saving" |
| 85 | + class="inline-flex items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50" |
| 86 | + @click="save" |
| 87 | + >{{ saving ? 'Saving…' : 'Save' }}</button> |
| 88 | + </div> |
| 89 | + </template> |
| 90 | + </template> |
| 91 | + </div> |
| 92 | +</template> |
| 93 | + |
| 94 | +<style scoped> |
| 95 | +.dark input { |
| 96 | + background-color: hsl(var(--muted)) !important; |
| 97 | + color: hsl(var(--foreground)); |
| 98 | +} |
| 99 | +.dark input::placeholder { |
| 100 | + color: hsl(var(--muted-foreground)); opacity: 1; |
| 101 | +} |
| 102 | +</style> |
0 commit comments