-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): user is not redirected to Login page after requesting pass…
…word reset link
- Loading branch information
“bc-yevhenii-buliuk”
committed
Jun 7, 2024
1 parent
bf4739d
commit b9f81be
Showing
7 changed files
with
88 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
fix redirection to the Login page after password change |
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
46 changes: 46 additions & 0 deletions
46
core/app/[locale]/(default)/login/_components/login-status-provider.tsx
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,46 @@ | ||
'use client'; | ||
|
||
import { createContext, useContext, useState, useEffect, PropsWithChildren, ReactNode } from 'react'; | ||
|
||
export interface LoginState { | ||
status: 'idle' | 'success'; | ||
message?: string; | ||
} | ||
|
||
export const LoginStatusContext = createContext<{ | ||
loginState: LoginState; | ||
setLoginState: (state: LoginState | ((prevState: LoginState) => LoginState)) => void; | ||
} | null>(null); | ||
|
||
export const LoginStatusProvider = ({ children, isPermanentBanner }: { | ||
children: ReactNode, | ||
isPermanentBanner: ReactNode | ||
}) => { | ||
const [loginState, setLoginState] = useState<LoginState>({status: 'idle', message: ''}); | ||
|
||
if (!isPermanentBanner) { | ||
useEffect(() => { | ||
if (loginState.status !== 'idle') { | ||
setTimeout(() => { | ||
setLoginState({ status: 'idle', message: '' }); | ||
}, 3000); | ||
} | ||
}, [loginState, setLoginState]); | ||
} | ||
|
||
return ( | ||
<LoginStatusContext.Provider value={{loginState, setLoginState}}> | ||
{children} | ||
</LoginStatusContext.Provider> | ||
) | ||
} | ||
|
||
export function useLoginStatusContext() { | ||
const context = useContext(LoginStatusContext); | ||
|
||
if (!context) { | ||
throw new Error('useLoginStatusContext must be used within a LoginStatusProvider'); | ||
} | ||
|
||
return context; | ||
} |
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,10 @@ | ||
import { PropsWithChildren } from 'react'; | ||
import { LoginStatusProvider } from './_components/login-status-provider'; | ||
|
||
export default function LoginLayout({ children }: PropsWithChildren) { | ||
return ( | ||
<LoginStatusProvider isPermanentBanner={true}> | ||
{children} | ||
</LoginStatusProvider> | ||
) | ||
} |
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