Skip to content

Commit d575efd

Browse files
committed
fix(web): improve phone settings and API authentication
Confirm phone deletion and display backend validation errors below phone fields. Initialize the shared API key header when loading the current user. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3a586f29-42a9-436f-8ec3-e84b097c8a3b
1 parent 3ee244d commit d575efd

2 files changed

Lines changed: 62 additions & 3 deletions

File tree

‎web/app/pages/settings/index.vue‎

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ async function deleteDiscord(id: string) {
446446
// ---------------------------------------------------------------------------
447447
const updatingPhone = ref(false)
448448
const showPhoneEdit = ref(false)
449+
const showPhoneDelete = ref(false)
449450
const activePhone = ref<EntitiesPhone | null>(null)
450451
451452
function showEditPhone(phoneId: string) {
@@ -458,24 +459,29 @@ function showEditPhone(phoneId: string) {
458459
459460
async function updatePhone() {
460461
if (!activePhone.value) return
462+
resetErrors()
461463
updatingPhone.value = true
462464
try {
463465
await phonesStore.updatePhone(activePhone.value)
464466
showPhoneEdit.value = false
465467
activePhone.value = null
468+
} catch (error: unknown) {
469+
errorMessages.value = parseErrors(error)
466470
} finally {
467471
updatingPhone.value = false
468472
}
469473
}
470474
471-
async function deletePhone(phoneId: string) {
475+
async function deletePhone() {
476+
if (!activePhone.value || updatingPhone.value) return
472477
updatingPhone.value = true
473478
try {
474-
await phonesStore.deletePhone(phoneId)
479+
await phonesStore.deletePhone(activePhone.value.id)
475480
notificationsStore.addNotification({
476481
message: 'Phone deleted successfully',
477482
type: 'success',
478483
})
484+
showPhoneDelete.value = false
479485
showPhoneEdit.value = false
480486
activePhone.value = null
481487
} catch (error: unknown) {
@@ -1623,41 +1629,49 @@ onMounted(async () => {
16231629
disabled
16241630
label="ID"
16251631
:model-value="activePhone.id"
1632+
:error-messages="errorMessages.get('id')"
16261633
/>
16271634
<VTextField
16281635
variant="outlined"
16291636
disabled
16301637
density="compact"
16311638
label="Phone Number"
16321639
:model-value="activePhone.phone_number"
1640+
:error-messages="errorMessages.get('phone_number')"
16331641
/>
16341642
<VTextField
16351643
variant="outlined"
16361644
disabled
16371645
density="compact"
16381646
label="SIM"
16391647
:model-value="activePhone.sim"
1648+
:error-messages="errorMessages.get('sim')"
16401649
/>
16411650
<VTextarea
16421651
variant="outlined"
16431652
disabled
16441653
density="compact"
16451654
label="FCM Token"
16461655
:model-value="activePhone.fcm_token"
1656+
:error-messages="errorMessages.get('fcm_token')"
16471657
/>
16481658
<VTextField
16491659
v-model="activePhone.message_expiration_seconds"
16501660
variant="outlined"
16511661
type="number"
16521662
density="compact"
16531663
label="Message Expiration (seconds)"
1664+
:error-messages="
1665+
errorMessages.get('message_expiration_seconds')
1666+
"
16541667
/>
16551668
<VTextField
16561669
v-model="activePhone.messages_per_minute"
16571670
variant="outlined"
16581671
type="number"
16591672
density="compact"
16601673
label="Messages Per Minute"
1674+
:error-messages="errorMessages.get('messages_per_minute')"
16611675
/>
16621676
<VTextField
16631677
v-model="activePhone.max_send_attempts"
@@ -1666,6 +1680,7 @@ onMounted(async () => {
16661680
density="compact"
16671681
placeholder="How many retries when sending an SMS"
16681682
label="Max Send Attempts"
1683+
:error-messages="errorMessages.get('max_send_attempts')"
16691684
min="1"
16701685
max="5"
16711686
:rules="[
@@ -1681,6 +1696,9 @@ onMounted(async () => {
16811696
density="compact"
16821697
clearable
16831698
label="Send Schedule"
1699+
:error-messages="
1700+
errorMessages.get('message_send_schedule_id')
1701+
"
16841702
:items="sendSchedules"
16851703
item-title="name"
16861704
item-value="id"
@@ -1693,6 +1711,7 @@ onMounted(async () => {
16931711
density="compact"
16941712
class="mt-6"
16951713
label="Missed Call AutoReply"
1714+
:error-messages="errorMessages.get('missed_call_auto_reply')"
16961715
persistent-placeholder
16971716
persistent-hint
16981717
placeholder="We are currently closed at the moment, please send us a text message from 09:00 to 17:00"
@@ -1704,6 +1723,9 @@ onMounted(async () => {
17041723
color="primary"
17051724
density="compact"
17061725
label="Archive New Outgoing Message Threads"
1726+
:error-messages="
1727+
errorMessages.get('archive_new_outgoing_message_threads')
1728+
"
17071729
hint="Automatically archive new conversations started by an outgoing message. Conversations started by an incoming message are not affected."
17081730
persistent-hint
17091731
/>
@@ -1713,6 +1735,7 @@ onMounted(async () => {
17131735
color="primary"
17141736
density="compact"
17151737
label="Unarchive Threads Automatically"
1738+
:error-messages="errorMessages.get('unarchive_thread')"
17161739
hint="When a new message is received on an archived conversation, change it back to the unarchived state"
17171740
persistent-hint
17181741
/>
@@ -1730,7 +1753,7 @@ onMounted(async () => {
17301753
color="error"
17311754
variant="text"
17321755
:disabled="updatingPhone"
1733-
@click="deletePhone(activePhone?.id ?? '')"
1756+
@click="showPhoneDelete = true"
17341757
>
17351758
<VIcon v-if="lgAndUp" start :icon="mdiDelete" />
17361759
Delete
@@ -1739,6 +1762,41 @@ onMounted(async () => {
17391762
</VCard>
17401763
</VDialog>
17411764

1765+
<VDialog
1766+
v-model="showPhoneDelete"
1767+
max-width="500"
1768+
opacity="0.9"
1769+
:persistent="updatingPhone"
1770+
>
1771+
<VCard>
1772+
<VCardTitle>Delete Phone</VCardTitle>
1773+
<VCardText class="text-medium-emphasis">
1774+
Are you sure you want to delete the phone
1775+
<b>{{ activePhone?.phone_number }}</b
1776+
>? This action cannot be undone.
1777+
</VCardText>
1778+
<VCardActions>
1779+
<VBtn
1780+
variant="flat"
1781+
color="error"
1782+
:loading="updatingPhone"
1783+
:disabled="updatingPhone"
1784+
@click="deletePhone"
1785+
>
1786+
Delete
1787+
</VBtn>
1788+
<VSpacer />
1789+
<VBtn
1790+
variant="text"
1791+
:disabled="updatingPhone"
1792+
@click="showPhoneDelete = false"
1793+
>
1794+
Cancel
1795+
</VBtn>
1796+
</VCardActions>
1797+
</VCard>
1798+
</VDialog>
1799+
17421800
<!-- Send Schedule Edit Dialog -->
17431801
<VDialog v-model="showScheduleEdit" max-width="800px" opacity="0.9">
17441802
<VCard>

‎web/app/stores/auth.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const useAuthStore = defineStore('auth', () => {
4949

5050
async function loadUser() {
5151
const response = await apiFetch<{ data: EntitiesUser }>('/v1/users/me')
52+
setApiKey(response.data.api_key)
5253
user.value = response.data
5354
}
5455

0 commit comments

Comments
 (0)