Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/stores/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type Account = Models.User<
organization?: string;
console: Models.Preferences;
notificationPrefs: Record<string, NotificationPrefItem>;
deploymentFailedEmailAlert: boolean;
} & Record<string, string>
>;

Expand Down
38 changes: 38 additions & 0 deletions src/routes/(console)/account/alerts/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script>
import { CardGrid } from "$lib/components";
import { InputChoice } from "$lib/elements/forms";
import { Container } from "$lib/layout";
import { sdk } from '$lib/stores/sdk';
import { user } from '$lib/stores/user';
import { Layout } from "@appwrite.io/pink-svelte";
let deploymentFailedEmailAlert = $user.prefs.deploymentFailedEmailAlert ?? true;
function toggleDeploymentFailedEmailAlert() {
deploymentFailedEmailAlert = !deploymentFailedEmailAlert;
const newPrefs = {
...$user.prefs,
deploymentFailedEmailAlert: deploymentFailedEmailAlert
};
sdk.forConsole.account.updatePrefs({ prefs: newPrefs });
}
Comment on lines +11 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add error handling and await the API call.

The updatePrefs call has several issues:

  1. No error handling—if the API call fails, the local state will be out of sync with the server.
  2. The promise is not awaited, so you can't provide user feedback or handle failures.
  3. No loading or success indicators for the user.

Consider this approach:

+    import { addNotification } from '$lib/stores/notifications';
+
     let deploymentFailedEmailAlert = $user.prefs.deploymentFailedEmailAlert ?? true;
+    let isUpdating = false;

-    function toggleDeploymentFailedEmailAlert() {
+    async function toggleDeploymentFailedEmailAlert() {
+      if (isUpdating) return;
+      
+      const previousValue = deploymentFailedEmailAlert;
       deploymentFailedEmailAlert = !deploymentFailedEmailAlert;
+      
       const newPrefs = {
         ...$user.prefs,
         deploymentFailedEmailAlert: deploymentFailedEmailAlert
       };
-      sdk.forConsole.account.updatePrefs({ prefs: newPrefs });
+      
+      isUpdating = true;
+      try {
+        await sdk.forConsole.account.updatePrefs({ prefs: newPrefs });
+        addNotification({
+          type: 'success',
+          message: 'Email alert preference updated'
+        });
+      } catch (error) {
+        deploymentFailedEmailAlert = previousValue; // Revert on failure
+        addNotification({
+          type: 'error',
+          message: error.message
+        });
+      } finally {
+        isUpdating = false;
+      }
     }

Committable suggestion skipped: line range outside the PR's diff.

</script>
<Container>
<CardGrid>
<svelte:fragment slot="title">Email Alerts</svelte:fragment>
Toggle email preferences to receive notifications when certain events occur.
<svelte:fragment slot="aside">
<Layout.Stack gap="xl">
<InputChoice
on:change={toggleDeploymentFailedEmailAlert}
type="switchbox"
id="mfa"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix incorrect ID attribute.

The id attribute is set to "mfa" but this input is for deployment failure alerts, not multi-factor authentication.

Apply this diff:

-            id="mfa"
+            id="deploymentFailedEmailAlert"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
id="mfa"
id="deploymentFailedEmailAlert"
🤖 Prompt for AI Agents
In src/routes/(console)/account/alerts/+page.svelte around line 32, the input's
id is incorrectly set to "mfa" for a deployment failure alert; change the id to
a descriptive value such as "deployment-failure" (or "deploy-failure-alert") and
update any matching label for= attributes or JS selectors that reference "mfa"
to use the new id so markup and bindings remain consistent.

label="Deployment Failed"
value={deploymentFailedEmailAlert} />
</Layout.Stack>
</svelte:fragment>
</CardGrid>
</Container>
Comment on lines +1 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix code formatting.

The pipeline indicates Prettier formatting issues. Run prettier --write to fix.

🧰 Tools
🪛 GitHub Actions: Tests

[warning] 1-1: Code style issues found by Prettier. Run 'prettier --write' to fix.

🤖 Prompt for AI Agents
In src/routes/(console)/account/alerts/+page.svelte around lines 1 to 38 the
file fails Prettier formatting; run `prettier --write
src/routes/(console)/account/alerts/+page.svelte` (or `prettier --write .` at
repo root) to automatically fix formatting, then review the changed diff and
commit the formatted file so the pipeline passes.

5 changes: 5 additions & 0 deletions src/routes/(console)/account/header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
title: 'Organizations',
event: 'organizations',
hasChildren: true
},
{
href: `${path}/alerts`,
title: 'Alerts',
event: 'alerts',
}
Comment on lines +36 to 41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix code formatting.

The pipeline indicates Prettier formatting issues. Run prettier --write to fix.

🤖 Prompt for AI Agents
In src/routes/(console)/account/header.svelte around lines 36 to 41 the code is
misformatted according to Prettier; run the project's Prettier formatter (e.g.,
run `prettier --write src/routes/(console)/account/header.svelte` or simply
`prettier --write .`), or apply the repo's editor formatting rules to reformat
this block so spacing, commas and indentation match the project's Prettier
configuration, then stage and commit the formatted file.

];
Expand Down
Loading