|
|
@@ -1,8 +1,8 @@
|
|
|
import React, { useState } from 'react';
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
import { format } from 'date-fns';
|
|
|
-import { Plus, Search, Edit, Trash2, User, Mail, Phone } from 'lucide-react';
|
|
|
-import { userClient, roleClient } from '@/client/api';
|
|
|
+import { Plus, Search, Edit, Trash2 } from 'lucide-react';
|
|
|
+import { userClient } from '@/client/api';
|
|
|
import type { InferResponseType, InferRequestType } from 'hono/client';
|
|
|
import { Button } from '@/client/components/ui/button';
|
|
|
import { Input } from '@/client/components/ui/input';
|
|
|
@@ -11,16 +11,13 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@
|
|
|
import { Badge } from '@/client/components/ui/badge';
|
|
|
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/client/components/ui/dialog';
|
|
|
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/client/components/ui/form';
|
|
|
-import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/client/components/ui/select';
|
|
|
import { useForm } from 'react-hook-form';
|
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
|
import { z } from 'zod';
|
|
|
import { toast } from 'sonner';
|
|
|
import { Skeleton } from '@/client/components/ui/skeleton';
|
|
|
import { Switch } from '@/client/components/ui/switch';
|
|
|
-import { Label } from '@/client/components/ui/label';
|
|
|
|
|
|
-type UserListResponse = InferResponseType<typeof userClient.$get, 200>;
|
|
|
type CreateUserRequest = InferRequestType<typeof userClient.$post>['json'];
|
|
|
type UpdateUserRequest = InferRequestType<typeof userClient[':id']['$put']>['json'];
|
|
|
|
|
|
@@ -28,9 +25,9 @@ type UpdateUserRequest = InferRequestType<typeof userClient[':id']['$put']>['jso
|
|
|
const userFormSchema = z.object({
|
|
|
username: z.string().min(3, '用户名至少3个字符'),
|
|
|
nickname: z.string().optional(),
|
|
|
- email: z.email('请输入有效的邮箱地址').optional().or(z.literal('')).transform(val => val || null),
|
|
|
- phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入有效的手机号').optional().or(z.literal('')).transform(val => val || null),
|
|
|
- name: z.string().optional().or(z.literal('')).transform(val => val || null),
|
|
|
+ email: z.string().email('请输入有效的邮箱地址').nullable().optional().transform(val => val === '' ? null : val),
|
|
|
+ phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入有效的手机号').nullable().optional().transform(val => val === '' ? null : val),
|
|
|
+ name: z.string().nullable().optional().transform(val => val === '' ? null : val),
|
|
|
password: z.string().min(6, '密码至少6个字符').optional(),
|
|
|
isDisabled: z.boolean().default(false),
|
|
|
});
|
|
|
@@ -270,11 +267,11 @@ export const UsersPage = () => {
|
|
|
<TableCell>{user.email || '-'}</TableCell>
|
|
|
<TableCell>{user.name || '-'}</TableCell>
|
|
|
<TableCell>
|
|
|
- <Badge
|
|
|
- variant={user.role === 'admin' ? 'destructive' : 'default'}
|
|
|
+ <Badge
|
|
|
+ variant={user.roles?.some(role => role.name === 'admin') ? 'destructive' : 'default'}
|
|
|
className="capitalize"
|
|
|
>
|
|
|
- {user.role === 'admin' ? '管理员' : '普通用户'}
|
|
|
+ {user.roles?.some(role => role.name === 'admin') ? '管理员' : '普通用户'}
|
|
|
</Badge>
|
|
|
</TableCell>
|
|
|
<TableCell>
|