-
Notifications
You must be signed in to change notification settings - Fork 344
/
Copy pathWorkSpaceEmailSettings.vue
185 lines (172 loc) · 4.68 KB
/
WorkSpaceEmailSettings.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<template>
<div id="email-settings">
<UButton
color="gray"
label="Email Settings"
icon="i-heroicons-envelope"
@click="showEmailSettingsModal = !showEmailSettingsModal"
/>
<modal
:show="showEmailSettingsModal"
max-width="lg"
@close="showEmailSettingsModal = false"
>
<h4 class="font-medium">
Email Settings
</h4>
<p class="mb-4 text-gray-500 text-sm">
Customize email sender - connect your SMTP server.
</p>
<UAlert
v-if="!workspace.is_pro"
icon="i-heroicons-user-group-20-solid"
class="my-4 !text-orange-500"
color="orange"
variant="subtle"
title="Pro plan required"
>
<template #description>
Please <a
href="#"
class="text-orange-500 underline"
@click.prevent="openSubscriptionModal"
>
upgrade your account
</a> to setup an email settings.
</template>
</UAlert>
<TextInput
:form="emailSettingsForm"
name="host"
:required="true"
:disabled="!workspace.is_pro"
label="Host/Server"
class="mt-2"
placeholder="smtp.example.com"
/>
<TextInput
:form="emailSettingsForm"
name="port"
:required="true"
:disabled="!workspace.is_pro"
label="Port"
placeholder="587"
/>
<TextInput
:form="emailSettingsForm"
name="username"
:required="true"
:disabled="!workspace.is_pro"
label="Username"
placeholder="Username"
/>
<TextInput
:form="emailSettingsForm"
name="password"
native-type="password"
:required="true"
:disabled="!workspace.is_pro"
label="Password"
placeholder="Password"
/>
<TextInput
:form="emailSettingsForm"
name="sender_address"
:disabled="!workspace.is_pro"
label="Sender address"
placeholder="sender@example.com"
/>
<div class="flex justify-between gap-2">
<UButton
class="mt-3 px-6"
:loading="emailSettingsLoading"
:disabled="!workspace.is_pro"
icon="i-heroicons-check"
@click="saveChanges"
>
Update
</UButton>
<UButton
class="mt-3 ml-2"
color="white"
size="sm"
:loading="emailSettingsLoading"
:disabled="!workspace.is_pro"
icon="i-heroicons-x-mark"
@click="clearEmailSettings"
>
Clear
</UButton>
</div>
</modal>
</div>
</template>
<script setup>
import {watch} from "vue"
const workspacesStore = useWorkspacesStore()
const workspace = computed(() => workspacesStore.getCurrent)
const subscriptionModalStore = useSubscriptionModalStore()
const openSubscriptionModal = () => {
showEmailSettingsModal.value = false
subscriptionModalStore.setModalContent('Upgrade to send emails using your own domain')
subscriptionModalStore.openModal()
}
const emailSettingsForm = useForm({
host: '',
port: '',
username: '',
password: '',
sender_address: ''
})
const emailSettingsLoading = ref(false)
const showEmailSettingsModal = ref(false)
onMounted(() => {
initEmailSettings()
})
watch(
() => workspace,
() => {
initEmailSettings()
},
)
const clearEmailSettings = () => {
emailSettingsForm.reset()
saveChanges()
}
const saveChanges = () => {
if (emailSettingsLoading.value) return
emailSettingsLoading.value = true
// Update the workspace Email Settings
emailSettingsForm
.put("/open/workspaces/" + workspace.value.id + "/email-settings", {
data: {
host: emailSettingsForm?.host,
port: emailSettingsForm?.port,
username: emailSettingsForm?.username,
password: emailSettingsForm?.password,
sender_address: emailSettingsForm?.sender_address,
},
})
.then((data) => {
workspacesStore.save(data)
useAlert().success("Email settings saved.")
})
.catch((error) => {
useAlert().error(
"Failed to update email settings: " + error.response.data.message,
)
})
.finally(() => {
emailSettingsLoading.value = false
})
}
const initEmailSettings = () => {
if (!workspace || !workspace.value.settings.email_settings) return
const emailSettings = workspace.value?.settings?.email_settings
emailSettingsForm.host = emailSettings?.host
emailSettingsForm.port = emailSettings?.port
emailSettingsForm.username = emailSettings?.username
emailSettingsForm.password = emailSettings?.password
emailSettingsForm.sender_address = emailSettings?.sender_address
}
</script>