fix: 培训/绩效/违纪列表页CRUD改用api实例(修复401鉴权失败)
This commit is contained in:
@@ -4,6 +4,7 @@ import { Link } from 'react-router-dom'
|
||||
import { Search, Plus, Edit2, Trash2, X } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import { rosterApi, employeeApi } from '../../lib/api-services'
|
||||
import api from '../../lib/api'
|
||||
import { usePageSize } from '../../hooks/usePageSize'
|
||||
import { Input, Label, Select } from '../../components/ui/Input'
|
||||
import Button from '../../components/ui/Button'
|
||||
@@ -43,14 +44,10 @@ export default function DisciplinaryRecords() {
|
||||
const isEdit = !!data.recordId
|
||||
const recordId = data.recordId
|
||||
delete data.recordId
|
||||
const url = isEdit
|
||||
? `/api/v1/roster/${empId}/disciplinary/${recordId}`
|
||||
: `/api/v1/roster/${empId}/disciplinary`
|
||||
return fetch(url, {
|
||||
method: isEdit ? 'PUT' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||
body: JSON.stringify(data),
|
||||
}).then(r => r.json())
|
||||
if (isEdit) {
|
||||
return api.put(`/roster/${empId}/disciplinary/${recordId}`, data)
|
||||
}
|
||||
return api.post(`/roster/${empId}/disciplinary`, data)
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('违纪记录已保存')
|
||||
@@ -63,10 +60,7 @@ export default function DisciplinaryRecords() {
|
||||
|
||||
const deleteMut = useMutation({
|
||||
mutationFn: ({ employeeId, recordId }: { employeeId: string; recordId: string }) =>
|
||||
fetch(`/api/v1/roster/${employeeId}/disciplinary/${recordId}`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||
}).then(r => r.json()),
|
||||
api.delete(`/roster/${employeeId}/disciplinary/${recordId}`),
|
||||
onSuccess: () => {
|
||||
toast.success('记录已删除')
|
||||
queryClient.invalidateQueries({ queryKey: ['disciplinary-list'] })
|
||||
|
||||
Reference in New Issue
Block a user