reset-password.page.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 dynamic from 'next/dynamic';
  6. import {
  7. CommonProps, getNextI18NextConfig, getServerSideCommonProps,
  8. } from './utils/commons';
  9. type Props = CommonProps & {
  10. email: string
  11. };
  12. const PasswordResetExecutionForm = dynamic(() => import('~/components/PasswordResetExecutionForm'), { ssr: false });
  13. const ForgotPasswordPage: NextPage<Props> = (props: Props) => {
  14. const { t } = useTranslation();
  15. return (
  16. <div id="main" className="main">
  17. <div id="content-main" className="content-main 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><i className="icon-lock-open large"></i></h1>
  23. <h2 className="text-center">{ t('forgot_password.reset_password') }</h2>
  24. <h5>{ props.email }</h5>
  25. <p className="mt-4">{ t('forgot_password.password_reset_excecution_desc') }</p>
  26. <PasswordResetExecutionForm />
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. );
  34. };
  35. // eslint-disable-next-line max-len
  36. async function injectNextI18NextConfigurations(context: GetServerSidePropsContext, props: Props, namespacesRequired?: string[] | undefined): Promise<void> {
  37. const nextI18NextConfig = await getNextI18NextConfig(serverSideTranslations, context, namespacesRequired);
  38. props._nextI18Next = nextI18NextConfig._nextI18Next;
  39. }
  40. export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
  41. const result = await getServerSideCommonProps(context);
  42. // check for presence
  43. // see: https://github.com/vercel/next.js/issues/19271#issuecomment-730006862
  44. if (!('props' in result)) {
  45. throw new Error('invalid getSSP result');
  46. }
  47. const props: Props = result.props as Props;
  48. const email = context.query.email;
  49. if (typeof email === 'string') {
  50. props.email = email;
  51. }
  52. await injectNextI18NextConfigurations(context, props, ['translation', 'commons']);
  53. return {
  54. props,
  55. };
  56. };
  57. export default ForgotPasswordPage;