mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
Group plan fixes (#9437)
* Prevented title editing on personal page * Fixed claim/unlclaim from user task page * Removed task from local on delete * Immediately show unassigned bar * Add move to group tasks * Fixed group member count increase * Added upgrade when group plan is canceled
This commit is contained in:
@@ -24,6 +24,8 @@
|
|||||||
li {{ $t('gemCapExtra') }} {{group.purchased.plan.consecutive.gemCapExtra}}
|
li {{ $t('gemCapExtra') }} {{group.purchased.plan.consecutive.gemCapExtra}}
|
||||||
li {{ $t('mysticHourglasses') }} {{group.purchased.plan.consecutive.trinkets}}
|
li {{ $t('mysticHourglasses') }} {{group.purchased.plan.consecutive.trinkets}}
|
||||||
.col-12.col-md-6.offset-md-3
|
.col-12.col-md-6.offset-md-3
|
||||||
|
button.btn.btn-success(class='btn-success', v-if='group.purchased.plan.dateTerminated', @click='upgradeGroup()')
|
||||||
|
| {{ $t('upgrade') }}
|
||||||
.btn.btn-primary(v-if='!group.purchased.plan.dateTerminated && group.purchased.plan.paymentMethod === "Stripe"',
|
.btn.btn-primary(v-if='!group.purchased.plan.dateTerminated && group.purchased.plan.paymentMethod === "Stripe"',
|
||||||
@click='showStripeEdit({groupId: group.id})') {{ $t('subUpdateCard') }}
|
@click='showStripeEdit({groupId: group.id})') {{ $t('subUpdateCard') }}
|
||||||
.btn.btn-sm.btn-danger(v-if='!group.purchased.plan.dateTerminated',
|
.btn.btn-sm.btn-danger(v-if='!group.purchased.plan.dateTerminated',
|
||||||
@@ -69,6 +71,10 @@ export default {
|
|||||||
let group = await this.$store.dispatch('guilds:getGroup', {groupId: this.groupId});
|
let group = await this.$store.dispatch('guilds:getGroup', {groupId: this.groupId});
|
||||||
this.group = Object.assign({}, group);
|
this.group = Object.assign({}, group);
|
||||||
},
|
},
|
||||||
|
upgradeGroup () {
|
||||||
|
this.$store.state.upgradingGroup = this.group;
|
||||||
|
this.$router.push('/group-plans');
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
:groupId="groupId",
|
:groupId="groupId",
|
||||||
v-on:taskCreated='taskCreated',
|
v-on:taskCreated='taskCreated',
|
||||||
v-on:taskEdited='taskEdited',
|
v-on:taskEdited='taskEdited',
|
||||||
|
v-on:taskDestroyed='taskDestroyed'
|
||||||
)
|
)
|
||||||
.row
|
.row
|
||||||
task-column.col-12.col-sm-6.col-3(
|
task-column.col-12.col-sm-6.col-3(
|
||||||
@@ -380,6 +381,7 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
taskCreated (task) {
|
taskCreated (task) {
|
||||||
|
task.group.id = this.group._id;
|
||||||
this.tasksByType[task.type].push(task);
|
this.tasksByType[task.type].push(task);
|
||||||
},
|
},
|
||||||
taskEdited (task) {
|
taskEdited (task) {
|
||||||
@@ -388,6 +390,12 @@ export default {
|
|||||||
});
|
});
|
||||||
this.tasksByType[task.type].splice(index, 1, task);
|
this.tasksByType[task.type].splice(index, 1, task);
|
||||||
},
|
},
|
||||||
|
taskDestroyed (task) {
|
||||||
|
let index = findIndex(this.tasksByType[task.type], (taskItem) => {
|
||||||
|
return taskItem._id === task._id;
|
||||||
|
});
|
||||||
|
this.tasksByType[task.type].splice(index, 1);
|
||||||
|
},
|
||||||
cancelTaskModal () {
|
cancelTaskModal () {
|
||||||
this.editingTask = null;
|
this.editingTask = null;
|
||||||
this.creatingTask = null;
|
this.creatingTask = null;
|
||||||
|
|||||||
@@ -76,24 +76,36 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
claim () {
|
async claim () {
|
||||||
if (!confirm('Are you sure you want to claim this task?')) return;
|
if (!confirm('Are you sure you want to claim this task?')) return;
|
||||||
|
|
||||||
|
let taskId = this.task._id;
|
||||||
|
// If we are on the user task
|
||||||
|
if (this.task.userId) {
|
||||||
|
taskId = this.task.group.taskId;
|
||||||
|
}
|
||||||
|
|
||||||
this.$store.dispatch('tasks:assignTask', {
|
this.$store.dispatch('tasks:assignTask', {
|
||||||
taskId: this.task._id,
|
taskId,
|
||||||
userId: this.user._id,
|
userId: this.user._id,
|
||||||
});
|
});
|
||||||
this.task.group.assignedUsers.push(this.user._id);
|
this.task.group.assignedUsers.push(this.user._id);
|
||||||
// @TODO: Reload user tasks?
|
|
||||||
},
|
},
|
||||||
unassign () {
|
async unassign () {
|
||||||
if (!confirm('Are you sure you want to unclaim this task?')) return;
|
if (!confirm('Are you sure you want to unclaim this task?')) return;
|
||||||
|
|
||||||
|
let taskId = this.task._id;
|
||||||
|
// If we are on the user task
|
||||||
|
if (this.task.userId) {
|
||||||
|
taskId = this.task.group.taskId;
|
||||||
|
}
|
||||||
|
|
||||||
this.$store.dispatch('tasks:unassignTask', {
|
this.$store.dispatch('tasks:unassignTask', {
|
||||||
taskId: this.task._id,
|
taskId,
|
||||||
userId: this.user._id,
|
userId: this.user._id,
|
||||||
});
|
});
|
||||||
let index = this.task.group.assignedUsers.indexOf(this.user._id);
|
let index = this.task.group.assignedUsers.indexOf(this.user._id);
|
||||||
this.task.group.assignedUsers.splice(index, 1);
|
this.task.group.assignedUsers.splice(index, 1);
|
||||||
// @TODO: Reload user tasks?
|
|
||||||
},
|
},
|
||||||
approve () {
|
approve () {
|
||||||
if (!confirm('Are you sure you want to approve this task?')) return;
|
if (!confirm('Are you sure you want to approve this task?')) return;
|
||||||
|
|||||||
@@ -35,9 +35,9 @@
|
|||||||
h3(v-once) {{$t('theseAreYourTasks', {taskType: $t(types[type].label)})}}
|
h3(v-once) {{$t('theseAreYourTasks', {taskType: $t(types[type].label)})}}
|
||||||
.small-text {{$t(`${type}sDesc`)}}
|
.small-text {{$t(`${type}sDesc`)}}
|
||||||
.sortable-tasks(
|
.sortable-tasks(
|
||||||
ref="tasksList",
|
ref="tasksList",
|
||||||
v-sortable='activeFilters[type].label !== "scheduled"',
|
v-sortable='activeFilters[type].label !== "scheduled"',
|
||||||
@onsort='sorted',
|
@onsort='sorted',
|
||||||
data-sortableId
|
data-sortableId
|
||||||
)
|
)
|
||||||
task(
|
task(
|
||||||
@@ -441,20 +441,32 @@ export default {
|
|||||||
}),
|
}),
|
||||||
async sorted (data) {
|
async sorted (data) {
|
||||||
const filteredList = this.taskList;
|
const filteredList = this.taskList;
|
||||||
const taskIdToMove = filteredList[data.oldIndex]._id;
|
const taskToMove = filteredList[data.oldIndex];
|
||||||
|
const taskIdToMove = taskToMove._id;
|
||||||
|
let originTasks = this.tasks[`${this.type}s`];
|
||||||
|
if (this.taskListOverride) originTasks = this.taskListOverride;
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
const taskIdToReplace = filteredList[data.newIndex];
|
const taskIdToReplace = filteredList[data.newIndex];
|
||||||
const newIndexOnServer = this.tasks[`${this.type}s`].findIndex(taskId => taskId === taskIdToReplace);
|
const newIndexOnServer = originTasks.findIndex(taskId => taskId === taskIdToReplace);
|
||||||
let newOrder = await this.$store.dispatch('tasks:move', {
|
|
||||||
taskId: taskIdToMove,
|
let newOrder;
|
||||||
position: newIndexOnServer,
|
if (taskToMove.group.id) {
|
||||||
});
|
newOrder = await this.$store.dispatch('tasks:moveGroupTask', {
|
||||||
this.user.tasksOrder[`${this.type}s`] = newOrder;
|
taskId: taskIdToMove,
|
||||||
|
position: newIndexOnServer,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
newOrder = await this.$store.dispatch('tasks:move', {
|
||||||
|
taskId: taskIdToMove,
|
||||||
|
position: newIndexOnServer,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!this.taskListOverride) this.user.tasksOrder[`${this.type}s`] = newOrder;
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
const deleted = this.tasks[`${this.type}s`].splice(data.oldIndex, 1);
|
const deleted = originTasks.splice(data.oldIndex, 1);
|
||||||
this.tasks[`${this.type}s`].splice(data.newIndex, 0, deleted[0]);
|
originTasks.splice(data.newIndex, 0, deleted[0]);
|
||||||
},
|
},
|
||||||
async moveTo (task, where) { // where is 'top' or 'bottom'
|
async moveTo (task, where) { // where is 'top' or 'bottom'
|
||||||
const taskIdToMove = task._id;
|
const taskIdToMove = task._id;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
type="text", :class="[`${cssClass}-modal-input`]",
|
type="text", :class="[`${cssClass}-modal-input`]",
|
||||||
required, v-model="task.text",
|
required, v-model="task.text",
|
||||||
autofocus, spellcheck="true",
|
autofocus, spellcheck="true",
|
||||||
|
:disabled="groupAccessRequiredAndOnPersonalPage"
|
||||||
)
|
)
|
||||||
.form-group
|
.form-group
|
||||||
label(v-once) {{ $t('notes') }}
|
label(v-once) {{ $t('notes') }}
|
||||||
@@ -596,6 +597,10 @@ export default {
|
|||||||
user: 'user.data',
|
user: 'user.data',
|
||||||
dayMapping: 'constants.DAY_MAPPING',
|
dayMapping: 'constants.DAY_MAPPING',
|
||||||
}),
|
}),
|
||||||
|
groupAccessRequiredAndOnPersonalPage () {
|
||||||
|
if (!this.groupId && this.task.group.id) return true;
|
||||||
|
return false;
|
||||||
|
},
|
||||||
checklistEnabled () {
|
checklistEnabled () {
|
||||||
return ['daily', 'todo'].indexOf(this.task.type) > -1 && !this.isOriginalChallengeTask;
|
return ['daily', 'todo'].indexOf(this.task.type) > -1 && !this.isOriginalChallengeTask;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -218,3 +218,8 @@ export async function move (store, payload) {
|
|||||||
let response = await axios.post(`/api/v3/tasks/${payload.taskId}/move/to/${payload.position}`);
|
let response = await axios.post(`/api/v3/tasks/${payload.taskId}/move/to/${payload.position}`);
|
||||||
return response.data.data;
|
return response.data.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function moveGroupTask (store, payload) {
|
||||||
|
let response = await axios.post(`/api/v3/group-tasks/${payload.taskId}/move/to/${payload.position}`);
|
||||||
|
return response.data.data;
|
||||||
|
}
|
||||||
|
|||||||
@@ -567,13 +567,13 @@ api.joinGroup = {
|
|||||||
|
|
||||||
if (group.memberCount === 0) group.leader = user._id; // If new user is only member -> set as leader
|
if (group.memberCount === 0) group.leader = user._id; // If new user is only member -> set as leader
|
||||||
|
|
||||||
group.memberCount += 1;
|
|
||||||
|
|
||||||
if (group.hasNotCancelled()) {
|
if (group.hasNotCancelled()) {
|
||||||
await payments.addSubToGroupUser(user, group);
|
await payments.addSubToGroupUser(user, group);
|
||||||
await group.updateGroupPlan();
|
await group.updateGroupPlan();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group.memberCount += 1;
|
||||||
|
|
||||||
let promises = [group.save(), user.save()];
|
let promises = [group.save(), user.save()];
|
||||||
|
|
||||||
if (inviter) {
|
if (inviter) {
|
||||||
|
|||||||
Reference in New Issue
Block a user