Add setting for sending reminder emails (#343)

Fix the "Import your data button" in the settings

Add setting for sending reminder emails

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/343
Co-Authored-By: konrad <konrad@kola-entertainments.de>
Co-Committed-By: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad 2020-12-19 00:12:30 +00:00
parent d104f15deb
commit 4a02a1b496
6 changed files with 56 additions and 47 deletions

View file

@ -1,10 +0,0 @@
import AbstractModel from './abstractModel'
export default class UserNameModel extends AbstractModel {
defaults() {
return {
name: '',
}
}
}

View file

@ -0,0 +1,11 @@
import AbstractModel from './abstractModel'
export default class UserSettingsModel extends AbstractModel {
defaults() {
return {
name: '',
emailRemindersEnabled: true,
}
}
}

View file

@ -1,10 +0,0 @@
import AbstractService from './abstractService'
export default class UserNameService extends AbstractService {
constructor() {
super({
update: '/user/settings/name',
})
}
}

View file

@ -0,0 +1,10 @@
import AbstractService from './abstractService'
export default class UserSettingsService extends AbstractService {
constructor() {
super({
update: '/user/settings/general',
})
}
}

View file

@ -16,8 +16,9 @@ export default {
state.info = info state.info = info
state.avatarUrl = info.getAvatarUrl() state.avatarUrl = info.getAvatarUrl()
}, },
setUserName(state, name) { setUserSettings(state, {name, emailRemindersEnabled}) {
state.info.name = name state.info.name = name
state.info.emailRemindersEnabled = emailRemindersEnabled
}, },
authenticated(state, authenticated) { authenticated(state, authenticated) {
state.authenticated = authenticated state.authenticated = authenticated

View file

@ -106,11 +106,11 @@
</div> </div>
</div> </div>
<!-- Name --> <!-- General -->
<div class="card update-name"> <div class="card update-name">
<header class="card-header"> <header class="card-header">
<p class="card-header-title"> <p class="card-header-title">
Update your name General Settings
</p> </p>
</header> </header>
<div class="card-content"> <div class="card-content">
@ -119,17 +119,23 @@
<label class="label" for="newName">Name</label> <label class="label" for="newName">Name</label>
<div class="control"> <div class="control">
<input <input
@keyup.enter="updateName" @keyup.enter="updateSettings"
class="input" class="input"
id="newName" id="newName"
placeholder="The new name" placeholder="The new name"
type="text" type="text"
v-model="name"/> v-model="settings.name"/>
</div> </div>
</div> </div>
<div class="field">
<label class="checkbox">
<input type="checkbox" v-model="settings.emailRemindersEnabled"/>
Send me Reminders for tasks via Email
</label>
</div>
<div class="bigbuttons"> <div class="bigbuttons">
<button :class="{ 'is-loading': userNameService.loading}" @click="updateName()" <button :class="{ 'is-loading': userSettingsService.loading}" @click="updateSettings()"
class="button is-primary is-fullwidth"> class="button is-primary is-fullwidth">
Save Save
</button> </button>
@ -217,7 +223,7 @@
<div class="card-content"> <div class="card-content">
<router-link <router-link
:to="{name: 'migrate.start'}" :to="{name: 'migrate.start'}"
class="button is-primary is-right noshadow is-outlined" class="button is-primary"
v-if="migratorsEnabled" v-if="migratorsEnabled"
> >
Import your data into Vikunja Import your data into Vikunja
@ -266,8 +272,8 @@ import EmailUpdateService from '../../services/emailUpdate'
import EmailUpdateModel from '../../models/emailUpdate' import EmailUpdateModel from '../../models/emailUpdate'
import TotpModel from '../../models/totp' import TotpModel from '../../models/totp'
import TotpService from '../../services/totp' import TotpService from '../../services/totp'
import UserNameService from '../../services/userName' import UserSettingsService from '../../services/userSettings'
import UserNameModel from '../../models/userName' import UserSettingsModel from '../../models/userSettings'
import {mapState} from 'vuex' import {mapState} from 'vuex'
@ -295,8 +301,8 @@ export default {
caldavUrl: '', caldavUrl: '',
name: '', settings: UserSettingsModel,
userNameService: UserNameService, userSettingsService: UserSettingsService,
} }
}, },
components: { components: {
@ -312,8 +318,11 @@ export default {
this.totpService = new TotpService() this.totpService = new TotpService()
this.totp = new TotpModel() this.totp = new TotpModel()
this.userNameService = new UserNameService() this.userSettingsService = new UserSettingsService()
this.name = this.$store.state.auth.info.name this.settings = new UserSettingsModel({
name: this.$store.state.auth.info.name,
emailRemindersEnabled: this.$store.state.auth.info.emailRemindersEnabled ?? false,
})
this.totpStatus() this.totpStatus()
this.buildCaldavUrl() this.buildCaldavUrl()
@ -399,12 +408,10 @@ export default {
}) })
.catch(e => this.error(e, this)) .catch(e => this.error(e, this))
}, },
updateName() { updateSettings() {
const name = new UserNameModel({name: this.name}) this.userSettingsService.update(this.settings)
this.userNameService.update(name)
.then(() => { .then(() => {
this.$store.commit('auth/setUserName', this.name) this.$store.commit('auth/setUserSettings', this.settings)
this.success({message: 'The name was successfully changed.'}, this) this.success({message: 'The name was successfully changed.'}, this)
}) })
.catch(e => this.error(e, this)) .catch(e => this.error(e, this))