2021-10-17 21:01:14 +02:00
|
|
|
<template>
|
|
|
|
<div id="user-preferences-edition">
|
|
|
|
<div class="profile-form form-box">
|
|
|
|
<ErrorMessage :message="errorMessages" v-if="errorMessages" />
|
|
|
|
<form @submit.prevent="updateProfile">
|
|
|
|
<label class="form-items">
|
2021-10-20 17:38:25 +02:00
|
|
|
{{ $t('user.PROFILE.LANGUAGE') }}
|
2021-10-17 21:01:14 +02:00
|
|
|
<select id="language" v-model="userForm.language" :disabled="loading">
|
|
|
|
<option
|
|
|
|
v-for="lang in availableLanguages"
|
|
|
|
:value="lang.value"
|
|
|
|
:key="lang.value"
|
|
|
|
>
|
|
|
|
{{ lang.label }}
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</label>
|
|
|
|
<label class="form-items" for="timezone">
|
2021-10-20 17:38:25 +02:00
|
|
|
{{ $t('user.PROFILE.TIMEZONE') }}
|
2021-10-17 21:01:14 +02:00
|
|
|
<input
|
|
|
|
id="timezone"
|
|
|
|
v-model="userForm.timezone"
|
|
|
|
:disabled="loading"
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
<label class="form-items">
|
2021-10-20 17:38:25 +02:00
|
|
|
{{ $t('user.PROFILE.FIRST_DAY_OF_WEEK') }}
|
2021-10-17 21:01:14 +02:00
|
|
|
<select id="weekm" v-model="userForm.weekm" :disabled="loading">
|
|
|
|
<option
|
|
|
|
v-for="start in weekStart"
|
|
|
|
:value="start.value"
|
|
|
|
:key="start.value"
|
|
|
|
>
|
2021-10-20 17:38:25 +02:00
|
|
|
{{ $t(`user.PROFILE.${start.label}`) }}
|
2021-10-17 21:01:14 +02:00
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</label>
|
|
|
|
<div class="form-buttons">
|
|
|
|
<button class="confirm" type="submit">
|
2021-10-20 17:38:25 +02:00
|
|
|
{{ $t('buttons.SUBMIT') }}
|
2021-10-17 21:01:14 +02:00
|
|
|
</button>
|
2021-10-23 20:04:38 +02:00
|
|
|
<button
|
|
|
|
class="cancel"
|
|
|
|
@click.prevent="$router.push('/profile/preferences')"
|
|
|
|
>
|
2021-10-20 17:38:25 +02:00
|
|
|
{{ $t('buttons.CANCEL') }}
|
2021-10-17 21:01:14 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import {
|
|
|
|
ComputedRef,
|
|
|
|
PropType,
|
|
|
|
computed,
|
|
|
|
defineComponent,
|
|
|
|
reactive,
|
|
|
|
onMounted,
|
|
|
|
} from 'vue'
|
|
|
|
|
|
|
|
import { ROOT_STORE, USER_STORE } from '@/store/constants'
|
2021-10-30 12:01:55 +02:00
|
|
|
import { IUserProfile, IUserPreferencesPayload } from '@/types/user'
|
2021-10-17 21:01:14 +02:00
|
|
|
import { useStore } from '@/use/useStore'
|
2021-10-31 19:48:49 +01:00
|
|
|
import { availableLanguages } from '@/utils/locales'
|
2021-10-17 21:01:14 +02:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'UserPreferencesEdition',
|
|
|
|
props: {
|
|
|
|
user: {
|
2021-10-30 12:01:55 +02:00
|
|
|
type: Object as PropType<IUserProfile>,
|
2021-10-17 21:01:14 +02:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setup(props) {
|
|
|
|
const store = useStore()
|
|
|
|
const userForm: IUserPreferencesPayload = reactive({
|
|
|
|
language: '',
|
|
|
|
timezone: 'Europe/Paris',
|
|
|
|
weekm: false,
|
|
|
|
})
|
|
|
|
const weekStart = [
|
|
|
|
{
|
|
|
|
label: 'MONDAY',
|
|
|
|
value: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'SUNDAY',
|
|
|
|
value: false,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
const loading = computed(
|
|
|
|
() => store.getters[USER_STORE.GETTERS.USER_LOADING]
|
|
|
|
)
|
|
|
|
const errorMessages: ComputedRef<string | string[] | null> = computed(
|
|
|
|
() => store.getters[ROOT_STORE.GETTERS.ERROR_MESSAGES]
|
|
|
|
)
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
if (props.user) {
|
|
|
|
updateUserForm(props.user)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-10-30 12:01:55 +02:00
|
|
|
function updateUserForm(user: IUserProfile) {
|
2021-10-17 21:01:14 +02:00
|
|
|
userForm.language = user.language ? user.language : 'en'
|
|
|
|
userForm.timezone = user.timezone ? user.timezone : 'Europe/Paris'
|
|
|
|
userForm.weekm = user.weekm ? user.weekm : false
|
|
|
|
}
|
|
|
|
function updateProfile() {
|
|
|
|
store.dispatch(USER_STORE.ACTIONS.UPDATE_USER_PREFERENCES, userForm)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
availableLanguages,
|
|
|
|
errorMessages,
|
|
|
|
loading,
|
|
|
|
userForm,
|
|
|
|
weekStart,
|
|
|
|
updateProfile,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
</script>
|