AddTeacher.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { useIntl } from "react-intl";
  2. import {
  3. ProForm,
  4. ProFormSelect,
  5. ProFormText,
  6. } from "@ant-design/pro-components";
  7. import { Button, message, Popover } from "antd";
  8. import { UserAddOutlined } from "@ant-design/icons";
  9. import { get } from "../../../request";
  10. import { IUserListResponse } from "../../api/Auth";
  11. interface IFormData {
  12. userId: string;
  13. }
  14. interface IWidget {
  15. groupId?: string;
  16. }
  17. const Widget = ({ groupId }: IWidget) => {
  18. const intl = useIntl();
  19. const form = (
  20. <ProForm<IFormData>
  21. onFinish={async (values: IFormData) => {
  22. // TODO
  23. console.log(values);
  24. message.success(intl.formatMessage({ id: "flashes.success" }));
  25. }}
  26. >
  27. <ProForm.Group>
  28. <ProFormSelect
  29. name="userId"
  30. label={intl.formatMessage({ id: "forms.fields.user.label" })}
  31. showSearch
  32. debounceTime={300}
  33. request={async ({ keyWord }) => {
  34. console.log("keyWord", keyWord);
  35. const json = await get<IUserListResponse>(`/v2/user?view=key&key=`);
  36. const userList = json.data.rows.map((item) => {
  37. return {
  38. value: item.id,
  39. label: `${item.userName}-${item.nickName}`,
  40. };
  41. });
  42. console.log("json", userList);
  43. return userList;
  44. }}
  45. placeholder={intl.formatMessage({ id: "forms.fields.user.required" })}
  46. rules={[
  47. {
  48. required: true,
  49. message: intl.formatMessage({
  50. id: "forms.message.user.required",
  51. }),
  52. },
  53. ]}
  54. />
  55. </ProForm.Group>
  56. </ProForm>
  57. );
  58. return (
  59. <Popover
  60. placement="bottom"
  61. arrowPointAtCenter
  62. content={form}
  63. trigger="click"
  64. >
  65. <Button icon={<UserAddOutlined />} key="add" type="primary">
  66. {intl.formatMessage({ id: "buttons.group.add.member" })}
  67. </Button>
  68. </Popover>
  69. );
  70. };
  71. export default Widget;