forgot-password-errors.page.tsx 3.2 KB

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