save default address to db with google code ready#1355
Conversation
WalkthroughThis 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
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)
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
⏰ Context from checks skipped due to timeout of 90000ms (2)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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
updatePrimaryEmailAliasis 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>;
- Mark it optional (
?) and let unknown drivers degrade gracefully.- 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. ConsidersetDefaultEmailAliasfor consistency.apps/mail/components/create/email-composer.tsx (1)
110-112: Handle loading / error states fromuseSettings()
useSettings()can return{ data: undefined, error: … }for some time.
Ifsettingsisundefined, subsequent access likesettings.settings.defaultEmailAliasinsidedefaultValues(see below) will evaluate fine due to optional-chaining, but you never surface possible loading / error state to the UI. Consider exposingisLoading/errorfrom 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:
- Throw
StandardizedError('NotImplemented', …)so the caller can display a proper message, or- 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:emailAliasChangedis calculated but never used
emailAliasChangedbecomes 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 blockThe block invoking
updatePrimaryAliasis 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
📒 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
defaultUserSettingssetsdefaultEmailAlias: '', 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 yourdefaultUserSettings.[ suggest_optional_refactor ]
60-61: Follow-up: allow null instead of empty-string?If “no alias selected” is meaningful,
nullexpresses 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 deleteThe 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:
- Re-enable with a feature flag, or
- 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 codeThe
updatePrimaryEmailAliasmutation 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 goodKeys for alias-update success/error read clearly and follow the existing naming pattern.
392-395: UI strings added – consistency check passedThe 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 outThe two Gmail settings scopes (
gmail.settings.basic,gmail.settings.sharing) are commented out.
WhenupdatePrimaryEmailAliasis eventually implemented it will require at leastgmail.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.
773c9bd to
ab3342a
Compare
Merge activity
|
02f352e to
e7d6564
Compare
resolve code rabbit comments
919a6c6 to
0005c66
Compare
# 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 -->

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
Areas Affected
Features Added
defaultEmailAliasfield to the user settings schemaSummary by CodeRabbit