-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display welcome modal in correct order
Use react router loaders to display modals in correct order. We want to display welcome modal after access code modal in standalone app and before wallet connection in embedded apps.
- Loading branch information
1 parent
a2469bd
commit 82e8809
Showing
14 changed files
with
178 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react" | ||
import { useAppNavigate } from "#/hooks" | ||
import GateModal from "#/components/GateModal" | ||
|
||
export default function AccessPage() { | ||
const navigate = useAppNavigate() | ||
|
||
return ( | ||
<GateModal | ||
closeModal={() => { | ||
navigate("/dashboard") | ||
}} | ||
/> | ||
) | ||
} |
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,40 @@ | ||
import { getAccessCodeFromLocalStorage } from "#/hooks/useAccessCode" | ||
import redirectWithSearchParams from "#/router/utils" | ||
import { acreApi, shouldDisplayWelcomeModal } from "#/utils" | ||
import { LoaderFunction } from "react-router-dom" | ||
|
||
export const redirectToAccessPageLoader = async ( | ||
url: string, | ||
redirectToOnSuccess: null | string = null, | ||
redirectToOnFail: null | string = null, | ||
) => { | ||
try { | ||
const isValid = await acreApi.verifyAccessCode( | ||
getAccessCodeFromLocalStorage() ?? "", | ||
) | ||
|
||
if (isValid) { | ||
const shouldRedirectToWelcomeModal = shouldDisplayWelcomeModal() | ||
|
||
return shouldRedirectToWelcomeModal | ||
? redirectWithSearchParams(url, "/welcome") | ||
: !redirectToOnSuccess || | ||
redirectWithSearchParams(url, redirectToOnSuccess) | ||
} | ||
|
||
return redirectToOnFail | ||
? redirectWithSearchParams(url, redirectToOnFail) | ||
: null | ||
} catch (error) { | ||
console.error("Failed to verify access code") | ||
|
||
return redirectToOnFail | ||
? redirectWithSearchParams(url, redirectToOnFail) | ||
: null | ||
} | ||
} | ||
|
||
const accessPageLoader: LoaderFunction = async ({ request }) => | ||
redirectToAccessPageLoader(request.url, "/dashboard") | ||
|
||
export default accessPageLoader |
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,17 @@ | ||
import { referralProgram, shouldDisplayWelcomeModal } from "#/utils" | ||
import { LoaderFunction } from "react-router-dom" | ||
import redirectWithSearchParams from "#/router/utils" | ||
import { redirectToAccessPageLoader } from "../AccessPage/loader" | ||
|
||
const dashboardPageLoader: LoaderFunction = async (args) => { | ||
const { request } = args | ||
|
||
if (referralProgram.isEmbedApp(referralProgram.getEmbeddedApp(request.url))) | ||
return shouldDisplayWelcomeModal() | ||
? redirectWithSearchParams(request.url, "/welcome") | ||
: null | ||
|
||
return redirectToAccessPageLoader(request.url, null, "/access") | ||
} | ||
|
||
export default dashboardPageLoader |
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,23 @@ | ||
import React from "react" | ||
import WelcomeModal from "#/components/WelcomeModal" | ||
import { useAppNavigate, useLocalStorage } from "#/hooks" | ||
import { LOCAL_STORAGE_KEY } from "#/utils/shouldDisplayWelcomeModal" | ||
|
||
function WelcomePage() { | ||
const navigate = useAppNavigate() | ||
const [_, setShouldDisplayWelcomeModal] = useLocalStorage<boolean>( | ||
LOCAL_STORAGE_KEY, | ||
true, | ||
) | ||
|
||
return ( | ||
<WelcomeModal | ||
closeModal={() => { | ||
setShouldDisplayWelcomeModal(false) | ||
navigate("/dashboard") | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
export default WelcomePage |
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 redirectWithSearchParams from "#/router/utils" | ||
import { shouldDisplayWelcomeModal } from "#/utils" | ||
import { LoaderFunction } from "react-router-dom" | ||
|
||
const welcomePageLoader: LoaderFunction = ({ request }) => | ||
shouldDisplayWelcomeModal() | ||
? null | ||
: redirectWithSearchParams(request.url, "/dashboard") | ||
|
||
export default welcomePageLoader |
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,9 @@ | ||
import { redirect } from "react-router-dom" | ||
|
||
const redirectWithSearchParams = (url: string, to: string) => { | ||
const requestUrl = new URL(url) | ||
|
||
return redirect(`${to}${requestUrl.search}`) | ||
} | ||
|
||
export default redirectWithSearchParams |
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,7 @@ | ||
import { getLocalStorageItem } from "#/hooks/useLocalStorage" | ||
|
||
export const LOCAL_STORAGE_KEY = "acre.shouldDisplayWelcomeModal" | ||
|
||
export default function shouldDisplayWelcomeModal() { | ||
return getLocalStorageItem(LOCAL_STORAGE_KEY) !== "false" | ||
} |