Skip to content

Commit 4872fb3

Browse files
feat: read-only
1 parent 9bf421f commit 4872fb3

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

app/pages/settings.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@
174174
<ToggleSwitch
175175
v-if="notificationPreferences[notificationTypeId]"
176176
v-model="notificationPreferences[notificationTypeId].enabled"
177-
:disabled="!!auth.impersonation"
177+
:disabled="!!auth.impersonation || notificationType.readOnly"
178178
@update:model-value="(enabled) => enabled === false && (notificationPreferences[notificationTypeId]!.emailEnabled = false)"
179179
/>
180180
<label class="cursor-text text-nowrap">App</label>
181181
</div>
182-
<div v-if="notificationType.allowEmail" class="flex items-center gap-2">
182+
<div v-if="notificationType.sendEmail" class="flex items-center gap-2">
183183
<ToggleSwitch
184184
v-if="notificationPreferences[notificationTypeId]"
185185
v-model="notificationPreferences[notificationTypeId].emailEnabled"
@@ -401,9 +401,9 @@
401401
// This builds an object to send to the backend.
402402
function normalizeNotificationPreferences () {
403403
return Object.fromEntries(Object.keys(notificationTypes.value).sort().map((type) => {
404-
const normalizedPreference: NotificationPreference = { enabled: notificationPreferences.value[type]?.enabled !== false };
404+
const normalizedPreference: NotificationPreference = { enabled: notificationTypes.value[type]!.readOnly || notificationPreferences.value[type]?.enabled !== false };
405405
406-
if (notificationTypes.value[type]!.allowEmail) {
406+
if (notificationTypes.value[type]!.sendEmail) {
407407
normalizedPreference.emailEnabled = notificationPreferences.value[type]?.emailEnabled !== false;
408408
}
409409
@@ -444,15 +444,15 @@
444444
// Here we are fulfilling default values.
445445
const preferences = Object.fromEntries(Object.keys(notificationTypes.value)
446446
.map(type => [ type, {
447-
enabled: !allDisabled,
448-
emailEnabled: notificationTypes.value[type]?.allowEmail ? !(allDisabled || allEmailDisabled) : undefined,
447+
enabled: notificationTypes.value[type]!.readOnly || !allDisabled,
448+
emailEnabled: notificationTypes.value[type]?.sendEmail ? !(allDisabled || allEmailDisabled) : undefined,
449449
parameter: notificationTypes.value[type]?.hasParameter ? String(notificationTypes.value[type]?.defaultParameter) : undefined,
450450
}])) as Record<string, { enabled: boolean; emailEnabled?: boolean; parameter?: string }>;
451451
452452
// Here we are overriding default values with user preferences.
453453
for (const [ type, preference ] of Object.entries(userPreferences).filter(([ type ]) => type in preferences)) {
454454
if (typeof preference?.enabled === 'boolean') {
455-
preferences[type]!.enabled = preference.enabled;
455+
preferences[type]!.enabled = notificationTypes.value[type]!.readOnly || preference.enabled;
456456
preferences[type]!.emailEnabled = preference.enabled;
457457
}
458458

app/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ declare global {
148148
};
149149

150150
type NotificationTypes = Record<string, {
151-
allowEmail: boolean;
151+
readOnly: boolean;
152+
sendEmail: boolean;
152153
hasParameter: boolean;
153154
defaultParameter?: number;
154155
description: string;

0 commit comments

Comments
 (0)