2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-04-21 22:51:48 +00:00
|
|
|
<form data-testid="update-profile-form" @submit.prevent="update">
|
2022-04-15 14:24:30 +00:00
|
|
|
<div class="form-row">
|
2022-07-22 16:15:30 +00:00
|
|
|
<label>
|
|
|
|
Current Password
|
|
|
|
<input
|
|
|
|
v-model="profile.current_password"
|
|
|
|
v-koel-focus
|
|
|
|
name="current_password"
|
|
|
|
placeholder="Required to update your profile"
|
|
|
|
required
|
|
|
|
type="password"
|
2024-01-09 15:38:12 +00:00
|
|
|
data-testid="currentPassword"
|
2022-07-22 16:15:30 +00:00
|
|
|
>
|
|
|
|
</label>
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-row">
|
2022-07-22 16:15:30 +00:00
|
|
|
<label>
|
|
|
|
Name
|
2024-01-09 15:38:12 +00:00
|
|
|
<input id="inputProfileName" v-model="profile.name" name="name" required type="text" data-testid="name">
|
2022-07-22 16:15:30 +00:00
|
|
|
</label>
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-row">
|
2022-07-22 16:15:30 +00:00
|
|
|
<label>
|
|
|
|
Email Address
|
2024-01-09 15:38:12 +00:00
|
|
|
<input id="inputProfileEmail" v-model="profile.email" name="email" required type="email" data-testid="email">
|
2022-07-22 16:15:30 +00:00
|
|
|
</label>
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
|
|
|
|
2022-07-22 16:15:30 +00:00
|
|
|
<div class="form-row">
|
|
|
|
<label>
|
|
|
|
New Password
|
2023-08-20 22:35:58 +00:00
|
|
|
<PasswordField
|
2022-04-15 14:24:30 +00:00
|
|
|
v-model="profile.new_password"
|
2022-04-21 22:51:48 +00:00
|
|
|
autocomplete="new-password"
|
2024-03-12 05:47:59 +00:00
|
|
|
data-testid="newPassword"
|
|
|
|
minlength="10"
|
|
|
|
placeholder="Leave empty to keep current password"
|
2023-08-20 22:35:58 +00:00
|
|
|
/>
|
2022-07-22 16:15:30 +00:00
|
|
|
<span class="password-rules help">
|
2022-12-02 16:17:37 +00:00
|
|
|
Min. 10 characters. Should be a mix of characters, numbers, and symbols.
|
|
|
|
</span>
|
2022-07-22 16:15:30 +00:00
|
|
|
</label>
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-row">
|
2022-04-21 22:51:48 +00:00
|
|
|
<Btn class="btn-submit" type="submit">Save</Btn>
|
2024-02-28 04:37:27 +00:00
|
|
|
<span v-if="isDemo" class="demo-notice">
|
2022-04-15 14:24:30 +00:00
|
|
|
Changes will not be saved in the demo version.
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2022-07-07 18:05:46 +00:00
|
|
|
import { onMounted, ref } from 'vue'
|
2024-01-18 11:13:05 +00:00
|
|
|
import { userStore } from '@/stores'
|
|
|
|
import { authService, UpdateCurrentProfileData } from '@/services'
|
2024-02-28 04:37:27 +00:00
|
|
|
import { logger, parseValidationError } from '@/utils'
|
2022-11-18 17:45:38 +00:00
|
|
|
import { useDialogBox, useMessageToaster } from '@/composables'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
import Btn from '@/components/ui/Btn.vue'
|
2023-08-20 22:35:58 +00:00
|
|
|
import PasswordField from '@/components/ui/PasswordField.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-11-18 17:45:38 +00:00
|
|
|
const { toastSuccess } = useMessageToaster()
|
|
|
|
const { showErrorDialog } = useDialogBox()
|
2022-04-15 17:00:08 +00:00
|
|
|
const profile = ref<UpdateCurrentProfileData>({} as unknown as UpdateCurrentProfileData)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-02-28 04:37:27 +00:00
|
|
|
const isDemo = window.IS_DEMO
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
onMounted(() => {
|
|
|
|
profile.value = {
|
|
|
|
name: userStore.current.name,
|
|
|
|
email: userStore.current.email,
|
|
|
|
current_password: null
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
})
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
|
|
const update = async () => {
|
|
|
|
if (!profile.value) {
|
|
|
|
throw Error()
|
|
|
|
}
|
|
|
|
|
2024-02-28 04:37:27 +00:00
|
|
|
if (isDemo) {
|
2022-11-18 17:45:38 +00:00
|
|
|
toastSuccess('Profile updated.')
|
2022-04-29 20:15:10 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
try {
|
2024-01-18 11:13:05 +00:00
|
|
|
await authService.updateProfile(Object.assign({}, profile.value))
|
2022-04-15 17:00:08 +00:00
|
|
|
profile.value.current_password = null
|
|
|
|
delete profile.value.new_password
|
2022-11-18 17:45:38 +00:00
|
|
|
toastSuccess('Profile updated.')
|
|
|
|
} catch (error: any) {
|
|
|
|
const msg = error.response.status === 422 ? parseValidationError(error.response.data)[0] : 'Unknown error.'
|
|
|
|
showErrorDialog(msg, 'Error')
|
|
|
|
logger.log(error)
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2023-08-20 22:35:58 +00:00
|
|
|
form {
|
|
|
|
width: 33%;
|
|
|
|
|
|
|
|
input {
|
|
|
|
width: 100%;
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.password-rules {
|
2022-07-22 16:15:30 +00:00
|
|
|
display: block;
|
2022-04-15 14:24:30 +00:00
|
|
|
margin-top: .75rem;
|
|
|
|
}
|
|
|
|
|
2022-04-29 20:15:10 +00:00
|
|
|
.demo-notice {
|
|
|
|
font-size: .95rem;
|
|
|
|
opacity: .7;
|
|
|
|
margin-left: 5px;
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
@media only screen and (max-width: 667px) {
|
2022-04-15 14:24:30 +00:00
|
|
|
input {
|
|
|
|
&[type="text"], &[type="email"], &[type="password"] {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|