forked from wangziqi/gongxue-base
fix(admin): restore teacher profile form values
This commit is contained in:
@@ -15,6 +15,10 @@ import dayjs from 'dayjs';
|
||||
import api from '../../api';
|
||||
import PermissionButton from '../../components/PermissionButton';
|
||||
import { message } from '../../ui/app-message';
|
||||
import {
|
||||
userProfileResponseToFormValues,
|
||||
type UserProfileResponse,
|
||||
} from './user-profile-form';
|
||||
|
||||
const UsersPage: React.FC = () => {
|
||||
const [data, setData] = useState<any[]>([]);
|
||||
@@ -36,8 +40,8 @@ const UsersPage: React.FC = () => {
|
||||
const handleOpenProfile = async (record: any) => {
|
||||
setProfileUser(record);
|
||||
try {
|
||||
const res: any = await api.get(`/rbac/users/${record.id}/profile`);
|
||||
profileForm.setFieldsValue(res);
|
||||
const res = await api.get<UserProfileResponse>(`/rbac/users/${record.id}/profile`);
|
||||
profileForm.setFieldsValue(userProfileResponseToFormValues(res));
|
||||
} catch {
|
||||
profileForm.setFieldsValue({});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { userProfileResponseToFormValues } from './user-profile-form';
|
||||
|
||||
describe('user profile form mapping', () => {
|
||||
it('unwraps the nested profile returned by the user profile endpoint', () => {
|
||||
expect(
|
||||
userProfileResponseToFormValues({
|
||||
id: 9,
|
||||
username: 'teacher01',
|
||||
name: '测试教师',
|
||||
profile: {
|
||||
joinedAt: '2026-07-01',
|
||||
qualifications: '教师资格证',
|
||||
subjects: ['语文', '历史'],
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
joinedAt: '2026-07-01',
|
||||
qualifications: '教师资格证',
|
||||
subjects: ['语文', '历史'],
|
||||
});
|
||||
});
|
||||
|
||||
it('returns empty form values when the user has no profile', () => {
|
||||
expect(userProfileResponseToFormValues({ profile: null })).toEqual({});
|
||||
});
|
||||
});
|
||||
16
apps/admin/src/pages/Users/user-profile-form.ts
Normal file
16
apps/admin/src/pages/Users/user-profile-form.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export interface UserProfileFormValues {
|
||||
joinedAt?: string;
|
||||
qualifications?: string;
|
||||
subjects?: string[];
|
||||
}
|
||||
|
||||
export interface UserProfileResponse {
|
||||
id?: number;
|
||||
username?: string;
|
||||
name?: string;
|
||||
profile?: UserProfileFormValues | null;
|
||||
}
|
||||
|
||||
export const userProfileResponseToFormValues = (
|
||||
response: UserProfileResponse,
|
||||
): UserProfileFormValues => response.profile || {};
|
||||
Reference in New Issue
Block a user