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

다락방 초대링크 입력해서 들어가는 경우 내 다락방으로 제대로 가지지 않는 버그 수정 #440

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions frontend/src/apis/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ export const postDarakbangEntrance = async ({
code: string;
nickname: string;
}) => {
await ApiClient.postWithAuth('/darakbang/entrance?code=' + code, {
nickname,
});
const data = await ApiClient.postWithAuth(
'/darakbang/entrance?code=' + code,
{
nickname,
},
);

const json = await data.json();

return json.data as number;
};
4 changes: 3 additions & 1 deletion frontend/src/hooks/mutaions/useEnterDarakbang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
import { ApiError } from '@_utils/customError/ApiError';
import QUERY_KEYS from '@_constants/queryKeys';
import { postDarakbangEntrance } from '@_apis/posts';
import { setLastDarakbangId } from '@_common/lastDarakbangManager';

export default function useEnterDarakbang({
onSuccess,
Expand All @@ -16,7 +17,8 @@ export default function useEnterDarakbang({
return useMutation({
mutationFn: ({ code, nickname }: { code: string; nickname: string }) =>
postDarakbangEntrance({ code, nickname }),
onSuccess: () => {
onSuccess: (darakbangId) => {
setLastDarakbangId(darakbangId);
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.myDarakbangs] });

if (onSuccess) onSuccess();
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/routes/DarakbangInvitationRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { removeInviteCode, setInviteCode } from '@_common/inviteCodeManager';

import Button from '@_components/Button/Button';
import CompleteLayout from '@_layouts/CompleteLayout/CompleteLayout';
import GET_ROUTES from '@_common/getRoutes';
import MissingFallback from '@_components/MissingFallback/MissingFallback';
import ROUTES from '@_constants/routes';
import useDarakbangNameByCode from '@_hooks/queries/useDarakbangNameByCode';
Expand All @@ -13,12 +12,12 @@ export default function DarakbangInvitationRoute() {
const navigate = useNavigate();

const code = searchParam.get('code');
const { darakbangName, isLoading } = useDarakbangNameByCode(code || '');
if (isLoading) return null;
const { darakbangName } = useDarakbangNameByCode(code || '');
const isRightCode = darakbangName && darakbangName !== '';
if (darakbangName === undefined) return null;
if (isRightCode) {
if (code) setInviteCode(code);
return <Navigate to={GET_ROUTES.nowDarakbang.main()} replace />;
return <Navigate to={ROUTES.darakbangNickname} replace />;
}
if (!isRightCode) {
removeInviteCode();
Expand Down
Loading