forgot-password-errors.page.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React from 'react';
  2. import { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
  3. import { useTranslation } from 'next-i18next';
  4. import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
  5. import Link from 'next/link';
  6. import { forgotPasswordErrorCode } from '~/interfaces/errors/forgot-password';
  7. import {
  8. CommonProps, getNextI18NextConfig, getServerSideCommonProps,
  9. } from './utils/commons';
  10. type Props = CommonProps & {
  11. errorCode?: forgotPasswordErrorCode
  12. };
  13. const ForgotPasswordErrorsPage: NextPage<Props> = (props: Props) => {
  14. const { t } = useTranslation();
  15. const { errorCode } = props;
  16. return (
  17. <div id="main" className="main">
  18. <div id="content-main" className="content-main container-lg">
  19. <div className="container">
  20. <div className="row justify-content-md-center">
  21. <div className="col-md-6 mt-5">
  22. <div className="text-center">
  23. <h1><i className="icon-lock-open large" /></h1>
  24. <h2 className="text-center">{ t('forgot_password.reset_password') }</h2>
  25. { errorCode == null && (
  26. <h3 className="text-muted">errorCode Unknown</h3>
  27. )}
  28. { errorCode === forgotPasswordErrorCode.PASSWORD_RESET_IS_UNAVAILABLE && (
  29. <h3 className="text-muted">{ t('forgot_password.feature_is_unavailable') }</h3>
  30. )}
  31. { (errorCode === forgotPasswordErrorCode.PASSWORD_RESET_ORDER_IS_NOT_APPROPRIATE || errorCode === forgotPasswordErrorCode.TOKEN_NOT_FOUND) && (
  32. <div>
  33. <div className="alert alert-warning mb-3">
  34. <h2>{ t('forgot_password.incorrect_token_or_expired_url') }</h2>
  35. </div>
  36. <Link href="/forgot-password" className="link-switch" prefetch={false}>
  37. <i className="icon-key"></i> { t('forgot_password.forgot_password') }
  38. </Link>
  39. </div>
  40. ) }
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. );
  48. };
  49. async function injectNextI18NextConfigurations(context: GetServerSidePropsContext, props: Props, namespacesRequired?: string[] | undefined): Promise<void> {
  50. const nextI18NextConfig = await getNextI18NextConfig(serverSideTranslations, context, namespacesRequired);
  51. props._nextI18Next = nextI18NextConfig._nextI18Next;
  52. }
  53. export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
  54. const result = await getServerSideCommonProps(context);
  55. // check for presence
  56. // see: https://github.com/vercel/next.js/issues/19271#issuecomment-730006862
  57. if (!('props' in result)) {
  58. throw new Error('invalid getSSP result');
  59. }
  60. const props: Props = result.props as Props;
  61. const errorCode = context.query.errorCode;
  62. if (typeof errorCode === 'string') {
  63. props.errorCode = errorCode as forgotPasswordErrorCode;
  64. }
  65. await injectNextI18NextConfigurations(context, props, ['translation']);
  66. return {
  67. props,
  68. };
  69. };
  70. export default ForgotPasswordErrorsPage;