فهرست منبع

refs 113224: change UserInfo type

Futa Arai 3 سال پیش
والد
کامیت
36b9530f3b

+ 0 - 1
packages/app/.env.development

@@ -18,7 +18,6 @@ HACKMD_URI_FOR_SERVER="http://hackmd:3000"
 OGP_URI="http://ogp:8088"
 GROWI_QUESTIONNAIRE_SERVER_ORIGIN="http://host.docker.internal:3003"
 GROWI_QUESTIONNAIRE_SERVER_ORIGIN_CLIENT_SIDE="http://localhost:3003"
-AUTO_INSTALL_ALLOW_GUEST_MODE=true
 # DRAWIO_URI="http://localhost:8080/?offline=1&https=0"
 # S2SMSG_PUBSUB_SERVER_TYPE=nchan
 # PUBLISH_OPEN_API=true

+ 9 - 6
packages/app/src/components/Questionnaire/QuestionnaireModal.tsx

@@ -11,7 +11,7 @@ import { IAnswer } from '~/interfaces/questionnaire/answer';
 import { IGrowiInfo } from '~/interfaces/questionnaire/growi-info';
 import { IQuestionnaireAnswer } from '~/interfaces/questionnaire/questionnaire-answer';
 import { IQuestionnaireOrderHasId } from '~/interfaces/questionnaire/questionnaire-order';
-import { IUserInfo } from '~/interfaces/questionnaire/user-info';
+import { IUserInfo, UserType } from '~/interfaces/questionnaire/user-info';
 import { useCurrentUser, useGrowiVersion } from '~/stores/context';
 import { useQuestionnaireModal } from '~/stores/modal';
 import axios from '~/utils/axios';
@@ -62,11 +62,14 @@ const QuestionnaireModal = ({ questionnaireOrder, growiQuestionnaireServerOrigin
 
   // TODO: モック化されている箇所を実装
   const getUserInfo = useCallback((): IUserInfo => {
-    return {
-      userIdHash: '542bcc3bc5bc61b840017a18',
-      type: currentUser?.admin ? 'admin' : 'general',
-      userCreatedAt: currentUser?.createdAt || new Date(),
-    };
+    if (currentUser) {
+      return {
+        userIdHash: '542bcc3bc5bc61b840017a18',
+        type: currentUser?.admin ? UserType.admin : UserType.general,
+        userCreatedAt: currentUser?.createdAt,
+      };
+    }
+    return { type: UserType.guest };
   }, [currentUser]);
 
   const sendQuestionnaireAnswer = useCallback(async(questionnaireAnswer: IQuestionnaireAnswer) => {

+ 6 - 3
packages/app/src/interfaces/questionnaire/user-info.ts

@@ -1,9 +1,12 @@
-export const UserType = { admin: 'admin', general: 'general' } as const;
+export const UserType = { admin: 'admin', general: 'general', guest: 'guest' } as const;
 
+type guestType = typeof UserType.guest
 export type UserType = typeof UserType[keyof typeof UserType];
 
-export interface IUserInfo {
+export type IUserInfo = {
   userIdHash: string // userId hash generated by using appSiteUrl as salt
-  type: UserType
+  type: Omit<UserType, guestType>
   userCreatedAt: Date // createdAt of user that answered the questionnaire
+} | {
+  type: guestType
 }