Files
habitica/website/client/components/header/notifications/groupTaskApproval.vue
Sabe Jones 76ae41875d Group Plans quick wins (#11107)
* WIP(groups): quickish wins

* WIP(groups): two quick wins
1. Don't show task creation button if user is not leader or manager
2. Don't require JS confirm() for approving tasks

* fix(group-plans): allow delete from options button

* fix(group-plans): update tasksOrder when task deleted

* fix(group-tasks): dismiss notification when user takes action

* refactor(tasks): DRY out create button styling

* fix(group-tasks): sync after claiming/unclaiming
2019-04-15 10:48:27 -05:00

76 lines
2.2 KiB
Vue

<template lang="pug">
base-notification(
:can-remove="canRemove",
:has-icon="false",
:notification="notification",
@click="action",
ref="taskApprovalNotification",
)
div(slot="content")
div(v-html="notification.data.message")
.notifications-buttons
.btn.btn-small.btn-success(@click.stop="approve()") {{ $t('approve') }}
.btn.btn-small.btn-warning(@click.stop="needsWork()") {{ $t('needsWork') }}
</template>
<script>
import BaseNotification from './base';
import { mapState } from 'client/libs/store';
export default {
props: ['notification', 'canRemove'],
components: {
BaseNotification,
},
computed: {
...mapState({user: 'user.data'}),
// Check that the notification has all the necessary data (old ones are missing some fields)
notificationHasData () {
return Boolean(this.notification.data.groupTaskId && this.notification.data.userId);
},
},
methods: {
action () {
const groupId = this.notification.data.group.id;
this.$router.push({ name: 'groupPlanDetailTaskInformation', params: { groupId }});
},
async approve () {
// Redirect users to the group tasks page if the notification doesn't have data
if (!this.notificationHasData) {
this.$router.push({ name: 'groupPlanDetailTaskInformation', params: {
groupId: this.notification.data.groupId,
}});
return;
}
await this.$store.dispatch('tasks:approve', {
taskId: this.notification.data.groupTaskId,
userId: this.notification.data.userId,
});
this.$refs.taskApprovalNotification.remove();
},
async needsWork () {
// Redirect users to the group tasks page if the notification doesn't have data
if (!this.notificationHasData) {
this.$router.push({ name: 'groupPlanDetailTaskInformation', params: {
groupId: this.notification.data.groupId,
}});
return;
}
if (!confirm(this.$t('confirmNeedsWork'))) return;
await this.$store.dispatch('tasks:needsWork', {
taskId: this.notification.data.groupTaskId,
userId: this.notification.data.userId,
});
this.$refs.taskApprovalNotification.remove();
},
},
};
</script>