-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented redirects using context.config (#2755)
* feat: implemented redirects using context.config * fix(vscode): submodule search issue * chore(docs): webhooks schema --------- Co-authored-by: Alon Peretz <[email protected]>
- Loading branch information
1 parent
c7f9527
commit 7ee7582
Showing
50 changed files
with
508 additions
and
151 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
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
28 changes: 24 additions & 4 deletions
28
apps/kyb-app/src/hooks/useUIOptionsRedirect/useUIOptionsRedirect.ts
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 |
---|---|---|
@@ -1,13 +1,33 @@ | ||
import { useStateManagerContext } from '@/components/organisms/DynamicUI/StateManager/components/StateProvider'; | ||
import { UIOptions } from '@/domains/collection-flow'; | ||
import { useLanguage } from '@/hooks/useLanguage'; | ||
import { useUISchemasQuery } from '@/hooks/useUISchemasQuery'; | ||
import { useEffect } from 'react'; | ||
import { useEffect, useMemo } from 'react'; | ||
|
||
export const useUIOptionsRedirect = (state: 'success' | 'failure') => { | ||
const { data } = useUISchemasQuery(useLanguage()); | ||
const { config } = useStateManagerContext(); | ||
|
||
const uiOptions: UIOptions | null = useMemo(() => { | ||
// Config has priority over uiOptions in data | ||
if (config?.uiOptions?.redirectUrls) return config.uiOptions; | ||
|
||
if (data?.uiOptions?.redirectUrls) return data.uiOptions; | ||
|
||
return null; | ||
}, [data, config]); | ||
|
||
const redirectUrls: UIOptions['redirectUrls'] | null = useMemo(() => { | ||
if (!uiOptions) return null; | ||
|
||
return uiOptions.redirectUrls; | ||
}, [uiOptions]); | ||
|
||
useEffect(() => { | ||
if (data?.uiOptions?.redirectUrls?.[state]) { | ||
location.href = data.uiOptions.redirectUrls?.[state] as string; | ||
if (redirectUrls?.[state]) { | ||
const redirectUrl = redirectUrls[state] as string; | ||
console.info(`Collection Flow resolved to ${state}. Redirecting to ${redirectUrl}`); | ||
location.href = redirectUrls[state] as string; | ||
} | ||
}, [data, state]); | ||
}, [redirectUrls, state]); | ||
}; |
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
Oops, something went wrong.