11"use client" ;
22
3+ import { useState } from "react" ;
4+ import { useQueryClient } from "@tanstack/react-query" ;
35import classNames from "classnames/bind" ;
46
57import { Button , Flex , TextField , Typography } from "@permit/design-system" ;
8+ import { useTextField } from "@permit/design-system/hooks" ;
9+ import { userOptions } from "@/data/admin/getUser/queries" ;
10+ import { UserResponse } from "@/data/admin/getUser/types" ;
611import { useModal } from "@/shared/hooks/useModal" ;
12+ import { isAxiosErrorResponse } from "@/shared/types/axioxError" ;
713
814import { ChangeRoleModal } from "../ChangeRoleModal" ;
915import styles from "./index.module.scss" ;
1016
1117const cx = classNames . bind ( styles ) ;
1218
1319export const UserManagementClient = ( ) => {
14- const { show } = useModal ( ChangeRoleModal ) ;
20+ const qc = useQueryClient ( ) ;
21+ const { show : changeUserRoleModal } = useModal ( ChangeRoleModal ) ;
1522
16- const searchUser = ( ) => {
17- alert ( "hi" ) ;
23+ const [ userInfo , setUserInfo ] = useState < UserResponse | null > ( null ) ;
24+
25+ const userEmail = useTextField ( {
26+ initialValue : "" ,
27+ validate : ( value : string ) => {
28+ if ( ! value . trim ( ) ) return "유저 이메일을 입력해주세요." ;
29+
30+ return undefined ;
31+ } ,
32+ } ) ;
33+
34+ const searchUser = async ( ) => {
35+ const userEmailValid = userEmail . validateValue ( ) ;
36+
37+ if ( ! userEmailValid ) {
38+ return ;
39+ }
40+
41+ try {
42+ const userInfoData = await qc . fetchQuery ( userOptions ( { email : userEmail . value } ) ) ;
43+
44+ setUserInfo ( userInfoData ) ;
45+ } catch ( error ) {
46+ if ( isAxiosErrorResponse ( error ) ) {
47+ setUserInfo ( null ) ;
48+
49+ alert ( error . response ?. data . message || "유저를 찾을 수 없습니다." ) ;
50+ }
51+ }
1852 } ;
1953
2054 return (
@@ -27,23 +61,34 @@ export const UserManagementClient = () => {
2761 </ header >
2862 < main >
2963 < Flex gap = { 20 } >
30- < TextField className = { cx ( "input" ) } placeholder = "이메일을 입력해주세요" />
64+ < TextField
65+ className = { cx ( "input" ) }
66+ placeholder = "이메일을 입력해주세요"
67+ value = { userEmail . value }
68+ onChange = { userEmail . handleChange }
69+ error = { userEmail . error }
70+ />
3171 < Button variant = "cta" onClick = { searchUser } >
3272 Search
3373 </ Button >
3474 </ Flex >
3575
36- < div className = { cx ( "serach_area" ) } >
37- < Flex justify = "space-between" >
38- < Flex direction = "column" >
39- < Typography type = "title20" > userName: hi</ Typography >
40- < Typography type = "title20" > current Role: USER</ Typography >
76+ { userInfo && (
77+ < div className = { cx ( "serach_area" ) } >
78+ < Flex justify = "space-between" >
79+ < Flex direction = "column" >
80+ < Typography type = "title20" > userName: { userInfo . userName } </ Typography >
81+ < Typography type = "title20" > current Role: { userInfo . currentUserRole } </ Typography >
82+ </ Flex >
83+ < Button
84+ variant = "primary"
85+ onClick = { ( ) => changeUserRoleModal ( { userId : userInfo . userId } ) }
86+ >
87+ Change Role
88+ </ Button >
4189 </ Flex >
42- < Button variant = "primary" onClick = { show } >
43- Change Role
44- </ Button >
45- </ Flex >
46- </ div >
90+ </ div >
91+ ) }
4792 </ main >
4893 </ div >
4994 ) ;
0 commit comments