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>
|
2021-11-10 12:03:32 +01:00
|
|
|
<label class="form-items">
|
2021-10-20 17:38:25 +02:00
|
|
|
{{ $t('user.PROFILE.TIMEZONE') }}
|
2021-11-10 12:03:32 +01:00
|
|
|
<TimezoneDropdown
|
|
|
|
:input="userForm.timezone"
|
2021-10-17 21:01:14 +02:00
|
|
|
:disabled="loading"
|
2021-11-10 12:03:32 +01:00
|
|
|
@updateTimezone="updateTZ"
|
2021-10-17 21:01:14 +02:00
|
|
|
/>
|
|
|
|
</label>
|
2022-07-23 08:53:10 +02:00
|
|
|
<div class="form-items form-checkboxes">
|
|
|
|
<span class="checkboxes-label">
|
|
|
|
{{ $t('user.PROFILE.FIRST_DAY_OF_WEEK') }}
|
|
|
|
</span>
|
|
|
|
<div class="checkboxes">
|
|
|
|
<label v-for="start in weekStart" :key="start.label">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
:id="start.label"
|
|
|
|
:name="start.label"
|
|
|
|
:checked="start.value === userForm.weekm"
|
|
|
|
:disabled="loading"
|
|
|
|
@input="updateWeekM(start.value)"
|
|
|
|
/>
|
|
|
|
<span class="checkbox-label">
|
|
|
|
{{ $t(`user.PROFILE.${start.label}`) }}
|
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-items form-checkboxes">
|
|
|
|
<span class="checkboxes-label">
|
|
|
|
{{ $t('user.PROFILE.UNITS.LABEL') }}
|
|
|
|
</span>
|
|
|
|
<div class="checkboxes">
|
|
|
|
<label v-for="unit in imperialUnits" :key="unit.label">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
:id="unit.label"
|
|
|
|
:name="unit.label"
|
|
|
|
:checked="unit.value === userForm.imperial_units"
|
|
|
|
:disabled="loading"
|
|
|
|
@input="updateImperialUnit(unit.value)"
|
|
|
|
/>
|
|
|
|
<span class="checkbox-label">
|
|
|
|
{{ $t(`user.PROFILE.UNITS.${unit.label}`) }}
|
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-items form-checkboxes">
|
|
|
|
<span class="checkboxes-label">
|
|
|
|
{{ $t('user.PROFILE.ASCENT_DATA') }}
|
|
|
|
</span>
|
|
|
|
<div class="checkboxes">
|
|
|
|
<label v-for="status in ascentData" :key="status.label">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
:id="status.label"
|
|
|
|
:name="status.label"
|
|
|
|
:checked="status.value === userForm.display_ascent"
|
|
|
|
:disabled="loading"
|
|
|
|
@input="updateAscentDisplay(status.value)"
|
|
|
|
/>
|
|
|
|
<span class="checkbox-label">
|
|
|
|
{{ $t(`common.${status.label}`) }}
|
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-17 21:01:14 +02:00
|
|
|
<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>
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
<script setup lang="ts">
|
2022-03-13 08:48:37 +01:00
|
|
|
import { ComputedRef, computed, reactive, onMounted, onUnmounted } from 'vue'
|
2021-10-17 21:01:14 +02:00
|
|
|
|
2021-11-10 12:03:32 +01:00
|
|
|
import TimezoneDropdown from '@/components/User/ProfileEdition/TimezoneDropdown.vue'
|
2021-11-03 10:41:53 +01:00
|
|
|
import { AUTH_USER_STORE, ROOT_STORE } from '@/store/constants'
|
2022-07-23 08:17:37 +02:00
|
|
|
import { IUserPreferencesPayload, IAuthUserProfile } 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
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
interface Props {
|
2022-07-23 08:17:37 +02:00
|
|
|
user: IAuthUserProfile
|
2021-11-10 21:19:27 +01:00
|
|
|
}
|
|
|
|
const props = defineProps<Props>()
|
2021-10-17 21:01:14 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
const store = useStore()
|
2021-10-17 21:01:14 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
const userForm: IUserPreferencesPayload = reactive({
|
2022-07-23 08:17:37 +02:00
|
|
|
display_ascent: true,
|
2021-11-13 20:04:47 +01:00
|
|
|
imperial_units: false,
|
2021-11-10 21:19:27 +01:00
|
|
|
language: '',
|
|
|
|
timezone: 'Europe/Paris',
|
|
|
|
weekm: false,
|
|
|
|
})
|
|
|
|
const weekStart = [
|
|
|
|
{
|
|
|
|
label: 'SUNDAY',
|
|
|
|
value: false,
|
|
|
|
},
|
2021-11-13 20:04:47 +01:00
|
|
|
{
|
2022-07-23 08:53:10 +02:00
|
|
|
label: 'MONDAY',
|
2021-11-13 20:04:47 +01:00
|
|
|
value: true,
|
|
|
|
},
|
2022-07-23 08:53:10 +02:00
|
|
|
]
|
|
|
|
const imperialUnits = [
|
2021-11-13 20:04:47 +01:00
|
|
|
{
|
|
|
|
label: 'METRIC',
|
|
|
|
value: false,
|
|
|
|
},
|
2022-07-23 08:53:10 +02:00
|
|
|
{
|
|
|
|
label: 'IMPERIAL',
|
|
|
|
value: true,
|
|
|
|
},
|
2021-11-13 20:04:47 +01:00
|
|
|
]
|
2022-07-23 08:17:37 +02:00
|
|
|
const ascentData = [
|
|
|
|
{
|
|
|
|
label: 'DISPLAYED',
|
|
|
|
value: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'HIDDEN',
|
|
|
|
value: false,
|
|
|
|
},
|
|
|
|
]
|
2021-11-10 21:19:27 +01:00
|
|
|
const loading = computed(
|
|
|
|
() => store.getters[AUTH_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-17 21:01:14 +02:00
|
|
|
})
|
2021-11-10 21:19:27 +01:00
|
|
|
|
2022-07-23 08:17:37 +02:00
|
|
|
function updateUserForm(user: IAuthUserProfile) {
|
|
|
|
userForm.display_ascent = user.display_ascent
|
2021-11-13 20:04:47 +01:00
|
|
|
userForm.imperial_units = user.imperial_units ? user.imperial_units : false
|
2021-11-10 21:19:27 +01: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(AUTH_USER_STORE.ACTIONS.UPDATE_USER_PREFERENCES, userForm)
|
|
|
|
}
|
|
|
|
function updateTZ(value: string) {
|
|
|
|
userForm.timezone = value
|
|
|
|
}
|
2022-07-23 08:53:10 +02:00
|
|
|
function updateAscentDisplay(value: boolean) {
|
|
|
|
userForm.display_ascent = value
|
|
|
|
}
|
|
|
|
function updateImperialUnit(value: boolean) {
|
|
|
|
userForm.imperial_units = value
|
|
|
|
}
|
|
|
|
function updateWeekM(value: boolean) {
|
|
|
|
userForm.weekm = value
|
|
|
|
}
|
2022-03-13 08:48:37 +01:00
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
store.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
|
|
|
})
|
2021-10-17 21:01:14 +02:00
|
|
|
</script>
|
2022-07-23 08:53:10 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import '~@/scss/vars.scss';
|
|
|
|
#user-preferences-edition {
|
|
|
|
.form-items {
|
|
|
|
padding-top: $default-padding * 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
.form-checkboxes {
|
|
|
|
.checkboxes-label {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
.checkboxes {
|
|
|
|
display: flex;
|
|
|
|
gap: $default-padding;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
.checkbox-label {
|
|
|
|
padding-left: $default-padding * 0.5;
|
|
|
|
}
|
|
|
|
label {
|
|
|
|
font-weight: normal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|