import { Avatar, theme, Transfer, TransferProps } from "antd"; import { StaffDto } from "@nicestack/common"; import React, { forwardRef, useImperativeHandle, useMemo, useState } from "react"; // Define the ref type export interface StaffTransferRef { resetSelection: () => void; } interface StaffTransferProps { staffs?: StaffDto[]; onChange?: (targetKeys: string[]) => void; } interface TransferRecordType { key: string; title: string; description?: string; chosen: boolean; } const StaffTransfer = forwardRef(({ staffs = [], onChange: externalOnChange }, ref) => { const [targetKeys, setTargetKeys] = useState([]); const { token } = theme.useToken(); const dataSource = useMemo(() => { // console.log(staffs) return staffs.map(staff => ({ key: staff.id, title: staff.showname || staff.username, description: staff.officerId, chosen: false })); }, [staffs]); const handleChange: TransferProps['onChange'] = (newTargetKeys, direction, moveKeys) => { setTargetKeys(newTargetKeys); // console.log(newTargetKeys); if (externalOnChange) { externalOnChange(newTargetKeys as string[]); } }; const filterOption = (inputValue: string, item: TransferRecordType) => item.title.toLowerCase().includes(inputValue.toLowerCase()) || item.description?.toLowerCase().includes(inputValue.toLowerCase()); useImperativeHandle(ref, () => ({ resetSelection: () => { setTargetKeys([]); } })); return ( (
{item.title?.slice(0, 1).toUpperCase()} {item.title} {item.description}
)} /> ); }); export default StaffTransfer;