jam411 3 лет назад
Родитель
Сommit
5a93ec2708

+ 9 - 4
packages/app/src/components/Login/InvitedForm.tsx

@@ -3,10 +3,10 @@ import React from 'react';
 import { IUser } from '@growi/core';
 import { useTranslation } from 'next-i18next';
 
-import { useCsrfToken } from '../../stores/context';
+import { useCsrfToken, useCurrentUser } from '../../stores/context';
 
 type InvitedFormProps = {
-  currentUser: IUser,
+  user: IUser,
   invitedFormUsername?: string,
   invitedFormName?: string,
 }
@@ -14,8 +14,13 @@ type InvitedFormProps = {
 export const InvitedForm = (props: InvitedFormProps): JSX.Element => {
   const { t } = useTranslation();
   const { data: csrfToken } = useCsrfToken();
+  const { data: user } = useCurrentUser();
 
-  const { currentUser, invitedFormUsername, invitedFormName } = props;
+  const { invitedFormUsername, invitedFormName } = props;
+
+  if (user == null) {
+    return <></>;
+  }
 
   return (
     <div className="noLogin-dialog p-3 mx-auto" id="noLogin-dialog">
@@ -37,7 +42,7 @@ export const InvitedForm = (props: InvitedFormProps): JSX.Element => {
             disabled
             placeholder={t('Email')}
             name="invitedForm[email]"
-            defaultValue={currentUser.email}
+            defaultValue={user.email}
             required
           />
         </div>

+ 7 - 10
packages/app/src/pages/login/[[...path]].page.tsx

@@ -9,7 +9,7 @@ import { useRouter } from 'next/router';
 import { NoLoginLayout } from '~/components/Layout/NoLoginLayout';
 import { CrowiRequest } from '~/interfaces/crowi-request';
 
-import { useCsrfToken, useCurrentPathname } from '../../stores/context';
+import { useCsrfToken, useCurrentPathname, useCurrentUser } from '../../stores/context';
 import {
   CommonProps, getServerSideCommonProps, useCustomTitle, getNextI18NextConfig,
 } from '../utils/commons';
@@ -34,6 +34,7 @@ const LoginPage: NextPage<Props> = (props: Props) => {
 
   useCsrfToken(props.csrfToken);
   useCurrentPathname(props.currentPathname);
+  useCurrentUser(props.currentUser);
 
   const loginPagesMap = {
     login: {
@@ -49,7 +50,6 @@ const LoginPage: NextPage<Props> = (props: Props) => {
     },
     invited: {
       component: <InvitedForm
-        currentUser={props.currentUser}
         invitedFormUsername={props.invitedFormUsername}
         invitedFormName={props.invitedFormName}
       />,
@@ -75,11 +75,14 @@ const LoginPage: NextPage<Props> = (props: Props) => {
 
 async function injectServerConfigurations(context: GetServerSidePropsContext, props: Props): Promise<void> {
   const req: CrowiRequest = context.req as CrowiRequest;
-  const { crowi } = req;
+  const { crowi, body: invitedForm } = req;
   const { mailService, configManager } = crowi;
 
   props.isMailerSetup = mailService.isMailerSetup;
   props.registrationWhiteList = configManager.getConfig('crowi', 'security:registrationWhiteList');
+
+  props.invitedFormUsername = invitedForm.username;
+  props.invitedFormName = invitedForm.name;
 }
 
 function injectEnabledStrategies(context: GetServerSidePropsContext, props: Props): void {
@@ -113,7 +116,7 @@ async function injectNextI18NextConfigurations(context: GetServerSidePropsContex
 
 export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
   const req = context.req as CrowiRequest<IUserHasId & any>;
-  const { user, body: invitedForm } = req;
+  const { user } = req;
   const result = await getServerSideCommonProps(context);
 
   // check for presence
@@ -126,12 +129,6 @@ export const getServerSideProps: GetServerSideProps = async(context: GetServerSi
   if (user != null) {
     props.currentUser = user.toObject();
   }
-  if (invitedForm.username != null) {
-    props.invitedFormUsername = req.body.invitedForm.username;
-  }
-  if (invitedForm.name != null) {
-    props.invitedFormName = req.body.invitedForm.name;
-  }
 
   injectServerConfigurations(context, props);
   injectEnabledStrategies(context, props);