-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[To Main] Fix for issue of null appearing in public URLs (#2529)
* Fix for issue of null appearing in public URLs * updating change log * Adding comments to HOC
- Loading branch information
1 parent
2b853c6
commit 0e58785
Showing
18 changed files
with
130 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,15 +90,15 @@ ACCESS_REQUEST_EMAIL_ADDRESS="[email protected]" | |
|
||
# Site paths for creating emails from templates | ||
SITE_URL=http://localhost:3000 | ||
SURVEY_PATH=/{lang}/surveys/submit/{survey_id}/{token} | ||
SURVEY_PATH=/surveys/submit/{survey_id}/{token}/{lang} | ||
USER_MANAGEMENT_PATH=/usermanagement | ||
SUBMISSION_PATH=/{lang}/engagements/{engagement_id}/edit/{token} | ||
SUBSCRIBE_PATH=/{lang}/engagements/{engagement_id}/subscribe/{token} | ||
UNSUBSCRIBE_PATH=/{lang}/engagements/{engagement_id}/unsubscribe/{participant_id} | ||
ENGAGEMENT_PATH=/{lang}/engagements/{engagement_id}/view | ||
ENGAGEMENT_PATH_SLUG=/{lang}/{slug} | ||
ENGAGEMENT_DASHBOARD_PATH=/{lang}/engagements/{engagement_id}/comments/public | ||
ENGAGEMENT_DASHBOARD_PATH_SLUG=/{lang}/{slug}/comments/public | ||
SUBMISSION_PATH=/engagements/{engagement_id}/edit/{token}/{lang} | ||
SUBSCRIBE_PATH=/engagements/{engagement_id}/subscribe/{token}/{lang} | ||
UNSUBSCRIBE_PATH=/engagements/{engagement_id}/unsubscribe/{participant_id}/{lang} | ||
ENGAGEMENT_PATH=/engagements/{engagement_id}/view/{lang} | ||
ENGAGEMENT_PATH_SLUG=/{slug}/{lang} | ||
ENGAGEMENT_DASHBOARD_PATH=/engagements/{engagement_id}/comments/public/{lang} | ||
ENGAGEMENT_DASHBOARD_PATH_SLUG=/{slug}/comments/public/{lang} | ||
|
||
#CDogs API settings | ||
CDOGS_ACCESS_TOKEN= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useEffect, ComponentType, useMemo } from 'react'; | ||
import { useParams, useNavigate } from 'react-router-dom'; | ||
import { useAppSelector } from '../hooks'; | ||
import { LanguageState } from 'reduxSlices/languageSlice'; | ||
|
||
interface RouteParams { | ||
[key: string]: string | undefined; | ||
engagementId?: string; | ||
slug?: string; | ||
subscriptionStatus?: string; | ||
scriptionKey?: string; | ||
dashboardType?: string; | ||
token?: string; | ||
widgetId?: string; | ||
} | ||
|
||
/** | ||
* Higher-Order Component (HOC) to handle language parameter in the URL. | ||
* This HOC checks if the current URL includes the language code and adds it if necessary. | ||
* It uses the language state and available translations from the context to determine if the language code should be added. | ||
* @param Component - The component to be wrapped by this HOC. | ||
* @returns A new component with language parameter handling. | ||
*/ | ||
const withLanguageParam = <P extends object>(Component: ComponentType<P>) => { | ||
return (props: P) => { | ||
const languageState: LanguageState = useAppSelector((state) => state.language); | ||
const languageCode = languageState.id; | ||
const rawParams = useParams<RouteParams>(); | ||
const params = useMemo(() => rawParams, [rawParams]); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
const currentUrl = window.location.pathname; | ||
if (languageCode && !currentUrl.includes(languageCode)) { | ||
let newUrl = currentUrl; | ||
|
||
for (const param in params) { | ||
if (params[param as keyof RouteParams]) { | ||
newUrl = newUrl.replace(`:${param}`, params[param as keyof RouteParams] as string); | ||
} | ||
} | ||
|
||
newUrl = newUrl.replace(':language', languageCode); | ||
|
||
navigate(newUrl, { replace: true }); | ||
} | ||
}, [languageCode, navigate, params]); | ||
|
||
return <Component {...props} />; | ||
}; | ||
}; | ||
|
||
export default withLanguageParam; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.