Skip to content

Commit 81531db

Browse files
authored
Merge pull request #20 from wepp-store/feature/wepp-event-log-install-tracking
Feature / wepp event log install tracking
2 parents 859f97f + 81c472e commit 81531db

File tree

25 files changed

+798
-48
lines changed

25 files changed

+798
-48
lines changed

package-lock.json

Lines changed: 325 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"react-hook-form": "^7.52.1",
3333
"react-hot-toast": "^2.4.1",
3434
"react-intersection-observer": "^9.13.0",
35+
"recharts": "^2.15.3",
3536
"tailwindcss": "^3.4.4",
3637
"yup": "^1.4.0",
3738
"zustand": "^4.5.4"

src/app/(end-user)/wepps/[weppId]/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export default async function Page({ params }: Props) {
6262
await queryClient.prefetchQuery(
6363
weppDetailOptions({
6464
weppId: params.weppId,
65-
read: true,
6665
gcTime: Infinity,
6766
staleTime: Infinity,
6867
})

src/app/api/refresh/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { axiosInstance } from '@/shared/apis/axios';
22
import { PATH_API } from '@/shared/apis/path';
3+
import { STORAGE_KEYS } from '@/shared/constants';
34
import { cookies } from 'next/headers';
45

56
function jwtDecode(token: string) {
@@ -23,7 +24,7 @@ export async function POST(req: Request) {
2324

2425
const { exp, iat } = jwtDecode(data.accessToken);
2526

26-
cookieStore.set('weppstore_token', data.accessToken, {
27+
cookieStore.set(STORAGE_KEYS.TOKEN.ACCESS, data.accessToken, {
2728
httpOnly: true,
2829
secure: process.env.NODE_ENV === 'production',
2930
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',

src/app/api/sign-in/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { axiosInstance } from '@/shared/apis/axios';
22
import { PATH_API } from '@/shared/apis/path';
3+
import { STORAGE_KEYS } from '@/shared/constants';
34
import { cookies } from 'next/headers';
45

56
function jwtDecode(token: string) {
@@ -25,14 +26,14 @@ export async function POST(req: Request) {
2526
const decodedAccessToken = jwtDecode(data.accessToken);
2627
const decodedRefreshToken = jwtDecode(data.refreshToken);
2728

28-
cookieStore.set('weppstore_token', data.accessToken, {
29+
cookieStore.set(STORAGE_KEYS.TOKEN.ACCESS, data.accessToken, {
2930
httpOnly: true,
3031
secure: process.env.NODE_ENV === 'production',
3132
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
3233
maxAge: remainingSeconds(decodedAccessToken) || 0,
3334
});
3435

35-
cookieStore.set('weppstore_refresh_token', data.refreshToken, {
36+
cookieStore.set(STORAGE_KEYS.TOKEN.REFRESH, data.refreshToken, {
3637
httpOnly: true,
3738
secure: process.env.NODE_ENV === 'production',
3839
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',

src/features/delete-wepp/ui/delete-wepp-button.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ const DeleteWeppButton = () => {
1717

1818
return (
1919
<>
20-
<Button color="danger" variant="bordered" onPress={onOpenChange}>
20+
<Button
21+
color="danger"
22+
variant="bordered"
23+
onPress={onOpenChange}
24+
radius="sm"
25+
>
2126
삭제하기
2227
</Button>
2328

src/shared/apis/path.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ export const PATH_API = {
2424
},
2525
WEPP: {
2626
ROOT: '/wepp',
27+
DETAIL: (weppId: string) => `/wepp/${weppId}` as const,
2728
MINE_LIST: '/wepp/mine-list',
2829
MINE: (weppId: string) => `/wepp/mine/${weppId}` as const,
2930
SUBMIT: '/wepp/submit',
3031
VERIFY: '/wepp/verify',
3132
UPLOAD: '/wepp/upload',
3233
CLEAR_URL: '/wepp/clear-url',
34+
EVENT_LOG: '/wepp/event',
3335
},
3436
COMMENT: {
3537
ROOT: '/comments',
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {
2+
useQuery,
3+
UseQueryResult,
4+
UseQueryOptions,
5+
} from '@tanstack/react-query';
6+
import { AxiosError } from 'axios';
7+
import { PATH_API } from '../../path';
8+
import { axiosInstance } from '../../axios';
9+
import { weppKeys } from './query-key-factory';
10+
import { notFound } from 'next/navigation';
11+
12+
type Props = {
13+
weppId: string;
14+
from?: string;
15+
to?: string;
16+
} & Omit<UseQueryOptions, 'queryKey'>;
17+
18+
interface ResponseType {
19+
date: string;
20+
devicePlatform: string;
21+
deviceType: string;
22+
view: number;
23+
install: number;
24+
}
25+
26+
export const useEventLogs = ({ weppId, from, to, ...other }: Props) => {
27+
return useQuery({
28+
queryKey: weppKeys.eventLogs(weppId, from, to),
29+
queryFn: async () => {
30+
try {
31+
const response = await axiosInstance.get(PATH_API.WEPP.EVENT_LOG, {
32+
params: {
33+
wepp_id: weppId,
34+
from,
35+
to,
36+
},
37+
});
38+
39+
return response.data;
40+
} catch (error: any) {
41+
if (error.statusCode === 404) {
42+
return notFound();
43+
}
44+
45+
throw error;
46+
}
47+
},
48+
enabled: !!weppId,
49+
staleTime: Infinity,
50+
gcTime: Infinity,
51+
...other,
52+
}) as UseQueryResult<ResponseType[], AxiosError>;
53+
};

src/shared/apis/queries/wepp/query-key-factory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export const weppKeys = {
55
detail: (weppId: string) => [...weppKeys.all, weppId] as const,
66
mineList: [PATH_API.WEPP.MINE_LIST] as const,
77
mine: (weppId: string) => [...weppKeys.mineList, weppId] as const,
8+
eventLogs: (weppId: string, from?: string, to?: string) =>
9+
[...weppKeys.all, PATH_API.WEPP.EVENT_LOG, weppId, from, to] as const,
810
};

src/shared/apis/queries/wepp/wepp-detail.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,16 @@ import { notFound } from 'next/navigation';
1212

1313
type Props = {
1414
weppId: string;
15-
read?: boolean;
1615
} & Omit<UseQueryOptions, 'queryKey'>;
1716

1817
export const weppDetailOptions = ({
1918
weppId,
20-
read = false,
2119
...other
2220
}: Props): UseQueryOptions => ({
2321
queryKey: weppKeys.detail(weppId),
2422
queryFn: async () => {
2523
try {
26-
const response = await axiosInstance.get(
27-
`${PATH_API.WEPP.ROOT}/${weppId}`,
28-
{
29-
headers: {
30-
'X-WEPP-READ': read,
31-
// TODO: 작동하나?
32-
'Cache-Control': 'max-age=3600, must-revalidate', // 1시간 동안 캐시 유지
33-
},
34-
}
35-
);
24+
const response = await axiosInstance.get(PATH_API.WEPP.DETAIL(weppId));
3625
return response.data;
3726
} catch (error: any) {
3827
if (error.statusCode === 404) {
@@ -45,8 +34,9 @@ export const weppDetailOptions = ({
4534
...other,
4635
});
4736

48-
export const useWeppDetail = ({ weppId, read = false, ...other }: Props) => {
49-
return useQuery(
50-
weppDetailOptions({ weppId, read, ...other })
51-
) as UseQueryResult<IWepp, AxiosError>;
37+
export const useWeppDetail = ({ weppId, ...other }: Props) => {
38+
return useQuery(weppDetailOptions({ weppId, ...other })) as UseQueryResult<
39+
IWepp,
40+
AxiosError
41+
>;
5242
};

0 commit comments

Comments
 (0)