@@ -5,7 +5,9 @@ import onClient from '#app/lib/utilities/onClient';
55import { AccountContextProps , IdctaConfig } from '#app/models/types/account' ;
66import appendCtaQueryParams from '#app/lib/idcta/appendCtaQueryParams' ;
77
8- export const AccountContext = createContext < AccountContextProps | null > ( null ) ;
8+ export const AccountContext = createContext < AccountContextProps > (
9+ { } as AccountContextProps ,
10+ ) ;
911
1012const getSignedInCookie = ( cookieName = 'ckns_id' ) => {
1113 return onClient ( ) ? Cookie . get ( cookieName ) : false ;
@@ -19,24 +21,25 @@ export const AccountProvider = ({
1921 initialConfig : IdctaConfig | null ;
2022} ) => {
2123 const { locale } = use ( ServiceContext ) ;
22- const [ ptrt , setPtrt ] = useState < string | undefined > ( undefined ) ;
24+ const [ pageToReturnTo , setPageToReturnTo ] = useState < string | null > ( null ) ;
2325
2426 useEffect ( ( ) => {
25- setPtrt ( window . location . href ) ;
27+ setPageToReturnTo ( window . location . href ) ;
2628 } , [ ] ) ;
2729
2830 const idIdctaAvailable = initialConfig ?. [ 'id-availability' ] === 'GREEN' ;
2931
3032 const buildAccountUrl = ( url ?: string ) => {
3133 return idIdctaAvailable && url
32- ? appendCtaQueryParams ( url , { ptrt , lang : locale } )
34+ ? appendCtaQueryParams ( url , { pageToReturnTo , lang : locale } )
3335 : initialConfig ?. unavailable_url ;
3436 } ;
3537
3638 const signInUrl = buildAccountUrl ( initialConfig ?. signin_url ) ;
3739 const registerUrl = buildAccountUrl ( initialConfig ?. register_url ) ;
3840 const settingsUrl = buildAccountUrl ( initialConfig ?. settings_url ) ;
3941 const signOutUrl = buildAccountUrl ( initialConfig ?. signout_url ) ;
42+ const forYouUrl = buildAccountUrl ( initialConfig ?. foryou_url ) ;
4043
4144 const cookieName = initialConfig ?. identity . idSignedInCookieName ;
4245 const isSignedIn = idIdctaAvailable
@@ -51,8 +54,10 @@ export const AccountProvider = ({
5154 signOutUrl,
5255 registerUrl,
5356 settingsUrl,
57+ forYouUrl,
5458 } ) ,
5559 [
60+ forYouUrl ,
5661 idIdctaAvailable ,
5762 isSignedIn ,
5863 registerUrl ,
0 commit comments