-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve Activation page, page errors and minor fixes
- Loading branch information
1 parent
3f3b02b
commit dfe6022
Showing
12 changed files
with
131 additions
and
41 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from "react"; | ||
//LOOKUP: https://medium.com/trabe/catching-asynchronous-errors-in-react-using-error-boundaries-5e8a5fd7b971 | ||
/* | ||
NOTE: | ||
React Router v6 does have built in methods to catch async errors, however there seems to be new(and better) tools | ||
for client side page routing in react. | ||
Not knowing the future of this app, I did not want to be dependent on a 3rd party service that i can easily implement | ||
with a custom hook | ||
*/ | ||
export const useThrowAsyncError = () => { | ||
const [_, setError] = React.useState(); | ||
return React.useCallback( | ||
(e: any) => { | ||
setError(() => { | ||
throw e; | ||
}); | ||
}, | ||
[setError] | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
import { useEffect, useRef } from 'react' | ||
import { useNavigate, useParams } from 'react-router-dom' | ||
import { Id } from 'react-toastify' | ||
import responseHandler from '../../apis/responseHandler' | ||
import RestAPI from '../../apis/server.endpoints' | ||
import { notifyToastPromiseSuccess } from '../../components/alerts/toasts/promise.notifier' | ||
import SectionWrapper from '../misc/SectionWrapper' | ||
import { useThrowAsyncError } from '../../hooks/useThrowAsyncError.hook' | ||
import Frame from '../misc/Frame' | ||
|
||
|
||
export default function ActivationPage() { | ||
|
||
const { token } = useParams() | ||
const navigation = useNavigate() | ||
const ref = useRef(true) | ||
const throwError = useThrowAsyncError() | ||
useEffect(() => { | ||
if (ref.current) { | ||
|
||
responseHandler(() => RestAPI.activate(token as string), (_res: Response, toastId: Id) => { | ||
|
||
notifyToastPromiseSuccess(toastId, "Success!") | ||
navigation("/login") | ||
return true; | ||
|
||
}).then(res => { | ||
!res && throwError(new Error("There seems to be a problem activating your account. Please request a new link through the sign up form, or try again later. If the error persists, then please contact the developers at: '[email protected]'")) | ||
}) | ||
|
||
ref.current = false | ||
} | ||
}, [ref]) | ||
|
||
return ( | ||
<> | ||
|
||
<Frame></Frame> | ||
<main id="main"> | ||
<SectionWrapper className="account-activation"> | ||
<h2>Activating Your Account</h2> | ||
</SectionWrapper></main> | ||
</> | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
frontend/src/pages/errorBoundaries/ActivateAccountErrors.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,10 @@ | ||
import { useRouteError } from 'react-router-dom'; | ||
import ErrorPage from './ErrorPage'; | ||
|
||
export default function ActivateAccountErrors() { | ||
const error = useRouteError() as Error | ||
|
||
return ( | ||
<ErrorPage title="We've Spilled The Tea" message={error.message} /> | ||
) | ||
} |
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,13 @@ | ||
import Frame from '../misc/Frame' | ||
|
||
export default function ErrorPage({ title, message }: { title: string, message: string }) { | ||
return ( | ||
<> | ||
<Frame></Frame> | ||
<main id="main" className='error-container'> | ||
<h1>{title}</h1> | ||
<p className="error-message">{message}</p> | ||
</main> | ||
</> | ||
) | ||
} |
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 |
---|---|---|
|
@@ -25,3 +25,4 @@ | |
@use "pages/item-display"; | ||
@use "pages/profile"; | ||
@use "pages/help-center"; | ||
@use "pages/error-boundary"; |
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,16 @@ | ||
@use "../base/colors" as colors; | ||
#main.error-container { | ||
display: flex; | ||
flex-direction: column; | ||
place-content: center; | ||
place-items: center; | ||
} | ||
.error-message { | ||
max-width: 70%; | ||
border-radius: 10px; | ||
background-color: rgba($color: colors.$light, $alpha: 0.1); | ||
backdrop-filter: blur(15px); | ||
font-size: 1.5rem; | ||
padding: 1.5em; | ||
line-height: 1.3em; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.