2025-01-06 08:45:23 +08:00
|
|
|
import { useRoleMap } from "@nice/client";
|
2024-12-30 08:26:40 +08:00
|
|
|
import { Button, message, Modal } from "antd";
|
|
|
|
import { useContext, useRef, useState } from "react";
|
|
|
|
import { RoleEditorContext } from "./role-editor";
|
|
|
|
import StaffTransfer, { StaffTransferRef } from "../../staff/staff-transfer";
|
2025-01-06 08:45:23 +08:00
|
|
|
import { ObjectType } from "@nice/common";
|
|
|
|
import { api } from "@nice/client"
|
2024-12-30 08:26:40 +08:00
|
|
|
export default function RoleStaffModal() {
|
|
|
|
const {
|
|
|
|
domainId,
|
|
|
|
mapStaffIds,
|
|
|
|
setMapStaffIds,
|
|
|
|
modalOpen,
|
|
|
|
setModalOpen,
|
|
|
|
role
|
|
|
|
} = useContext(RoleEditorContext);
|
|
|
|
const staffsRef = useRef<StaffTransferRef>(null)
|
|
|
|
const { data } = api.rolemap.getStaffsNotMap.useQuery({ domainId, roleId: role?.id });
|
|
|
|
const { addRoleForObjects } = useRoleMap();
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const handleOk = async () => {
|
|
|
|
if (!mapStaffIds?.length) {
|
|
|
|
message.warning("未选择人员");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setLoading(true);
|
|
|
|
try {
|
|
|
|
const result = await addRoleForObjects.mutateAsync({
|
|
|
|
roleId: role?.id,
|
|
|
|
domainId,
|
|
|
|
objectType: ObjectType.STAFF,
|
|
|
|
objectIds: mapStaffIds
|
|
|
|
});
|
|
|
|
message.success("人员分配成功");
|
|
|
|
setModalOpen(false);
|
|
|
|
setMapStaffIds([]);
|
|
|
|
if (staffsRef.current)
|
|
|
|
staffsRef.current.resetSelection()
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
message.error("人员分配失败,请稍后重试");
|
|
|
|
} finally {
|
|
|
|
setLoading(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCancel = () => setModalOpen(false);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
width={600}
|
|
|
|
title="选择人员"
|
|
|
|
open={modalOpen}
|
|
|
|
onOk={handleOk}
|
|
|
|
confirmLoading={loading}
|
|
|
|
onCancel={handleCancel}
|
|
|
|
>
|
|
|
|
<StaffTransfer ref={staffsRef}
|
|
|
|
onChange={(values: string[]) => setMapStaffIds(values)}
|
|
|
|
staffs={data as any}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|