Refactor notification view to disable push column when push is not

currently possible

Closes #821

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-09-07 17:45:21 +02:00
parent 3564b69db8
commit d36f1d4b5e
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
2 changed files with 60 additions and 43 deletions

View File

@ -29,9 +29,11 @@ export interface IUserSettings {
location?: IUserPreferredLocation; location?: IUserPreferredLocation;
} }
export type IActivitySettingMethod = "email" | "push";
export interface IActivitySetting { export interface IActivitySetting {
key: string; key: string;
method: string; method: IActivitySettingMethod;
enabled: boolean; enabled: boolean;
} }

View File

@ -66,14 +66,14 @@
<th v-for="(method, key) in notificationMethods" :key="key"> <th v-for="(method, key) in notificationMethods" :key="key">
{{ method }} {{ method }}
</th> </th>
<th></th> <th>{{ $t("Description") }}</th>
</tr> </tr>
<tr v-for="subType in notificationType.subtypes" :key="subType.id"> <tr v-for="subType in notificationType.subtypes" :key="subType.id">
<td v-for="(method, key) in notificationMethods" :key="key"> <td v-for="(method, key) in notificationMethods" :key="key">
<b-checkbox <b-checkbox
:value="notificationValues[subType.id][key]" :value="notificationValues[subType.id][key].enabled"
@input="(e) => updateNotificationValue(subType.id, key, e)" @input="(e) => updateNotificationValue(subType.id, key, e)"
:disabled="notificationValues[subType.id].disabled" :disabled="notificationValues[subType.id][key].disabled"
/> />
</td> </td>
<td> <td>
@ -291,7 +291,7 @@ import {
USER_NOTIFICATIONS, USER_NOTIFICATIONS,
UPDATE_ACTIVITY_SETTING, UPDATE_ACTIVITY_SETTING,
} from "../../graphql/user"; } from "../../graphql/user";
import { IUser } from "../../types/current-user.model"; import { IActivitySettingMethod, IUser } from "../../types/current-user.model";
import RouteName from "../../router/name"; import RouteName from "../../router/name";
import { IFeedToken } from "@/types/feedtoken.model"; import { IFeedToken } from "@/types/feedtoken.model";
import { CREATE_FEED_TOKEN, DELETE_FEED_TOKEN } from "@/graphql/feed_tokens"; import { CREATE_FEED_TOKEN, DELETE_FEED_TOKEN } from "@/graphql/feed_tokens";
@ -367,70 +367,68 @@ export default class Notifications extends Vue {
defaultNotificationValues = { defaultNotificationValues = {
participation_event_updated: { participation_event_updated: {
email: true, email: { enabled: true, disabled: true },
push: true, push: { enabled: true, disabled: true },
disabled: true,
}, },
participation_event_comment: { participation_event_comment: {
email: true, email: { enabled: true, disabled: false },
push: true, push: { enabled: true, disabled: false },
}, },
event_new_pending_participation: { event_new_pending_participation: {
email: true, email: { enabled: true, disabled: false },
push: true, push: { enabled: true, disabled: false },
}, },
event_new_participation: { event_new_participation: {
email: false, email: { enabled: false, disabled: false },
push: false, push: { enabled: false, disabled: false },
}, },
event_created: { event_created: {
email: false, email: { enabled: false, disabled: false },
push: false, push: { enabled: false, disabled: false },
}, },
event_updated: { event_updated: {
email: false, email: { enabled: false, disabled: false },
push: false, push: { enabled: false, disabled: false },
}, },
discussion_updated: { discussion_updated: {
email: false, email: { enabled: false, disabled: false },
push: false, push: { enabled: false, disabled: false },
}, },
post_published: { post_published: {
email: false, email: { enabled: false, disabled: false },
push: false, push: { enabled: false, disabled: false },
}, },
post_updated: { post_updated: {
email: false, email: { enabled: false, disabled: false },
push: false, push: { enabled: false, disabled: false },
}, },
resource_updated: { resource_updated: {
email: false, email: { enabled: false, disabled: false },
push: false, push: { enabled: false, disabled: false },
}, },
member_request: { member_request: {
email: true, email: { enabled: true, disabled: false },
push: true, push: { enabled: true, disabled: false },
}, },
member_updated: { member_updated: {
email: false, email: { enabled: false, disabled: false },
push: false, push: { enabled: false, disabled: false },
}, },
user_email_password_updated: { user_email_password_updated: {
email: true, email: { enabled: true, disabled: true },
push: false, push: { enabled: false, disabled: true },
disabled: true,
}, },
event_comment_mention: { event_comment_mention: {
email: true, email: { enabled: true, disabled: false },
push: true, push: { enabled: true, disabled: false },
}, },
discussion_mention: { discussion_mention: {
email: true, email: { enabled: true, disabled: false },
push: false, push: { enabled: false, disabled: false },
}, },
event_new_comment: { event_new_comment: {
email: true, email: { enabled: true, disabled: false },
push: false, push: { enabled: false, disabled: false },
}, },
}; };
@ -542,17 +540,34 @@ export default class Notifications extends Vue {
}, },
]; ];
get userNotificationValues(): Record<string, Record<string, boolean>> { get userNotificationValues(): Record<
string,
Record<IActivitySettingMethod, { enabled: boolean; disabled: boolean }>
> {
return this.loggedUser.activitySettings.reduce((acc, activitySetting) => { return this.loggedUser.activitySettings.reduce((acc, activitySetting) => {
acc[activitySetting.key] = acc[activitySetting.key] || {}; acc[activitySetting.key] = acc[activitySetting.key] || {};
acc[activitySetting.key][activitySetting.method] = acc[activitySetting.key][activitySetting.method] =
acc[activitySetting.key][activitySetting.method] || {};
acc[activitySetting.key][activitySetting.method].enabled =
activitySetting.enabled; activitySetting.enabled;
return acc; return acc;
}, {} as Record<string, Record<string, boolean>>); }, {} as Record<string, Record<IActivitySettingMethod, { enabled: boolean; disabled: boolean }>>);
} }
get notificationValues(): Record<string, Record<string, boolean>> { get notificationValues(): Record<
return merge(this.defaultNotificationValues, this.userNotificationValues); string,
Record<IActivitySettingMethod, { enabled: boolean; disabled: boolean }>
> {
const values = merge(
this.defaultNotificationValues,
this.userNotificationValues
);
for (const value in values) {
if (!this.canShowWebPush) {
values[value].push.disabled = true;
}
}
return values;
} }
async mounted(): Promise<void> { async mounted(): Promise<void> {