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

[feat] 어드민 유저 검색 관련 #136

Merged
merged 3 commits into from
Aug 23, 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
2 changes: 1 addition & 1 deletion packages/adminPage/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function App() {
<Route exact path="/events/:eventId/edit" element={<EventsEditPage />} />
<Route path="/events/:eventId" element={<EventsDetailPage />} />
<Route path="/events" element={<EventsPage />} />
<Route path="/comments/:eventId" element={<CommentsIDPage />} />
<Route path="/comments" element={<CommentsPage />} />
<Route path="/comments/:eventId" element={<CommentsIDPage />} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

왜 /comments/:eventId의 순서를 바꾸셨나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

처음에 /comments의 자식 route로 :eventId를 넣으려 했는데 저희 설계상 맞지 않아서 그냥 뺐는데 그 잔재입니다

<Route path="/users" element={<UsersPage />} />
</Route>
<Route path="/login" element={<LoginPage />} />
Expand Down
10 changes: 5 additions & 5 deletions packages/adminPage/src/features/users/Users.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { fetchServer } from "@common/dataFetch/fetchServer.js";
import Pagination from "@admin/components/Pagination";
import { useState } from "react";

export default function Comments({ searchString, category }) {
searchString;
export default function Comments({ searchParams }) {
const [page, setPage] = useState(1);
const data = useQuery(
"admin-users",
() =>
fetchServer(`/api/v1/admin/event-users?page=${page - 1}&search=${searchString}&size=15`)
fetchServer(
`/api/v1/admin/event-users?page=${page - 1}&search=${searchParams.get("search") ?? ""}&field=${searchParams.get("field") ?? "userName"}&size=15`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

searchParams을 잘 쓰시는군요

)
.then((res) => {
console.log(category);
return res;
})
.catch((e) => {
alert("통신 오류로 유저 목록 로드 실패.");
console.log(e);
return { users: [] };
}),
[page, searchString],
[page, searchParams],
);

return (
Expand Down
10 changes: 7 additions & 3 deletions packages/adminPage/src/features/users/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import Suspense from "@common/components/Suspense";
import Loading from "./Loading.jsx";
import Users from "./Users.jsx";
import { useState } from "react";
import { useSearchParams } from "react-router-dom";

export default function AdminCommentID() {
const [formString, setFormString] = useState("");
const [searchString, setSearchString] = useState("");
const [category, setCategory] = useState("name");
const [category, setCategory] = useState("userName");

const [searchParams, setSearchParams] = useSearchParams();

function searchComment(e) {
e.preventDefault();
setSearchString(formString);
setSearchParams({ search: formString, field: category });
}

return (
Expand All @@ -37,7 +41,7 @@ export default function AdminCommentID() {
onChange={(e) => setCategory(e.target.value)}
className="bg-transparent text-neutral-600"
>
<option value="name">성명</option>
<option value="userName">성명</option>
<option value="phoneNumber">전화번호</option>
<option value="frameId">FrameId</option>
</select>
Expand All @@ -58,7 +62,7 @@ export default function AdminCommentID() {
</div>

<Suspense fallback={<Loading />}>
<Users searchString={searchString} category={category} />
<Users searchParams={searchParams} setSearchParams={setSearchParams} />
</Suspense>
</div>
);
Expand Down