|
|
@@ -106,58 +106,52 @@ const Contracts: React.FC = () => {
|
|
|
};
|
|
|
|
|
|
// 创建合同记录
|
|
|
- const createContract = useMutation(
|
|
|
- async (data: any) => {
|
|
|
+ const createContract = useMutation({
|
|
|
+ mutationFn: async (data: any) => {
|
|
|
const response = await hetongClient.$post({ json: data });
|
|
|
if (!response.ok) throw new Error('Failed to create contract');
|
|
|
return response.json();
|
|
|
},
|
|
|
- {
|
|
|
- onSuccess: () => {
|
|
|
- message.success('合同记录创建成功');
|
|
|
- queryClient.invalidateQueries({ queryKey: ['contracts'] });
|
|
|
- setModalVisible(false);
|
|
|
- },
|
|
|
- onError: () => {
|
|
|
- message.error('操作失败,请重试');
|
|
|
- }
|
|
|
+ onSuccess: () => {
|
|
|
+ message.success('合同记录创建成功');
|
|
|
+ queryClient.invalidateQueries({ queryKey: ['contracts'] });
|
|
|
+ setModalVisible(false);
|
|
|
+ },
|
|
|
+ onError: () => {
|
|
|
+ message.error('操作失败,请重试');
|
|
|
}
|
|
|
- );
|
|
|
+ });
|
|
|
|
|
|
// 更新合同记录
|
|
|
- const updateContract = useMutation(
|
|
|
- async ({ id, data }: { id: string; data: any }) => {
|
|
|
+ const updateContract = useMutation({
|
|
|
+ mutationFn: async ({ id, data }: { id: string; data: any }) => {
|
|
|
const response = await hetongClient[':id'].$put({ param: { id: parseInt(id, 10) }, json: data });
|
|
|
if (!response.ok) throw new Error('Failed to update contract');
|
|
|
return response.json();
|
|
|
},
|
|
|
- {
|
|
|
- onSuccess: () => {
|
|
|
- message.success('合同记录更新成功');
|
|
|
- queryClient.invalidateQueries({ queryKey: ['contracts'] });
|
|
|
- setModalVisible(false);
|
|
|
- },
|
|
|
- onError: () => {
|
|
|
- message.error('操作失败,请重试');
|
|
|
- }
|
|
|
+ onSuccess: () => {
|
|
|
+ message.success('合同记录更新成功');
|
|
|
+ queryClient.invalidateQueries({ queryKey: ['contracts'] });
|
|
|
+ setModalVisible(false);
|
|
|
+ },
|
|
|
+ onError: () => {
|
|
|
+ message.error('操作失败,请重试');
|
|
|
}
|
|
|
- );
|
|
|
+ });
|
|
|
|
|
|
// 删除合同记录
|
|
|
- const deleteContract = useMutation(
|
|
|
- async (id: string) => {
|
|
|
+ const deleteContract = useMutation({
|
|
|
+ mutationFn: async (id: string) => {
|
|
|
const response = await hetongClient[':id'].$delete({ param: { id: parseInt(id, 10) } });
|
|
|
if (!response.ok) throw new Error('Failed to delete contract');
|
|
|
return response.json();
|
|
|
},
|
|
|
- {
|
|
|
- onSuccess: () => {
|
|
|
- message.success('合同记录删除成功');
|
|
|
- queryClient.invalidateQueries({ queryKey: ['contracts'] });
|
|
|
- },
|
|
|
- onError: () => {
|
|
|
- message.error('删除失败,请重试');
|
|
|
- }
|
|
|
+ onSuccess: () => {
|
|
|
+ message.success('合同记录删除成功');
|
|
|
+ queryClient.invalidateQueries({ queryKey: ['contracts'] });
|
|
|
+ },
|
|
|
+ onError: () => {
|
|
|
+ message.error('删除失败,请重试');
|
|
|
}
|
|
|
);
|
|
|
|