Conversation
There was a problem hiding this comment.
Other comments (5)
-
src/components/signupComp/SignUp.js (82-92)
Consider using URLSearchParams for building the redirect URL to ensure all parameters are properly encoded and the URL is constructed correctly:
let redirectUrl = SUCCESS_REDIRECTION_URL?.replace(':session', payload.session); const urlParams = new URLSearchParams(); const signupDate = getCookie('signup_date'); const interestedServices = getCookie('interested_services'); if (signupDate) urlParams.append('signup_date', signupDate); if (interestedServices) urlParams.append('interested_services', interestedServices); Object.entries(getUtmFromCookies()).forEach(([key, value]) => { if (key?.startsWith('utm_') && value) urlParams.append(key, value); }); const queryString = urlParams.toString(); if (queryString) redirectUrl += `&${queryString}`; location.href = redirectUrl; -
src/components/signupComp/SignUp.js (60-62)
When setting UTM parameter cookies on lines 60-62, consider checking if they already exist to avoid overwriting values that might have been set earlier in the user journey:
const urlParams = new URLSearchParams(window.location.search); urlParams.forEach((value, key) => { if (key.startsWith('utm_') && !getCookie(key)) setSharedCookie(key, value, 30); }); - src/utils/utilis.js (63-81) There are now two cookie-setting functions (`setCookie` and `setSharedCookie`) with different implementations and security settings. Consider consolidating these functions or clearly documenting when to use each one to avoid confusion and ensure consistent cookie handling across the application.
- src/components/signupComp/StepThree/StepThree.js (299-299) The cookie expiration is hardcoded to 30 days in multiple places. Consider defining this as a constant at the top of the file or importing it from a configuration file to ensure consistency across all cookie operations.
- src/utils/utilis.js (63-63) In `setSharedCookie()`, the cookie value is properly encoded, but the cookie name isn't checked for special characters. While this might not be an immediate issue with your current usage, it's a good practice to ensure cookie names are valid to prevent future bugs.
💡 To request another review, post a new comment with "/windsurf-review".
| let redirectUrl = SUCCESS_REDIRECTION_URL?.replace(':session', payload.session); | ||
| const signupDate = getCookie('signup_date'); | ||
| const interestedServices = getCookie('interested_services'); | ||
| if (signupDate) redirectUrl += `&signup_date=${encodeURIComponent(signupDate)}`; | ||
| if (interestedServices) | ||
| redirectUrl += `&interested_services=${encodeURIComponent(interestedServices)}`; | ||
| Object.entries(getUtmFromCookies()).forEach(([key, value]) => { | ||
| if (key?.startsWith('utm_') && value) | ||
| redirectUrl += `&${encodeURIComponent(key)}=${encodeURIComponent(value)}`; | ||
| }); | ||
| location.href = redirectUrl; |
There was a problem hiding this comment.
There's duplicate code for building the redirect URL with parameters in three different places (lines 82-92, 393-406, and 490-503). Consider extracting this into a reusable function to improve maintainability and reduce the risk of inconsistent behavior.
| setSharedCookie( | ||
| 'interested_services', | ||
| JSON.stringify(value.map((obj) => obj.label)), | ||
| 30 | ||
| ); |
There was a problem hiding this comment.
Consider adding error handling around the JSON.stringify operation to prevent potential issues if the data structure changes in the future.
| setSharedCookie( | |
| 'interested_services', | |
| JSON.stringify(value.map((obj) => obj.label)), | |
| 30 | |
| ); | |
| setSharedCookie( | |
| 'interested_services', | |
| try { | |
| JSON.stringify(value.map((obj) => obj.label)) | |
| } catch (e) { | |
| console.error('Error stringifying services:', e); | |
| '[]' | |
| }, | |
| 30 | |
| ); |
| document.cookie.split(';').forEach((cookie) => { | ||
| const [key, value] = cookie.trim().split('='); | ||
| if (key?.startsWith('utm_') && value) result[key] = decodeURIComponent(value); | ||
| }); |
There was a problem hiding this comment.
The cookie parsing in getUtmFromCookies() might fail if there's a malformed cookie without an equals sign. Consider adding a check before destructuring:
| document.cookie.split(';').forEach((cookie) => { | |
| const [key, value] = cookie.trim().split('='); | |
| if (key?.startsWith('utm_') && value) result[key] = decodeURIComponent(value); | |
| }); | |
| document.cookie.split(';').forEach((cookie) => { | |
| const parts = cookie.trim().split('='); | |
| if (parts.length >= 2) { | |
| const [key, ...valueParts] = parts; | |
| const value = valueParts.join('='); // Handle values that might contain '=' | |
| if (key?.startsWith('utm_') && value) result[key] = decodeURIComponent(value); | |
| } | |
| }); |
No description provided.