Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dep 167 Add flow of invitation #122

Merged
merged 5 commits into from
Jun 29, 2023
Merged

Dep 167 Add flow of invitation #122

merged 5 commits into from
Jun 29, 2023

Conversation

hyehyeonmoon
Copy link
Collaborator

@hyehyeonmoon hyehyeonmoon commented Jun 28, 2023

⛳️ Task

  • 초대 코드 검사 및 행성 가입 api를 추가합니다.
  • mock을 추가합니다.
  • 사용자의 로그인여부를 파악하기 위해 함수를 수정합니다.
  • 초대 페이지를 생성합니다.
  • 초대 페이지 스타일을 추가합니다.

✍️ Note

  • 에러 처리는 추후 진행할 예정입니다.
  • 비로그인 사용자가 회원가입 후 다시 기존 페이지로 돌아오는 로직은 추후 진행할 예정입니다.

⚡️ Test

pnpm msw // 실행
  • 비로그인

/invitation/1로 들어옴 -> 초대 수락하기 버튼 클릭 -> /auth/signin으로 전환

Jun-29-2023.00-34-18.mp4
  • 로그인 + 캐릭터 생성이 되어 있다 가정 ( /auth/signin 에서 로그인 후 실행)

/invitation/1로 들어옴 -> 초대 수락하기 버튼 클릭 -> /planet/id으로 전환

Jun-29-2023 00-33-12

📎 Reference

초대 flow miro

@hyehyeonmoon hyehyeonmoon added the feat 기능 (새로운 기능) label Jun 28, 2023
@hyehyeonmoon hyehyeonmoon added this to the v1.0.0 milestone Jun 28, 2023
@hyehyeonmoon hyehyeonmoon requested a review from a team June 28, 2023 15:32
@hyehyeonmoon hyehyeonmoon self-assigned this Jun 28, 2023
@github-actions
Copy link

Copy link
Collaborator Author

@hyehyeonmoon hyehyeonmoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invitation page 에서 진행되는 부분들을 middleware 에서 진행하려 했으나
middleware에서는 error page를 띄워주지 못하기 때문에 client page component로 구현했습니다.

<h1>{title}</h1>
</Template.Title>
<Template.Content />
<Template.Button disabled={isInitialLoading || isRefetching} onClick={onClick}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용자의 데이터를 가져오는 동안 button을 비활성화 합니다.
enabled option 이 걸릴 경우, isLoading: true 로 반환됩니다. (참고 : issue)
따라서 이에 대한 방안책으로 isInitialLoading || isRefetching을 사용합니다.

Comment on lines +34 to +48
const onClick = async () => {
const searchParams = new URLSearchParams({
redirectUri: `/invitation/${invitationCode}`,
}).toString();
if (planetId && userId) {
await mutateAsync({ planetId, userId });
if (userInfo?.isCharacterCreated) {
router.push(`/planet/${planetId}`);
} else {
router.push(`/onboarding?${searchParams}`);
}
} else {
router.push(`/auth/signin?${searchParams}`);
}
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래 flow를 구현했습니다.
image

const title = '당신을 디프만 행성으로\n 초대합니다';

const InvitationPage = ({ params }: { params: { code: string } }) => {
const router = useRouter();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useRouter 를 사용하기 위해서 client component 로 선언했습니다.

Comment on lines -4 to +11
export const getUserIdClient = (): number => {
export const getUserIdClient = (): number | undefined => {
try {
if (typeof document === 'undefined') throw new UserIdNotFoundError();
const { userId } = getAuthTokensByCookie(document.cookie);
if (userId !== undefined) return userId;
throw new UserIdNotFoundError();
throw new UserIdNotFoundError(); // 비로그인한 사용자의 경우
} catch (e) {
return -1;
return undefined;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용자의 로그인 여부를 에러 없이 순수하게 알아내기 위해 사용합니다.
예) 로그인 사용자, 비로그인 사용자 모두 초대코드를 들고 입장할 수 있으며 해당 페이지에서 로그인 여부를 구분을 해주어야 합니다
-1 보다 undefined 가 처리하기 용이할 것 같아 수정했습니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 보다 undefined가 왜 처리가 용이한지 궁금합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로그인 여부를 -1 로 주게 된다면 아래와 같은 코드가 나올 것 같았어요.

const userId = getUserId();
if(userId === NOT_LOGIN)

이것보다 아래와 같이 사용하는 게 편하다고 생각했습니다.

const userId = getUserId();
if(!userId)

cookie에서 가져오는 값이기 때문에 -1이라는 임의의 숫자보다는 undefined 가 의미상 더 맞다고 생각되었어요. (확실히 하려면 null 이긴 하지만...)

저의 개인적인 생각일 뿐입니다!

Comment on lines +16 to +23
export type InvitationCodeValidationModel = {
planetId: number;
};

export type PlanetJoinModel = {
userId: number;
planetId: number;
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 api 명세가 나오지 않아 임의로 구현해 놓았습니다.

Comment on lines +38 to +47
export const getInvitationCodeIsValid = async (invitationCode: string) => {
return await publicApi.get<InvitationCodeValidationResponse>(`/invitation/${invitationCode}`);
};

export const useGetInvitationCodeIsValid = (invitationCode: string) =>
useQuery(userQueryKey.invitationCodeIsValid(), () => getInvitationCodeIsValid(invitationCode));

export const postPlanetJoin = async (body: PlanetJoinRequest) => {
return await privateApi.post<InvitationCodeValidationResponse>(`/join/planet`, body);
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public api가 한 파일(api.ts)에서 private api와 함께 선언되고 서버 컴포넌트에서 함께 사용(invitation page)되어도 문제없는 것을 확인했습니다.

@hyehyeonmoon hyehyeonmoon changed the title [Draft]Dep 167 Add flow of invitation Dep 167 Add flow of invitation Jun 28, 2023
@hyehyeonmoon hyehyeonmoon marked this pull request as ready for review June 28, 2023 15:46
@hyehyeonmoon hyehyeonmoon requested review from a team and 99-zziy and removed request for a team June 28, 2023 16:23
@99-zziy
Copy link
Member

99-zziy commented Jun 29, 2023

msw로 동작 확인했습니다! 그런데 로그인은 되는것 같은데 콜백 페이지?로 넘어간 후에 액션이 없네요.. 저만 그럴까요? 👀

@hyehyeonmoon
Copy link
Collaborator Author

어? 저는 로그인 페이지에서 콜백 페이지로 넘어가고 다시 main 페이지로 돌아왔었습니다...
흠... 우선 한 번 더 그런 일이 발생하면 이슈로 올리는 게 좋을 것 같아요. 저도 예의주시하겠습니다.

@hyehyeonmoon hyehyeonmoon merged commit 47e5adb into main Jun 29, 2023
@hyehyeonmoon hyehyeonmoon deleted the DEP-167-invitation-flow branch June 29, 2023 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat 기능 (새로운 기능)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants