22
33import { format } from "date-fns" ;
44import type { ThirdwebClient } from "thirdweb" ;
5+ import type { WalletUser } from "thirdweb/wallets" ;
56import { WalletAddress } from "@/components/blocks/wallet-address" ;
67import { Badge } from "@/components/ui/badge" ;
78import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
@@ -11,14 +12,20 @@ import {
1112 TooltipProvider ,
1213 TooltipTrigger ,
1314} from "@/components/ui/tooltip" ;
14- import type { UserSearchResult } from "./types" ;
1515
16- const getUserIdentifier = ( user : UserSearchResult ) => {
17- return user . email ?? user . phone ?? user . walletAddress ?? user . userId ;
16+ const getUserIdentifier = ( user : WalletUser ) => {
17+ const mainDetail = user . linkedAccounts [ 0 ] ?. details ;
18+ return (
19+ mainDetail ?. email ??
20+ mainDetail ?. phone ??
21+ mainDetail ?. address ??
22+ mainDetail ?. id ??
23+ user . id
24+ ) ;
1825} ;
1926
2027export function SearchResults ( props : {
21- results : UserSearchResult [ ] ;
28+ results : WalletUser [ ] ;
2229 client : ThirdwebClient ;
2330} ) {
2431 if ( props . results . length === 0 ) {
@@ -38,93 +45,105 @@ export function SearchResults(props: {
3845
3946 return (
4047 < div className = "space-y-4" >
41- { props . results . map ( ( user ) => (
42- < Card key = { user . userId } >
43- < CardHeader >
44- < CardTitle className = "text-lg" > User Details</ CardTitle >
45- </ CardHeader >
46- < CardContent className = "space-y-4" >
47- < div className = "grid grid-cols-1 md:grid-cols-2 gap-4" >
48- < div >
49- < p className = "text-sm font-medium text-muted-foreground" >
50- User Identifier
51- </ p >
52- < p className = "text-sm" > { getUserIdentifier ( user ) } </ p >
53- </ div >
54-
55- < div >
56- < p className = "text-sm font-medium text-muted-foreground" >
57- Wallet Address
58- </ p >
59- < WalletAddress
60- address = { user . walletAddress }
61- client = { props . client }
62- />
63- </ div >
64-
65- { user . email && (
48+ { props . results . map ( ( user ) => {
49+ const walletAddress = user . wallets ?. [ 0 ] ?. address ;
50+ const createdAt = user . wallets ?. [ 0 ] ?. createdAt ;
51+ const mainDetail = user . linkedAccounts ?. [ 0 ] ?. details ;
52+ const email = mainDetail ?. email as string | undefined ;
53+ const phone = mainDetail ?. phone as string | undefined ;
54+
55+ return (
56+ < Card key = { user . id } >
57+ < CardHeader >
58+ < CardTitle className = "text-lg" > User Details</ CardTitle >
59+ </ CardHeader >
60+ < CardContent className = "space-y-4" >
61+ < div className = "grid grid-cols-1 md:grid-cols-2 gap-4" >
6662 < div >
6763 < p className = "text-sm font-medium text-muted-foreground" >
68- Email
64+ User Identifier
6965 </ p >
70- < p className = "text-sm" > { user . email } </ p >
66+ < p className = "text-sm" > { getUserIdentifier ( user ) } </ p >
7167 </ div >
72- ) }
7368
74- { user . phone && (
69+ { walletAddress && (
70+ < div >
71+ < p className = "text-sm font-medium text-muted-foreground" >
72+ Wallet Address
73+ </ p >
74+ < WalletAddress
75+ address = { walletAddress }
76+ client = { props . client }
77+ />
78+ </ div >
79+ ) }
80+
81+ { email && (
82+ < div >
83+ < p className = "text-sm font-medium text-muted-foreground" >
84+ Email
85+ </ p >
86+ < p className = "text-sm" > { email } </ p >
87+ </ div >
88+ ) }
89+
90+ { phone && (
91+ < div >
92+ < p className = "text-sm font-medium text-muted-foreground" >
93+ Phone
94+ </ p >
95+ < p className = "text-sm" > { phone } </ p >
96+ </ div >
97+ ) }
98+
99+ { createdAt && (
100+ < div >
101+ < p className = "text-sm font-medium text-muted-foreground" >
102+ Created
103+ </ p >
104+ < p className = "text-sm" >
105+ { format ( new Date ( createdAt ) , "MMM dd, yyyy" ) }
106+ </ p >
107+ </ div >
108+ ) }
109+
75110 < div >
76111 < p className = "text-sm font-medium text-muted-foreground" >
77- Phone
112+ Login Methods
78113 </ p >
79- < p className = "text-sm" > { user . phone } </ p >
80- </ div >
81- ) }
82-
83- < div >
84- < p className = "text-sm font-medium text-muted-foreground" >
85- Created
86- </ p >
87- < p className = "text-sm" >
88- { format ( new Date ( user . createdAt ) , "MMM dd, yyyy" ) }
89- </ p >
90- </ div >
91-
92- < div >
93- < p className = "text-sm font-medium text-muted-foreground" >
94- Login Methods
95- </ p >
96- < div className = "flex flex-wrap gap-1" >
97- { user . linkedAccounts . map ( ( account , index ) => (
98- < TooltipProvider
99- key = { `${ user . userId } -${ account . type } -${ index } ` }
100- >
101- < Tooltip >
102- < TooltipTrigger >
103- < Badge variant = "secondary" className = "text-xs" >
104- { account . type }
105- </ Badge >
106- </ TooltipTrigger >
107- < TooltipContent >
108- < div className = "text-sm space-y-1" >
109- { Object . entries ( account . details ) . map (
110- ( [ key , value ] ) => (
111- < div key = { key } >
112- < span className = "font-medium" > { key } :</ span > { " " }
113- { String ( value ) }
114- </ div >
115- ) ,
116- ) }
117- </ div >
118- </ TooltipContent >
119- </ Tooltip >
120- </ TooltipProvider >
121- ) ) }
114+ < div className = "flex flex-wrap gap-1" >
115+ { user . linkedAccounts ?. map ( ( account , index ) => (
116+ < TooltipProvider
117+ key = { `${ user . id } -${ account . type } -${ index } ` }
118+ >
119+ < Tooltip >
120+ < TooltipTrigger >
121+ < Badge variant = "secondary" className = "text-xs" >
122+ { account . type }
123+ </ Badge >
124+ </ TooltipTrigger >
125+ < TooltipContent >
126+ < div className = "text-sm space-y-1" >
127+ { Object . entries ( account . details ) . map (
128+ ( [ key , value ] ) => (
129+ < div key = { key } >
130+ < span className = "font-medium" > { key } :</ span > { " " }
131+ { String ( value ) }
132+ </ div >
133+ ) ,
134+ ) }
135+ </ div >
136+ </ TooltipContent >
137+ </ Tooltip >
138+ </ TooltipProvider >
139+ ) ) }
140+ </ div >
122141 </ div >
123142 </ div >
124- </ div >
125- </ CardContent >
126- </ Card >
127- ) ) }
143+ </ CardContent >
144+ </ Card >
145+ ) ;
146+ } ) }
128147 </ div >
129148 ) ;
130149}
0 commit comments