import { message } from "antd"; import { useIntl } from "react-intl"; import { ProForm, ProFormDependency, type ProFormInstance, ProFormSelect, } from "@ant-design/pro-components"; import { post } from "../../request"; import type { TRole } from "../../api/Auth"; import type { IShareRequest, IShareResponse } from "../../api/Share"; import { useRef } from "react"; import { EResType } from "./Share"; import UserSelect from "../template/UserSelect"; import GroupSelect from "../template/GroupSelect"; interface IWidget { resId: string; resType: EResType; onSuccess?: Function; } const CollaboratorAddWidget = ({ resId, resType, onSuccess }: IWidget) => { const roleList = ["editor", "reader"]; const intl = useIntl(); const formRef = useRef(undefined); interface IFormData { userId: string[]; groupId: string[]; userType: string; role: TRole; } return ( formRef={formRef} onFinish={async (values: IFormData) => { if (typeof resId !== "undefined") { const postData: IShareRequest = { user_id: values.userType === "user" ? values.userId : values.groupId, user_type: values.userType, role: values.role, res_id: resId, res_type: resType, }; const url = "/v2/share"; console.info("share api request", url, postData); post(url, postData).then((json) => { console.debug("share api response", json); if (json.ok) { if (typeof onSuccess !== "undefined") { onSuccess(); } formRef.current?.resetFields(["userId"]); message.success(intl.formatMessage({ id: "flashes.success" })); } }); } }} > {({ userType }) => { if (userType === "user") { return ; } else { return ; } }} { return { value: item, label: intl.formatMessage({ id: "auth.role." + item }), }; })} rules={[ { required: true, message: intl.formatMessage({ id: "forms.message.user.required", }), }, ]} /> ); }; export default CollaboratorAddWidget;