From d6e848845fdd9dae216e49cb7adec6ecbc30e4e2 Mon Sep 17 00:00:00 2001 From: seohee0112 Date: Mon, 12 Aug 2024 23:15:19 +0900 Subject: [PATCH 1/5] docs : mixpanel --- src/app/workbook/[id]/page.tsx | 10 +++---- .../components/ArticleBottomButton/indext.tsx | 10 +++---- src/article/components/ArticleTitle/index.tsx | 26 +++++++++---------- src/auth/hooks/useLogout.tsx | 3 +-- src/main/components/MainHeader/index.tsx | 2 +- src/problem/components/ProblemTitle/index.tsx | 13 ++++------ 6 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/app/workbook/[id]/page.tsx b/src/app/workbook/[id]/page.tsx index 3f1830a3..14aec1db 100644 --- a/src/app/workbook/[id]/page.tsx +++ b/src/app/workbook/[id]/page.tsx @@ -47,11 +47,11 @@ export default function WorkbookPage() { // usePathname 로 workbook id 받기 const pathname = usePathname(); const workbookId = getWorkbookId(pathname); - useTrackMixpanel({ - eventKey: EVENT_NAME.WORKBOOK_APPEAR, - property: { id: workbookId }, - dep: pathname, - }); + // useTrackMixpanel({ + // eventKey: EVENT_NAME.WORKBOOK_APPEAR, + // property: { id: workbookId }, + // dep: pathname, + // }); const { data: workbookInfo, isLoading } = useQuery({ ...getWorkbookQueryOptions(workbookId), diff --git a/src/article/components/ArticleBottomButton/indext.tsx b/src/article/components/ArticleBottomButton/indext.tsx index 3c324bec..28dc3421 100644 --- a/src/article/components/ArticleBottomButton/indext.tsx +++ b/src/article/components/ArticleBottomButton/indext.tsx @@ -5,9 +5,7 @@ import { useParams, useRouter } from "next/navigation"; import { HTMLAttributes } from "react"; import { Button } from "@shared/components/ui/button"; -import { EVENT_NAME } from "@shared/constants/mixpanel"; import { useProblemIdsViewModel } from "@shared/models/useProblemIdsViewModel"; -import { Mixpanel } from "@shared/utils/mixpanel"; interface ArticleBottomButtonProps extends HTMLAttributes {} export default function ArticleBottomButton({ @@ -18,10 +16,10 @@ export default function ArticleBottomButton({ const { getCurrentProblemId } = useProblemIdsViewModel(); const onClickGoProblem = () => { push(`/problem/${getCurrentProblemId()}`); - Mixpanel.track({ - name: EVENT_NAME.ARTICLE_PROBLEMBUTTON_TAPPED, - property: { id: articleId }, - }); + // Mixpanel.track({ + // name: EVENT_NAME.ARTICLE_PROBLEMBUTTON_TAPPED, + // property: { id: articleId }, + // }); }; return ( From 045616988174cc3f3e3809e2adad3b7de8466c68 Mon Sep 17 00:00:00 2001 From: seohee0112 Date: Mon, 12 Aug 2024 23:31:35 +0900 Subject: [PATCH 4/5] test : try catch --- src/shared/middlewares/auth.ts | 69 +++++++++++++++------------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/src/shared/middlewares/auth.ts b/src/shared/middlewares/auth.ts index f15fb67a..ad3afb3f 100644 --- a/src/shared/middlewares/auth.ts +++ b/src/shared/middlewares/auth.ts @@ -15,44 +15,37 @@ type authMiddlewareProps = { }; export const AuthMiddleware = async ({ req, nextUrl }: authMiddlewareProps) => { - try { - const { searchParams } = nextUrl; - const auth_token = searchParams.get(AUTH_TOKEN); - if (auth_token) { - const response: ApiResponse = await fewFetch().post( - API_ROUTE.TOKEN(auth_token), - ); - - const authData = response.data; - - if (authData?.message === "알 수 없는 오류가 발생했어요.") { - nextUrl.searchParams.delete(AUTH_TOKEN); - const response = NextResponse.redirect(nextUrl); - - // response.cookies.set(COOKIES.ACCESS_TOKEN, "false"); - response.cookies.set(ISLOGIN, "false"); - - return NextResponse.redirect(nextUrl); - } - if (authData?.data?.accessToken) { - const accessToken = authData.data.accessToken; - const memberEmail = tokenParse(accessToken).memberEmail; - - nextUrl.searchParams.delete(AUTH_TOKEN); - nextUrl.searchParams.set("member_email", memberEmail); - - const response = NextResponse.redirect(nextUrl); - - response.cookies.set(COOKIES.ACCESS_TOKEN, authData?.data?.accessToken); - response.cookies.set( - COOKIES.REFRESH_TOKEN, - authData?.data?.refreshToken, - ); - - return response; - } + const { searchParams } = nextUrl; + const auth_token = searchParams.get(AUTH_TOKEN); + if (auth_token) { + const response: ApiResponse = await fewFetch().post( + API_ROUTE.TOKEN(auth_token), + ); + + const authData = response.data; + + if (authData?.message === "알 수 없는 오류가 발생했어요.") { + nextUrl.searchParams.delete(AUTH_TOKEN); + const response = NextResponse.redirect(nextUrl); + + // response.cookies.set(COOKIES.ACCESS_TOKEN, "false"); + response.cookies.set(ISLOGIN, "false"); + + return NextResponse.redirect(nextUrl); + } + if (authData?.data?.accessToken) { + const accessToken = authData.data.accessToken; + const memberEmail = tokenParse(accessToken).memberEmail; + + nextUrl.searchParams.delete(AUTH_TOKEN); + nextUrl.searchParams.set("member_email", memberEmail); + + const response = NextResponse.redirect(nextUrl); + + response.cookies.set(COOKIES.ACCESS_TOKEN, authData?.data?.accessToken); + response.cookies.set(COOKIES.REFRESH_TOKEN, authData?.data?.refreshToken); + + return response; } - } catch { - return undefined; } }; From 7e7e03003e0993bf38bcf0760c89697941fc9098 Mon Sep 17 00:00:00 2001 From: soomin9106 Date: Fri, 16 Aug 2024 21:47:07 +0900 Subject: [PATCH 5/5] feat: workbook study button when user subscribes workbook --- .../components/WorkbookButton/index.tsx | 68 +++++++++++++++++-- src/workbook/constants/buttons.ts | 3 +- 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/workbook/components/WorkbookButton/index.tsx b/src/workbook/components/WorkbookButton/index.tsx index e23e0dfa..44d933d7 100644 --- a/src/workbook/components/WorkbookButton/index.tsx +++ b/src/workbook/components/WorkbookButton/index.tsx @@ -1,5 +1,7 @@ import { usePathname, useRouter, useSearchParams } from "next/navigation"; +import { useQueries } from "@tanstack/react-query"; + import queryClient from "@api/queryClient"; import useIsLogin from "@shared/hooks/useIsLogin"; @@ -7,7 +9,11 @@ import useIsLogin from "@shared/hooks/useIsLogin"; import { WORKBOOK_BTNS } from "@workbook/constants/buttons"; import { getWorkbookId } from "@workbook/utils"; +import { ENTIRE_CATEGORY } from "@main/constants"; +import { WorkbookCardModel } from "@main/models/WorkbookCardModel"; import { QUERY_KEY } from "@main/remotes"; +import { getSubscriptionWorkbooksQueryOptions } from "@main/remotes/getSubscriptionWorkbooksQueryOptions"; +import { getWorkbooksWithCategoryQueryOptions } from "@main/remotes/getWorkbooksWithCategoryQueryOptions"; import WorkbookButtonItem from "../\bWorkbookButtonItem"; import useSusbscribeWorkbook from "@common/hooks/useSusbscribeWorkbook"; @@ -20,7 +26,40 @@ export default function WorkbookButton() { const pathname = usePathname(); const workbookId = getWorkbookId(pathname); - const handleLoginClick = () => { + const workbookInfo = useQueries({ + queries: [ + getWorkbooksWithCategoryQueryOptions({ + code: ENTIRE_CATEGORY, + }), + { + ...getSubscriptionWorkbooksQueryOptions(), + enabled: isLogin === true, + }, + ], + combine: (result) => { + const [workbookServerList, workbookSubscriptionInfoList] = result; + + if (workbookServerList.data) { + const workbookCardModel = new WorkbookCardModel({ + initWorkbookSeverList: workbookServerList.data, + initWorkbookSubscriptionInfoList: workbookSubscriptionInfoList.data, + }); + + // 특정 워크북 ID에 따른 필터링 적용 + const targetWorkbookId = Number(workbookId); + const filteredWorkbookCombineList = + workbookCardModel.workbookCombineListData.filter( + (workbook) => workbook.id === targetWorkbookId, + ); + + return workbookCardModel.workbookCardList({ + workbookCombineList: filteredWorkbookCombineList, + }); + } + }, + }); + + const handleLoginSubClick = () => { postSubscribeWorkbook({ workbookId: workbookId.toString(), handleSucess: () => { @@ -38,13 +77,30 @@ export default function WorkbookButton() { router.push("/auth"); }; + const handleStudy = () => { + if (workbookInfo) { + router.push(`/article/${workbookInfo[0].articleId}?workbookId=${workbookId}`) + } + } + + console.log("workbookInfo ", workbookInfo); + return (
- {isLogin ? ( - + {isLogin && workbookInfo ? ( + <> + {workbookInfo[0].cardType === "SUBSCRIBE" ? ( + + ) : ( + + )} + ) : (