@@ -11,18 +11,19 @@ import {
1111 useDeleteCustomerService ,
1212 useUpdateCustomerService ,
1313} from '@/api/customer-service' ;
14- import { Button , Modal , Popover , Table , message } from '@/components/antd' ;
14+ import { Button , Modal , Popover , Table , message , FormInstance } from '@/components/antd' ;
1515import { Category , Retry , UserSelect } from '@/components/common' ;
1616import { UserLabel } from '@/App/Admin/components' ;
1717import { groupBy , sortBy } from 'lodash-es' ;
1818import { RoleCheckboxGroup } from '../../components/RoleCheckboxGroup' ;
19+ import { CustomerServiceForm , CustomerServiceFormData } from './components/CustomerServiceForm' ;
1920
2021function MemberActions ( {
2122 id,
2223 nickname,
2324 active,
2425 onEdit,
25- } : CustomerServiceSchema & { onEdit ?: ( ) => void } ) {
26+ } : Pick < CustomerServiceSchema , 'id' | 'nickname' | 'active' > & { onEdit ?: ( ) => void } ) {
2627 const queryClient = useQueryClient ( ) ;
2728
2829 const { mutate : update , isLoading : isUpdating } = useUpdateCustomerService ( {
@@ -133,20 +134,20 @@ function AddUserModal({ visible, onHide }: AddUserModalProps) {
133134}
134135
135136interface EditUserModalRef {
136- open : ( id : string , roles : CSRole [ ] ) => void ;
137+ open : ( id : string , data : CustomerServiceFormData ) => void ;
137138}
138139
139140const EditUserModal = forwardRef < EditUserModalRef > ( ( _ , ref ) => {
140141 const [ userId , setUserId ] = useState < string | undefined > ( ) ;
141- const [ roles , setRoles ] = useState < CSRole [ ] | undefined > ( ) ;
142+ const [ data , setData ] = useState < CustomerServiceFormData > ( ) ;
142143 const [ visible , setVisible ] = useState ( false ) ;
143144
144145 const queryClient = useQueryClient ( ) ;
145146
146147 useImperativeHandle ( ref , ( ) => ( {
147- open : ( id , roles ) => {
148+ open : ( id , data ) => {
148149 setUserId ( id ) ;
149- setRoles ( roles ) ;
150+ setData ( data ) ;
150151 setVisible ( true ) ;
151152 } ,
152153 } ) ) ;
@@ -160,17 +161,24 @@ const EditUserModal = forwardRef<EditUserModalRef>((_, ref) => {
160161 } ,
161162 } ) ;
162163
164+ const formRef = useRef < FormInstance > ( null ) ;
165+
163166 return (
164167 < Modal
165- visible = { visible }
168+ destroyOnClose
169+ open = { visible }
166170 title = "更新客服"
167- onOk = { ( ) => update ( { id : userId ! , roles } ) }
171+ onOk = { ( ) => formRef . current ?. submit ( ) }
168172 confirmLoading = { isUpdating }
169- okButtonProps = { { disabled : isUpdating || ! userId || roles ?. length === 0 } }
173+ okButtonProps = { { disabled : isUpdating || ! userId } }
170174 onCancel = { ( ) => setVisible ( false ) }
171175 cancelButtonProps = { { disabled : isUpdating } }
172176 >
173- < RoleCheckboxGroup value = { roles } onChange = { ( v ) => setRoles ( v as CSRole [ ] ) } />
177+ < CustomerServiceForm
178+ ref = { formRef }
179+ initData = { data }
180+ onSubmit = { ( data ) => update ( { ...data , id : userId ! } ) }
181+ />
174182 </ Modal >
175183 ) ;
176184} ) ;
@@ -280,11 +288,17 @@ export function Members() {
280288 < Table . Column
281289 key = "actions"
282290 title = "操作"
283- render = { ( _ , v : CustomerService ) => (
291+ render = { ( u : CustomerService ) => (
284292 < MemberActions
285- { ...v }
293+ id = { u . id }
294+ nickname = { u . nickname }
295+ active = { u . active }
286296 onEdit = { ( ) => {
287- editUserModalRef . current ?. open ( v . id , v . roles ) ;
297+ editUserModalRef . current ?. open ( u . id , {
298+ nickname : u . nickname ,
299+ email : u . email ,
300+ roles : u . roles ,
301+ } ) ;
288302 } }
289303 />
290304 ) }
0 commit comments