-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into wip/radeusgd/value-types-1
- Loading branch information
Showing
22 changed files
with
1,489 additions
and
1,560 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
82 changes: 40 additions & 42 deletions
82
...op/lib/dashboard/src/authentication/src/authentication/components/confirmRegistration.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 |
---|---|---|
@@ -1,62 +1,60 @@ | ||
/** @file Registration confirmation page for when a user clicks the confirmation link set to their | ||
* email address. */ | ||
import * as react from "react"; | ||
import * as router from "react-router-dom"; | ||
import toast from "react-hot-toast"; | ||
import * as react from 'react' | ||
import * as router from 'react-router-dom' | ||
import toast from 'react-hot-toast' | ||
|
||
import * as app from "../../components/app"; | ||
import * as auth from "../providers/auth"; | ||
import * as loggerProvider from "../../providers/logger"; | ||
import * as app from '../../components/app' | ||
import * as auth from '../providers/auth' | ||
import * as loggerProvider from '../../providers/logger' | ||
|
||
// ================= | ||
// === Constants === | ||
// ================= | ||
|
||
const REGISTRATION_QUERY_PARAMS = { | ||
verificationCode: "verification_code", | ||
email: "email", | ||
} as const; | ||
verificationCode: 'verification_code', | ||
email: 'email', | ||
} as const | ||
|
||
// ============================ | ||
// === Confirm Registration === | ||
// ============================ | ||
|
||
function ConfirmRegistration() { | ||
const logger = loggerProvider.useLogger(); | ||
const { confirmSignUp } = auth.useAuth(); | ||
const { search } = router.useLocation(); | ||
const navigate = router.useNavigate(); | ||
|
||
const { verificationCode, email } = parseUrlSearchParams(search); | ||
|
||
react.useEffect(() => { | ||
if (!email || !verificationCode) { | ||
navigate(app.LOGIN_PATH); | ||
} else { | ||
confirmSignUp(email, verificationCode) | ||
.then(() => { | ||
navigate(app.LOGIN_PATH + search.toString()); | ||
}) | ||
.catch((error) => { | ||
logger.error("Error while confirming sign-up", error); | ||
toast.error( | ||
"Something went wrong! Please try again or contact the administrators." | ||
); | ||
navigate(app.LOGIN_PATH); | ||
}); | ||
} | ||
}, []); | ||
|
||
return <></>; | ||
const logger = loggerProvider.useLogger() | ||
const { confirmSignUp } = auth.useAuth() | ||
const { search } = router.useLocation() | ||
const navigate = router.useNavigate() | ||
|
||
const { verificationCode, email } = parseUrlSearchParams(search) | ||
|
||
react.useEffect(() => { | ||
if (!email || !verificationCode) { | ||
navigate(app.LOGIN_PATH) | ||
} else { | ||
confirmSignUp(email, verificationCode) | ||
.then(() => { | ||
navigate(app.LOGIN_PATH + search.toString()) | ||
}) | ||
.catch(error => { | ||
logger.error('Error while confirming sign-up', error) | ||
toast.error( | ||
'Something went wrong! Please try again or contact the administrators.' | ||
) | ||
navigate(app.LOGIN_PATH) | ||
}) | ||
} | ||
}, []) | ||
|
||
return <></> | ||
} | ||
|
||
function parseUrlSearchParams(search: string) { | ||
const query = new URLSearchParams(search); | ||
const verificationCode = query.get( | ||
REGISTRATION_QUERY_PARAMS.verificationCode | ||
); | ||
const email = query.get(REGISTRATION_QUERY_PARAMS.email); | ||
return { verificationCode, email }; | ||
const query = new URLSearchParams(search) | ||
const verificationCode = query.get(REGISTRATION_QUERY_PARAMS.verificationCode) | ||
const email = query.get(REGISTRATION_QUERY_PARAMS.email) | ||
return { verificationCode, email } | ||
} | ||
|
||
export default ConfirmRegistration; | ||
export default ConfirmRegistration |
Oops, something went wrong.