Skip to content

Comments

save default address to db with google code ready#1355

Merged
ahmetskilinc merged 3 commits intostagingfrom
default_from_alias
Jun 20, 2025
Merged

save default address to db with google code ready#1355
ahmetskilinc merged 3 commits intostagingfrom
default_from_alias

Conversation

@ahmetskilinc
Copy link
Contributor

@ahmetskilinc ahmetskilinc commented Jun 18, 2025

Add Default Email Alias Selection in Settings

This PR adds the ability for users to select a default email alias that will be used as the "From" address when composing new emails. The selected default alias is stored in user settings and automatically applied when creating new emails.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🎨 UI/UX improvement

Areas Affected

  • User Interface/Experience
  • Data Storage/Management

Features Added

  1. Added a new defaultEmailAlias field to the user settings schema
  2. Added a dropdown selector in the General Settings page to choose a default email alias
  3. Modified the email composer to use the selected default alias when creating new emails
  4. Added appropriate translations for the new UI elements
  5. Added placeholder code (commented out) for future implementation of updating the primary alias in Gmail settings

Summary by CodeRabbit

  • New Features
    • Added the ability for users to select and manage a default email alias in general settings.
    • Introduced a dropdown menu for choosing a default email alias, which will be used as the default 'From' address when composing new emails.
  • Improvements
    • The email composer now automatically uses the selected default email alias when starting a new message.
  • Localization
    • Added new English localization strings for the default email alias feature and related notifications.
  • Chores
    • Removed unnecessary debug logging from email alias retrieval.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 18, 2025

Walkthrough

This update introduces a "default email alias" setting to user settings, updates the email composer to prioritize this alias when composing new emails, synchronizes form state with settings changes, and adds relevant localization strings. It also updates the user settings schema and removes debug logs from the server's alias-fetching logic.

Changes

File(s) Change Summary
apps/mail/app/(routes)/settings/general/page.tsx Added "defaultEmailAlias" management: fetches aliases, sets/selects default, updates form/UI accordingly.
apps/mail/components/create/email-composer.tsx Uses user settings for initial "from" email; syncs with default alias; reorganizes icon imports.
apps/mail/locales/en.json Added localization strings for default email alias selection and update messages.
apps/server/src/lib/driver/google.ts Removed all debug console.log statements from the email alias fetching method.
apps/server/src/lib/schemas.ts Added defaultEmailAlias to user settings schema and default settings object.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SettingsPage
    participant Server
    participant EmailComposer

    User->>SettingsPage: Opens General Settings
    SettingsPage->>Server: Fetches email aliases and user settings
    Server-->>SettingsPage: Returns aliases and settings (including defaultEmailAlias)
    SettingsPage->>User: Displays alias dropdown (select default)
    User->>SettingsPage: Selects default alias and submits
    SettingsPage->>Server: Updates user settings with new defaultEmailAlias

    User->>EmailComposer: Opens compose email
    EmailComposer->>Server: Fetches user settings and aliases
    Server-->>EmailComposer: Returns settings and aliases
    EmailComposer->>User: Sets "From" field to defaultEmailAlias (or fallback)
Loading

Possibly related PRs

  • Hotfixing #1303: Refactors EmailComposer to fetch aliases internally and update form initialization, related to alias handling improvements.
  • use aliases in email-composer #1233: Adds alias selection in email composer and syncs with user settings, closely related to managing default email aliases.
  • Feature/persist user settings #403: Implements initial persistence and management for user settings, providing the foundation for settings like "defaultEmailAlias".

Poem

A rabbit hopped through fields of code,
To set your "From" with every load.
Now pick your alias, set it true—
Compose with ease, the choice is new!
Settings synced and bugs are few,
🐇✨ Your emails shine with something new!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7d6564 and 0005c66.

📒 Files selected for processing (5)
  • apps/mail/app/(routes)/settings/general/page.tsx (6 hunks)
  • apps/mail/components/create/email-composer.tsx (4 hunks)
  • apps/mail/locales/en.json (2 hunks)
  • apps/server/src/lib/driver/google.ts (0 hunks)
  • apps/server/src/lib/schemas.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • apps/server/src/lib/driver/google.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/server/src/lib/schemas.ts
  • apps/mail/components/create/email-composer.tsx
  • apps/mail/app/(routes)/settings/general/page.tsx
  • apps/mail/locales/en.json
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (actions)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ahmetskilinc ahmetskilinc marked this pull request as ready for review June 18, 2025 14:22
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (5)
apps/server/src/lib/driver/types.ts (1)

91-93: New mandatory interface method can break downstream drivers

updatePrimaryEmailAlias is added as a required member. Any out-of-tree driver (or an older compiled artifact) will now fail at compile-time.
Two low-impact ways to mitigate:

-  updatePrimaryEmailAlias(email: string): Promise<void>;
+  /** Sets the primary/default email alias for the account. */
+  updatePrimaryEmailAlias?(email: string): Promise<void>;
  1. Mark it optional (?) and let unknown drivers degrade gracefully.
  2. Keep it mandatory but release the change with a clear breaking-change note.

Also, the name mixes “primary” vs “default” whereas the new schema property is defaultEmailAlias. Consider setDefaultEmailAlias for consistency.

apps/mail/components/create/email-composer.tsx (1)

110-112: Handle loading / error states from useSettings()

useSettings() can return { data: undefined, error: … } for some time.
If settings is undefined, subsequent access like settings.settings.defaultEmailAlias inside defaultValues (see below) will evaluate fine due to optional-chaining, but you never surface possible loading / error state to the UI. Consider exposing isLoading / error from the hook and disabling the form (or at least the “Send” button) until the data is available.

apps/server/src/lib/driver/microsoft.ts (1)

1260-1267: Method is a no-op – consider explicit “not implemented” signalling

updatePrimaryEmailAlias() currently just logs and resolves.
Callers may assume success and update UI optimistically. Recommend either:

  1. Throw StandardizedError('NotImplemented', …) so the caller can display a proper message, or
  2. Return a boolean/{ success:false } payload.
-      console.log('updatePrimaryEmailAlias not implemented for Outlook');
+      console.warn(
+        '[Outlook Driver] updatePrimaryEmailAlias is not implemented – Graph API limitation',
+      );
+      return { success: false, message: 'Not implemented for Outlook accounts' };
apps/mail/app/(routes)/settings/general/page.tsx (2)

165-167: emailAliasChanged is calculated but never used

emailAliasChanged becomes an unused constant after the surrounding code was commented out, triggering eslint/tsc “unused variable” warnings.

-      const emailAliasChanged =
-        saved?.defaultEmailAlias !== values.defaultEmailAlias && values.defaultEmailAlias;

Either delete the variable or re-enable the mutation that needs it.


174-185: Dead code: commented-out mutation block

The block invoking updatePrimaryAlias is fully commented. If the alias-update feature is postponed, consider removing the block to keep the file clean; otherwise, re-enable it together with a real backend implementation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d049e9e and 773c9bd.

📒 Files selected for processing (9)
  • apps/mail/app/(routes)/settings/general/page.tsx (5 hunks)
  • apps/mail/components/create/email-composer.tsx (3 hunks)
  • apps/mail/locales/en.json (2 hunks)
  • apps/server/src/lib/auth-providers.ts (1 hunks)
  • apps/server/src/lib/driver/google.ts (2 hunks)
  • apps/server/src/lib/driver/microsoft.ts (1 hunks)
  • apps/server/src/lib/driver/types.ts (1 hunks)
  • apps/server/src/lib/schemas.ts (2 hunks)
  • apps/server/src/trpc/routes/mail.ts (1 hunks)
🔇 Additional comments (7)
apps/server/src/lib/schemas.ts (2)

47-48: Default value is never enforced at validation time

defaultUserSettings sets defaultEmailAlias: '', yet the schema marks the field optional.
If consumers rely on the empty-string default they must remember to fall back manually whenever the key is omitted.

-  defaultEmailAlias: z.string().optional(),
+  defaultEmailAlias: z.string().default(''),

With .default('') the validator always yields a string, aligning runtime shape with your defaultUserSettings.

[ suggest_optional_refactor ]


60-61: Follow-up: allow null instead of empty-string?

If “no alias selected” is meaningful, null expresses intent better than '' and avoids confusion with a “real” empty alias.

- defaultEmailAlias: z.string().default(''),
+ defaultEmailAlias: z.string().nullable().default(null),

Just a consideration before this propagates into persisted data.

[ suggest_nitpick ]

apps/server/src/lib/auth-providers.ts (1)

45-47: Commented-out scopes leave dead code – decide or delete

The Gmail settings scopes are commented out here and the driver logic is stubbed. Carrying commented lines in production config adds noise and risks accidental commits. Either:

  1. Re-enable with a feature flag, or
  2. Remove until the functionality lands.

[ suggest_optional_refactor ]

apps/server/src/trpc/routes/mail.ts (1)

347-353: Stale commented mutation – prefer a feature toggle over commented code

The updatePrimaryEmailAlias mutation is entirely commented out. Commented code tends to rot and confuses readers & merge tools.

Options:

- // updatePrimaryEmailAlias: activeDriverProcedure ...
+ updatePrimaryEmailAlias: process.env.ENABLE_ALIAS_UPDATE === 'true'
+   ? activeDriverProcedure
+       .input(z.object({ email: z.string().email() }))
+       .mutation(async ({ ctx, input }) => {
+         const { driver } = ctx;
+         await driver.updatePrimaryEmailAlias?.(input.email);
+         return { success: true };
+       })
+   : undefined,

Keeps the router clean while preserving the work behind a flag.

[ suggest_essential_refactor ]

apps/mail/locales/en.json (2)

272-275: 👍 Translation keys look good

Keys for alias-update success/error read clearly and follow the existing naming pattern.


392-395: UI strings added – consistency check passed

The labels/description for selecting a default email alias are concise and match other General-settings strings.

apps/server/src/lib/driver/google.ts (1)

45-47: Scopes needed for alias-update logic are now commented out

The two Gmail settings scopes (gmail.settings.basic, gmail.settings.sharing) are commented out.
When updatePrimaryEmailAlias is eventually implemented it will require at least gmail.settings.basic; without it Google will reject the request with 403 / insufficient permissions.

Please double-check that the long-term plan is either
(a) to re-introduce the scopes when the feature is finished or
(b) to drop the backend alias-update capability entirely.

@graphite-app
Copy link
Contributor

graphite-app bot commented Jun 18, 2025

Merge activity

  • Jun 18, 5:38 PM UTC: This pull request can not be added to the Graphite merge queue. Please try rebasing and resubmitting to merge when ready.
  • Jun 18, 5:38 PM UTC: Graphite disabled "merge when ready" on this PR due to: a merge conflict with the target branch; resolve the conflict and try again..
  • Jun 20, 1:33 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 20, 1:34 AM UTC: @ahmetskilinc merged this pull request with Graphite.

@ahmetskilinc ahmetskilinc force-pushed the default_from_alias branch 2 times, most recently from 02f352e to e7d6564 Compare June 19, 2025 23:52
@ahmetskilinc ahmetskilinc merged commit c5d5479 into staging Jun 20, 2025
6 checks passed
@ahmetskilinc ahmetskilinc deleted the default_from_alias branch June 20, 2025 01:34
krakenftw pushed a commit to krakenftw/Zero that referenced this pull request Jun 24, 2025
# Add Default Email Alias Selection in Settings

This PR adds the ability for users to select a default email alias that will be used as the "From" address when composing new emails. The selected default alias is stored in user settings and automatically applied when creating new emails.

## Type of Change

- ✨ New feature (non-breaking change which adds functionality)
- 🎨 UI/UX improvement

## Areas Affected

- [x] User Interface/Experience
- [x] Data Storage/Management

## Features Added

1. Added a new `defaultEmailAlias` field to the user settings schema
2. Added a dropdown selector in the General Settings page to choose a default email alias
3. Modified the email composer to use the selected default alias when creating new emails
4. Added appropriate translations for the new UI elements
5. Added placeholder code (commented out) for future implementation of updating the primary alias in Gmail settings

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
	- Added the ability for users to select and manage a default email alias in general settings.
	- Introduced a dropdown menu for choosing a default email alias, which will be used as the default 'From' address when composing new emails.
- **Improvements**
	- The email composer now automatically uses the selected default email alias when starting a new message.
- **Localization**
	- Added new English localization strings for the default email alias feature and related notifications.
- **Chores**
	- Removed unnecessary debug logging from email alias retrieval.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@coderabbitai coderabbitai bot mentioned this pull request Jun 26, 2025
34 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants