From f243b7180b61f384e81c46a4f2e620e8e2f6757a Mon Sep 17 00:00:00 2001 From: kongkx Date: Tue, 8 Sep 2026 12:48:37 +0800 Subject: [PATCH] fix(users): surface composed profile errors --- src/features/users/user-detail-sheet.tsx | 149 ++++------------------- 1 file changed, 23 insertions(+), 126 deletions(-) diff --git a/src/features/users/user-detail-sheet.tsx b/src/features/users/user-detail-sheet.tsx index 92ee8a5..2a7dde2 100644 --- a/src/features/users/user-detail-sheet.tsx +++ b/src/features/users/user-detail-sheet.tsx @@ -7,14 +7,12 @@ import { GraduationCap, MapPin, Shield, - Star, Tag, User, Wrench, XCircle, } from 'lucide-react' import { fetchUserDetail, fetchUserInfo, fetchUserServices } from '@/api/modules/users' -import { fetchExcProvider } from '@/api/modules/exc' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' @@ -44,53 +42,20 @@ export function UserDetailSheet({ uid, onClose, onAssignRoles }: UserDetailSheet // 2. Full user profile, careers, educations, honors, addresses (GET /api/admin/v1/users/{uid}/info) const userInfoQuery = useQuery({ queryKey: ['user-info', uid], - queryFn: async () => { - if (!uid) return null - try { - const res = await fetchUserInfo(uid) - return res.data - } catch { - return null - } - }, + queryFn: async () => (uid ? (await fetchUserInfo(uid)).data : null), enabled: uid !== null, }) // 3. User provided services (GET /api/admin/v1/users/{uid}/services) const userServicesQuery = useQuery({ queryKey: ['user-services', uid], - queryFn: async () => { - if (!uid) return null - try { - const res = await fetchUserServices(uid) - return res.data - } catch { - return null - } - }, + queryFn: async () => (uid ? (await fetchUserServices(uid)).data : null), enabled: uid !== null, }) - // 4. Provider profile query (GET /api/admin/v1/exc/providers/{uid}) - const providerQuery = useQuery({ - queryKey: ['exc-provider', uid], - queryFn: async () => { - if (!uid) return null - try { - const res = await fetchExcProvider(uid) - return res.data - } catch { - return null - } - }, - enabled: uid !== null, - retry: false, - }) - const user = userQuery.data?.data const userInfo = userInfoQuery.data const userServices = userServicesQuery.data?.expertises ?? [] - const provider = providerQuery.data return ( !open && onClose()}> @@ -121,6 +86,13 @@ export function UserDetailSheet({ uid, onClose, onAssignRoles }: UserDetailSheet {userQuery.isPending ? (
加载中…
+ ) : userQuery.isError ? ( +
+

用户账号加载失败。

+ +
) : !user ? (
未找到用户信息
) : ( @@ -280,6 +252,13 @@ export function UserDetailSheet({ uid, onClose, onAssignRoles }: UserDetailSheet {userInfoQuery.isPending ? (
加载个人资料中…
+ ) : userInfoQuery.isError ? ( +
+

个人资料加载失败。

+ +
) : ( <> {/* Profile Headline & Bio */} @@ -463,6 +442,13 @@ export function UserDetailSheet({ uid, onClose, onAssignRoles }: UserDetailSheet {userServicesQuery.isPending ? (
加载服务事项中…
+ ) : userServicesQuery.isError ? ( +
+

服务事项加载失败。

+ +
) : userServices.length > 0 ? (

@@ -550,57 +536,6 @@ export function UserDetailSheet({ uid, onClose, onAssignRoles }: UserDetailSheet

))} - ) : provider ? ( - /* Fallback to provider overview if userServices is empty */ -
-

- 专长服务商资格 -

-
-
-
在线状态
-
- - - {provider.status === 'online' - ? '在线' - : provider.status === 'busy' - ? '忙碌' - : provider.status === 'offline' - ? '离线' - : provider.status} - -
-
-
-
实名认证
-
- - {provider.is_verified ? '已认证' : '未认证'} - -
-
-
-
评分
-
- - {provider.rating ? provider.rating.toFixed(1) : '暂无评分'} -
-
-
-
已完结订单
-
{provider.completed_jobs ?? 0} 单
-
-
-
) : (
@@ -610,44 +545,6 @@ export function UserDetailSheet({ uid, onClose, onAssignRoles }: UserDetailSheet

)} - - {/* Provider Profile Settings if available */} - {provider && ( -
-

- 专长服务商抢单与派单参数 -

-
-
-
自动抢单模式
-
- {provider.dispatch_setting?.auto_grab_enabled ? '已开启' : '已关闭'} -
-
-
-
今日接单量
-
- {provider.dispatch_setting?.accepted_today ?? 0} /{' '} - {provider.dispatch_setting?.daily_accept_cap ?? '无限制'} -
-
- {provider.dispatch_setting?.min_price != null && ( -
-
最低接单起价
-
¥{provider.dispatch_setting.min_price}
-
- )} - {provider.dispatch_setting?.max_radius_meters != null && ( -
-
服务接单半径
-
- {(provider.dispatch_setting.max_radius_meters / 1000).toFixed(1)} km -
-
- )} -
-
- )}
)}