+
setModalOpened(false)}>
+ {trashcanLoadStatus === "pending" ? (
+ 로딩중...
+ ) : (
+
+
{trashcanData?.address}
+
{trashcanData?.addressDetail}
+
{trashcanData?.createdAt}
+
{trashcanData?.status}
+
설명
+ {trashcanData?.description?.map((desc) =>
{desc}
)}
+
이미지
+
+ {trashcanData?.imageUrls?.map((url) => (
+

+ ))}
+
+
+ )}
+
쓰레기통 관리
+
-
+
{data &&
- data?.reportResponses &&
- data?.reportResponses.map((trashcan: any) => (
+ data?.trashcanListResponses &&
+ data?.trashcanListResponses.map((trashcan: TrashCanInfo) => (
))}
- {Array(data?.totalPages)
- .fill(0)
- .map((_, index) => (
+ {page > 9 && (
+
+ )}
+ {getPageArray().map((index) => (
+
+ ))}
+ {data?.totalPages &&
+ Math.floor(data.totalPages / 10) !== Math.floor(page / 10) && (
- ))}
+ )}
+
{
+ const num = Number(e.currentTarget.value);
+ if (!data?.totalPages) return;
+ if (e.key === "Enter" && num >= 0 && num <= data.totalPages) {
+ setPage(num - 1);
+ }
+ }}
+ />
);
}
diff --git a/src/app/api/auth/[...nextauth]/authoption.ts b/src/app/api/auth/[...nextauth]/authoption.ts
index b42e787..18f35d1 100644
--- a/src/app/api/auth/[...nextauth]/authoption.ts
+++ b/src/app/api/auth/[...nextauth]/authoption.ts
@@ -49,7 +49,6 @@ export const authOptions: AuthOptions = {
});
const result = await res.json();
-
if (res.ok && result) {
await setRefreshTokenCookie(res);
return result;
@@ -85,6 +84,7 @@ export const authOptions: AuthOptions = {
if (res.ok) {
await setRefreshTokenCookie(res);
const data = await res.json();
+
if (data) {
user.accessToken = data.accessToken;
user.jwtExpiredTime = data.jwtExpiredTime;
diff --git a/src/app/api/auth/[...nextauth]/setrtcookie.ts b/src/app/api/auth/[...nextauth]/setrtcookie.ts
index 47a62db..2a868e0 100644
--- a/src/app/api/auth/[...nextauth]/setrtcookie.ts
+++ b/src/app/api/auth/[...nextauth]/setrtcookie.ts
@@ -2,7 +2,7 @@ import { cookies } from "next/headers";
const setRefreshTokenCookie = async (res: Response) => {
const resCookie = res.headers.getSetCookie();
- console.log(resCookie);
+
if (!resCookie || !resCookie.length) return;
const cookie = resCookie[0]
.split(";")
@@ -11,6 +11,7 @@ const setRefreshTokenCookie = async (res: Response) => {
acc[key.trim()] = value;
return acc;
}, {} as any);
+ if (cookies().has("RefreshToken")) cookies().delete("RefreshToken");
cookies().set("RefreshToken", cookie.RefreshToken, { secure: true });
};
diff --git a/src/hooks/mutation/usenoticemutation.ts b/src/hooks/mutation/usenoticemutation.ts
index 361701b..4ec096f 100644
--- a/src/hooks/mutation/usenoticemutation.ts
+++ b/src/hooks/mutation/usenoticemutation.ts
@@ -14,10 +14,11 @@ const useNoticeMutation = ({
return useMutation({
mutationFn: async (input: NoticeResponse) => {
+ const fetchMethod = id ? "PATCH" : method;
const res = await fetch(
- `${APIURL}/api/notification${id ? `/${id}` : "/"}`,
+ `${APIURL}/api/notification${id ? `/${id}` : ""}`,
{
- method: id ? "PATCH" : method,
+ method: fetchMethod,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${session.data?.accessToken}`,
@@ -26,7 +27,7 @@ const useNoticeMutation = ({
},
);
const data = await res.json();
- console.log(data);
+
if (!res.ok) throw new Error(data.error);
return data;
},
diff --git a/src/hooks/query/query.ts b/src/hooks/query/query.ts
index 8018dca..a7d15db 100644
--- a/src/hooks/query/query.ts
+++ b/src/hooks/query/query.ts
@@ -6,17 +6,26 @@ import {
import { APIURL } from "@/util/const";
import { getSession } from "next-auth/react";
+type NoticeType = "ALL" | "UPDATED" | "EVENT" | "GENERAL";
+
interface MyTrashcanResponse {
totalPages: number;
trashcansResponses: TrashCanInfo[];
}
export const queryInfo = {
- notice: (page: number) => ({
- queryKey: ["notice", page],
+ notice: (page: number, notificationType: NoticeType) => ({
+ queryKey: ["notice", page, notificationType],
queryFn: async () => {
- const res = await fetch(`${APIURL}/api/notification?page=${page}`);
- if (!res.ok) return [];
+ const res = await fetch(
+ `${APIURL}/api/notification?page=${page}¬ificationType=${notificationType}`,
+ );
+
+ if (!res.ok)
+ return {
+ notificationInfoList: [],
+ totalPage: 0,
+ };
const data = await res.json();
return data;
},
@@ -41,27 +50,19 @@ export const queryInfo = {
info?.latitude ?? 0,
info?.longitude ?? 0,
info?.radius ?? 0,
- info?.status ?? "added",
+ info?.status ?? "ADDED",
info?.trashcanId ?? "",
],
queryFn: async () => {
if (!info) return [];
- const {
- latitude: lat,
- longitude: lng,
- radius,
- status,
- trashcanId: id,
- } = info;
+ const { latitude: lat, longitude: lng, radius, status } = info;
- const reqURL = id
- ? `${APIURL}/api/trashcans/locations/details/${id}`
- : `${APIURL}/api/trashcans/locations?${new URLSearchParams({
- latitude: lat.toString(),
- longitude: lng.toString(),
- radius: radius.toString(),
- status: status ?? "added",
- }).toString()}`;
+ const reqURL = `${APIURL}/api/trashcans/locations?${new URLSearchParams({
+ latitude: lat.toString(),
+ longitude: lng.toString(),
+ radius: radius.toString(),
+ status: status ?? "ADDED",
+ }).toString()}`;
const res = await fetch(reqURL, {
method: "GET",
@@ -70,12 +71,37 @@ export const queryInfo = {
"Access-Control-Allow-Origin": "*",
},
});
+
if (!res.ok) return [];
const data = await res.json();
return data;
},
}),
+ trashcaninfobyid: (trashcanId: string) => ({
+ queryKey: ["trashcaninfobyid", trashcanId],
+ queryFn: async () => {
+ if (!trashcanId)
+ return {
+ trashcanId: "",
+ status: "ADDED",
+ latitude: 0,
+ longitude: 0,
+ address: "",
+ addressDetail: "",
+ distance: 0,
+ };
+ const res = await fetch(
+ `${APIURL}/api/trashcans/locations/details/${trashcanId}`,
+ );
+ const data = await res.json();
+ return data;
+ },
+ onError: (e: any) => {
+ alert(e);
+ },
+ }),
+
myranking: {
queryKey: ["rank"],
queryFn: async () => {
@@ -118,7 +144,7 @@ export const queryInfo = {
queryFn: async () => {
const session = await getSession();
const response = await fetch(
- `${APIURL}/api/admin/trashcans?page=${page}&status=${status}${sort?.length ? `&sort=${sort}` : ``}`,
+ `${APIURL}/api/admin/trashcans?size=10&page=${page}&status=${status}${sort?.length ? `&sort=${sort}` : ``}`,
{
headers: {
Authorization: `Bearer ${session?.accessToken}`,
@@ -179,7 +205,6 @@ export const infiniteQueryInfo = {
);
const data = await res.json();
-
if (data?.message)
return {
totalPages: 0,
diff --git a/src/hooks/query/usenoticequery.ts b/src/hooks/query/usenoticequery.ts
index c4e1ed8..be5e12c 100644
--- a/src/hooks/query/usenoticequery.ts
+++ b/src/hooks/query/usenoticequery.ts
@@ -2,10 +2,10 @@ import { useQuery } from "@tanstack/react-query";
import { queryInfo } from "./query";
export const NoticeTypeDict = {
- all: "전체",
- updated: "업데이트",
- general: "일반",
- event: "이벤트",
+ ALL: "전체",
+ UPDATED: "업데이트",
+ GENERAL: "일반",
+ EVENT: "이벤트",
};
export type NoticeType = keyof typeof NoticeTypeDict;
@@ -21,8 +21,8 @@ export interface NoticePageResponse {
totalPage: number;
}
-const useNoticeQuery = (page: number) => {
- return useQuery
(queryInfo.notice(page));
+const useNoticeQuery = (page: number, notificationType: NoticeType) => {
+ return useQuery(queryInfo.notice(page, notificationType));
};
export default useNoticeQuery;
diff --git a/src/hooks/query/usetrashcaninfobyid.ts b/src/hooks/query/usetrashcaninfobyid.ts
new file mode 100644
index 0000000..8132247
--- /dev/null
+++ b/src/hooks/query/usetrashcaninfobyid.ts
@@ -0,0 +1,7 @@
+import { useQuery } from "@tanstack/react-query";
+import { TrashCanInfo } from "@/types/trashinfo";
+import { queryInfo } from "./query";
+
+export default function useTrashcanInfoByIdQuery(id: string) {
+ return useQuery(queryInfo.trashcaninfobyid(id));
+}