Conversation
…lities to be asynchronous.
| * @returns {string} Formatted date string or '-' if no date | ||
| */ | ||
| export function formatDate(date, formatStr = 'MMM d, yyyy') { | ||
| export function formatDate(date) { |
There was a problem hiding this comment.
'export' is only available in ES6 (use 'esversion: 6').
|
|
||
| const relativeFormatter = new Intl.RelativeTimeFormat('en', { numeric: 'auto' }); | ||
|
|
||
| const RELATIVE_UNITS = /** @type {const} */ ([ |
There was a problem hiding this comment.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
| year: 'numeric' | ||
| }); | ||
|
|
||
| const relativeFormatter = new Intl.RelativeTimeFormat('en', { numeric: 'auto' }); |
There was a problem hiding this comment.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
| */ | ||
|
|
||
| import { format, formatDistanceToNow } from 'date-fns'; | ||
| const dateFormatter = new Intl.DateTimeFormat('en-US', { |
There was a problem hiding this comment.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
| * @returns {string} Formatted date string or '-' if no date | ||
| */ | ||
| export function formatDate(date, formatStr = 'MMM d, yyyy') { | ||
| export function formatDate(date) { |
There was a problem hiding this comment.
'export' is only available in ES6 (use 'esversion: 6').
|
|
||
| const relativeFormatter = new Intl.RelativeTimeFormat('en', { numeric: 'auto' }); | ||
|
|
||
| const RELATIVE_UNITS = /** @type {const} */ ([ |
There was a problem hiding this comment.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
| year: 'numeric' | ||
| }); | ||
|
|
||
| const relativeFormatter = new Intl.RelativeTimeFormat('en', { numeric: 'auto' }); |
There was a problem hiding this comment.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
| */ | ||
|
|
||
| import { format, formatDistanceToNow } from 'date-fns'; | ||
| const dateFormatter = new Intl.DateTimeFormat('en-US', { |
There was a problem hiding this comment.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
| const trimmed = phoneNumber.trim(); | ||
|
|
||
| try { | ||
| const { isValidPhoneNumber, parsePhoneNumber, isPossiblePhoneNumber } = await getLib(); |
There was a problem hiding this comment.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
'destructuring binding' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Missing semicolon.
| * @returns {Promise<{ isValid: boolean, formatted?: string, error?: string }>} | ||
| */ | ||
| export function validatePhoneNumber(phoneNumber, defaultCountry) { | ||
| export async function validatePhoneNumber(phoneNumber, defaultCountry) { |
There was a problem hiding this comment.
'export' is only available in ES6 (use 'esversion: 6').
Expected an assignment or function call and instead saw an expression.
Missing semicolon.
Unexpected 'async'.
| @@ -1,19 +1,27 @@ | |||
| import { isValidPhoneNumber, parsePhoneNumber, isPossiblePhoneNumber } from 'libphonenumber-js'; | |||
| /** @type {Promise<typeof import('libphonenumber-js')> | null} */ | |||
| let _lib = null; | |||
There was a problem hiding this comment.
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
| errors.phone = phoneValidation.error || 'Please enter a valid phone number'; | ||
| } else { | ||
| formattedPhone = formatPhoneForStorage(phone.trim()); | ||
| formattedPhone = await formatPhoneForStorage(phone.trim()); |
| let formattedPhone = null; | ||
| if (phone && phone.trim().length > 0) { | ||
| const phoneValidation = validatePhoneNumber(phone.trim()); | ||
| const phoneValidation = await validatePhoneNumber(phone.trim()); |
There was a problem hiding this comment.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Missing semicolon.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
📝 WalkthroughWalkthroughRemoved the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR refactors frontend formatting utilities by removing date-fns in favor of native Intl APIs, and updates phone utilities to lazy-load libphonenumber-js via async helpers (propagating async usage into the profile page and server action).
Changes:
- Replace
date-fnsdate/relative formatting withIntl.DateTimeFormatandIntl.RelativeTimeFormat. - Refactor phone utilities to async functions with dynamic import caching for
libphonenumber-js. - Update profile UI/server action usage to await phone validation/formatting and adjust redirects.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/routes/(app)/profile/+page.svelte | Adapts profile UI to async phone formatting/validation and displays resolved formatted phone. |
| frontend/src/routes/(app)/profile/+page.server.js | Awaits async phone validation/formatting before sending updates to the API. |
| frontend/src/lib/utils/phone.js | Converts phone helpers to async and lazy-loads libphonenumber-js. |
| frontend/src/lib/utils/formatting.js | Replaces date-fns with Intl formatters for absolute + relative dates. |
| frontend/src/hooks.server.js | Adjusts org-switch-failure redirect status code. |
| frontend/package.json | Removes date-fns dependency. |
| frontend/pnpm-lock.yaml | Removes date-fns lock entries. |
Files not reviewed (1)
- frontend/pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
frontend/src/routes/(app)/profile/+page.svelte:61
validatePhoneis now async and is invoked on everyoninput. Multiple in-flight validations can resolve out of order and setphoneErrorbased on a previous input value. Consider debouncing validation and/or tracking the latest validatedformData.phonevalue (or a counter) so only the most recent validation result updatesphoneError.
async function validatePhone() {
if (!formData.phone.trim()) {
phoneError = '';
return;
}
const validation = await validatePhoneNumber(formData.phone);
if (!validation.isValid) {
phoneError = validation.error || 'Invalid phone number';
} else {
phoneError = '';
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Format phone for display (async, resolved into state) | ||
| $effect(() => { | ||
| if (data.user.phone) { | ||
| formatPhoneNumber(data.user.phone).then((f) => (formattedDisplayPhone = f)); | ||
| } else { | ||
| formattedDisplayPhone = ''; | ||
| } | ||
| }); |
There was a problem hiding this comment.
The async $effect that formats data.user.phone can race if data.user.phone changes before the previous formatPhoneNumber() promise resolves (stale promise may overwrite formattedDisplayPhone). Consider guarding with a monotonic request id / captured value check (only assign if the phone value is still current), or using an abortable pattern in the effect cleanup.
| year: 'numeric' | ||
| }); | ||
|
|
||
| const relativeFormatter = new Intl.RelativeTimeFormat('en', { numeric: 'auto' }); |
There was a problem hiding this comment.
dateFormatter is configured with locale en-US, but relativeFormatter uses en. If the intent is consistent formatting across the app, consider using the same locale (or deriving both from a single locale setting) to avoid mismatched language/region output.
| const relativeFormatter = new Intl.RelativeTimeFormat('en', { numeric: 'auto' }); | |
| const relativeFormatter = new Intl.RelativeTimeFormat('en-US', { numeric: 'auto' }); |
…lities to be asynchronous.
Summary by CodeRabbit
Release Notes
Bug Fixes
Refactor