-
Notifications
You must be signed in to change notification settings - Fork 2
PROD | WEB91-202 | signup cookies handling #1077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||||||||||
| import axios from 'axios'; | ||||||||||||||||||||||||||||||||
| import { setSharedCookie } from '@/utils/utilis'; | ||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||
| MdKeyboardArrowRight, | ||||||||||||||||||||||||||||||||
| MdKeyboardArrowLeft, | ||||||||||||||||||||||||||||||||
|
|
@@ -295,6 +296,7 @@ class StepThree extends React.Component { | |||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| finalSubmit = () => { | ||||||||||||||||||||||||||||||||
| setSharedCookie('signup_date', new Date().toISOString().split('T')[0], 30); | ||||||||||||||||||||||||||||||||
| const errors = { | ||||||||||||||||||||||||||||||||
| firstNameError: this.validateFirstName() || this.validateMinMax('firstName', 'First Name', null, 50), | ||||||||||||||||||||||||||||||||
| lastNameError: this.validateLastName() || this.validateMinMax('lastName', 'Last Name', null, 50), | ||||||||||||||||||||||||||||||||
|
|
@@ -515,6 +517,11 @@ class StepThree extends React.Component { | |||||||||||||||||||||||||||||||
| serviceNeeded: value.map((obj) => obj.value), | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||
| setSharedCookie( | ||||||||||||||||||||||||||||||||
| 'interested_services', | ||||||||||||||||||||||||||||||||
| JSON.stringify(value.map((obj) => obj.label)), | ||||||||||||||||||||||||||||||||
| 30 | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
|
Comment on lines
+520
to
+524
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling around the JSON.stringify operation to prevent potential issues if the data structure changes in the future.
Suggested change
|
||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||
| placeholder='Select Service Needed*' | ||||||||||||||||||||||||||||||||
| options={ | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,6 +50,36 @@ export function setCookie(name, value, days) { | |||||||||||||||||||||||||
| document.cookie = name + '=' + cookieValue + '; path=/'; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export function getUtmFromCookies() { | ||||||||||||||||||||||||||
| if (typeof document === 'undefined') return {}; | ||||||||||||||||||||||||||
| const result = {}; | ||||||||||||||||||||||||||
| document.cookie.split(';').forEach((cookie) => { | ||||||||||||||||||||||||||
| const [key, value] = cookie.trim().split('='); | ||||||||||||||||||||||||||
| if (key?.startsWith('utm_') && value) result[key] = decodeURIComponent(value); | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
Comment on lines
+56
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cookie parsing in
Suggested change
|
||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export function setSharedCookie(name, value, days = 1) { | ||||||||||||||||||||||||||
| if (typeof document === 'undefined') return; | ||||||||||||||||||||||||||
| const expirationDate = new Date(); | ||||||||||||||||||||||||||
| expirationDate.setDate(expirationDate.getDate() + days); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const isLocalhost = window.location.hostname === 'localhost'; | ||||||||||||||||||||||||||
| const cookieParts = [ | ||||||||||||||||||||||||||
| `${name}=${encodeURIComponent(value)}`, | ||||||||||||||||||||||||||
| `expires=${expirationDate.toUTCString()}`, | ||||||||||||||||||||||||||
| 'path=/', | ||||||||||||||||||||||||||
| 'SameSite=Lax', | ||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||
| if (!isLocalhost) { | ||||||||||||||||||||||||||
| cookieParts.push('domain=.msg91.com'); | ||||||||||||||||||||||||||
| cookieParts.push('Secure'); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| document.cookie = cookieParts.join('; '); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export function loginWithGitHubAccount(loginProcess) { | ||||||||||||||||||||||||||
| let state = Math.floor(100000000 + Math.random() * 900000000); | ||||||||||||||||||||||||||
| let otherParams = loginProcess ? `githublogin=true` : `githubsignup=true`; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.