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;
}
export type IActivitySettingMethod = "email" | "push";
export interface IActivitySetting {
key: string;
method: string;
method: IActivitySettingMethod;
enabled: boolean;
}

View File

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