fix(deposits): show student numbers in lookup
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { buildDepositStudentOption } from './deposit-student-option';
|
||||||
|
|
||||||
|
describe('deposit student option', () => {
|
||||||
|
it('uses the student number as the non-sensitive identifier', () => {
|
||||||
|
expect(
|
||||||
|
buildDepositStudentOption({ id: 23, name: '张三', studentNo: 'S2026001' }),
|
||||||
|
).toEqual({
|
||||||
|
value: 23,
|
||||||
|
label: '张三 (S2026001)',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('falls back to the internal id when the student number is missing', () => {
|
||||||
|
expect(buildDepositStudentOption({ id: 23, name: '张三', studentNo: null })).toEqual({
|
||||||
|
value: 23,
|
||||||
|
label: '张三 (#23)',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
10
apps/admin/src/pages/Deposits/deposit-student-option.ts
Normal file
10
apps/admin/src/pages/Deposits/deposit-student-option.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export interface DepositStudentLookup {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
studentNo?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const buildDepositStudentOption = (student: DepositStudentLookup) => ({
|
||||||
|
value: student.id,
|
||||||
|
label: `${student.name} (${student.studentNo || `#${student.id}`})`,
|
||||||
|
});
|
||||||
@@ -19,6 +19,7 @@ import dayjs from 'dayjs';
|
|||||||
import api from '../../api';
|
import api from '../../api';
|
||||||
import PermissionButton from '../../components/PermissionButton';
|
import PermissionButton from '../../components/PermissionButton';
|
||||||
import { message } from '../../ui/app-message';
|
import { message } from '../../ui/app-message';
|
||||||
|
import { buildDepositStudentOption } from './deposit-student-option';
|
||||||
|
|
||||||
const statusMap: Record<string, { text: string; color: string }> = {
|
const statusMap: Record<string, { text: string; color: string }> = {
|
||||||
paid: { text: '已缴', color: 'green' },
|
paid: { text: '已缴', color: 'green' },
|
||||||
@@ -90,10 +91,8 @@ const DepositsPage: React.FC = () => {
|
|||||||
const studentOptions = useMemo(
|
const studentOptions = useMemo(
|
||||||
() =>
|
() =>
|
||||||
students
|
students
|
||||||
.map((s: any) => ({
|
.filter((s: any) => s.status === 'active')
|
||||||
value: s.id,
|
.map(buildDepositStudentOption),
|
||||||
label: s.studentNo ? `${s.name} (${s.studentNo})` : s.name,
|
|
||||||
})),
|
|
||||||
[students],
|
[students],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user