Abdujamol 7 months ago
parent 797c942269
commit 5eae5d0d74

@ -34,6 +34,13 @@ export type TTasksPostParams = {
attachment_ids?: number[];
};
export type TTaskPostFileParams = {
files: any[];
task_id?: number;
shift_update_id?: number;
description?: string;
};
export const taskController = {
async read(filterObject: TTasksGetParams) {
const params = { ...filterObject };
@ -80,10 +87,29 @@ export const taskController = {
return data;
},
async addTaskFile(formData: any) {
const { data } = await instance.post("attachment/", formData, {
async addTaskFile(formData: TTaskPostFileParams) {
const params = { ...formData };
const form = new FormData();
if (formData.task_id) {
form.append("task_id", String(formData.task_id));
}
for (const file of formData.files) {
form.append("files", file);
}
console.log(form);
// if (Array.isArray(formData.files)) {
// params.files = formData.files;
// }
// if (!!formData.task_id) params.task_id = formData.task_id;
// if (!!formData.shift_update_id)
// params.shift_update_id = formData.shift_update_id;
if (!!formData.description) params.description = formData.description;
const { data } = await instance.post("attachment/", form, {
headers: {
"Content-Type": "multipart/form-data", // Установите правильный Content-Type
"Content-Type": "multipart/form-data",
},
});
return data;

@ -65,8 +65,6 @@ const AddTask = ({
const clipboardItem = clipboardData.items[0];
if (clipboardItem.kind === "file") {
const file = clipboardItem.getAsFile();
const formData = new FormData();
formData.append("file", file);
const reader = new FileReader();
reader.onload = (e) => {
@ -76,7 +74,7 @@ const AddTask = ({
};
reader.readAsDataURL(file);
taskController
.addTaskFile(formData)
.addTaskFile({ files: [file] })
.then((response) => {
const fileId = response.id;
setFileIds((prevFileIds): any => [...prevFileIds, fileId]);
@ -129,10 +127,10 @@ const AddTask = ({
onCancel={handleCancel}
onOk={() => {
form.validateFields().then(async (values) => {
const updatedValues = { ...values };
updatedValues.attachment_ids = fileIds;
// const updatedValues = { ...values };
values.attachment_ids = fileIds;
form.resetFields();
await taskController.addTaskController(updatedValues);
await taskController.addTaskController(values);
setOpen(!open);
});
}}
@ -146,7 +144,7 @@ const AddTask = ({
<FormAnt.Item
label="Company"
name="company_id"
rules={[{ required: false, message: "Please input company!" }]}
rules={[{ required: true, message: "Please input company!" }]}
>
<Select
showSearch
@ -185,7 +183,7 @@ const AddTask = ({
name="customer_id"
style={{ width: "85%" }}
rules={[
{ required: false, message: "Please input service points!" },
{ required: true, message: "Please input service points!" },
]}
>
<Select
@ -286,23 +284,22 @@ const AddTask = ({
const formData = new FormData();
formData.append("file", file);
taskController
.addTaskFile(formData)
.addTaskFile({ task_id: undefined, files: [file] })
.then((response) => {
const fileId = response.id;
console.log(response);
const fileId = response.data.file_ids[0];
setFileIds((prevFileIds): any => [
...prevFileIds,
fileId,
]);
onSuccess();
const updatedValues = form.getFieldsValue();
updatedValues.attachment_ids = [
...updatedValues.attachment_ids,
fileId,
];
form.setFieldsValue(updatedValues);
})
.catch((error) => {
onSuccess(error);
// const updatedValues = form.getFieldsValue();
// updatedValues.attachment_ids = [
// ...updatedValues.attachment_ids,
// fileId,
// ];
// form.setFieldsValue(updatedValues);
});
}}
>

@ -56,7 +56,7 @@ import {
import { TPagination } from "../../types/common/TPagination";
import { useTeamData } from "../../Hooks/Teams";
import { TTeam } from "../../types/Team/TTeam";
import { EditOutlined, UserOutlined } from "@ant-design/icons";
import { EditOutlined } from "@ant-design/icons";
const TaskModal = ({
modalOpen,
@ -76,12 +76,20 @@ const TaskModal = ({
) => Promise<QueryObserverResult<TPagination<TTask[]>, unknown>>;
}) => {
const moment = require("moment-timezone");
const [text, setText] = useState<string | undefined>(recordTask?.note);
const [pti, setPti] = useState<boolean | undefined>(recordTask?.pti);
const theme = localStorage.getItem("theme") === "true" ? true : false;
const [status, setStatus] = useState(recordTask?.status);
const [teamName, setTeamName] = useState(recordTask?.assigned_to?.name);
const { data, isLoading } = useTaskHistory(recordTask?.id);
const handleCancel = () => {
setModalOpen(!modalOpen);
};
const showUploadModal = () => {
setUploadOpen(!uploadOpen);
};
function getFileType(fileName: any) {
var fileExtension = fileName.split(".").pop()?.toLowerCase();
@ -102,36 +110,7 @@ const TaskModal = ({
return <img style={{ marginRight: 12 }} src={docicon} alt="" />;
}
}
const [text, setText] = useState<string | undefined>(recordTask?.note);
const [pti, setPti] = useState<boolean | undefined>(recordTask?.pti);
const theme = localStorage.getItem("theme") === "true" ? true : false;
const { data, isLoading } = useTaskHistory(recordTask?.id);
const patchTask = () => {
taskController
.taskPatch({ note: text, pti: pti }, recordTask?.id)
.then(() => {
message.success({ content: "Saved!" });
});
};
const [status, setStatus] = useState(recordTask?.status);
const statuspatch = (status: string) => {
setStatus(status);
taskController.taskPatch({ status: status }, recordTask?.id).then(() => {
message.success({ content: "Success", duration: 1 });
});
};
const [teamName, setTeamName] = useState(recordTask?.assigned_to?.name);
const teampatch = (item: TTeam) => {
setTeamName(item?.name);
taskController
.taskPatch({ assigned_to_id: item?.id }, recordTask?.id)
.then(() => {
message.success({ content: "Success", duration: 1 });
});
};
const teamData = useTeamData("");
const teams: MenuProps["items"] = teamData?.data?.map((item) => ({
key: item?.id,
@ -155,7 +134,6 @@ const TaskModal = ({
onClick: () => statuspatch("Done"),
},
];
const getImageSource = (source: string) => {
switch (source) {
case "driver":
@ -167,6 +145,30 @@ const TaskModal = ({
}
};
const statuspatch = (status: string) => {
setStatus(status);
taskController.taskPatch({ status: status }, recordTask?.id).then(() => {
message.success({ content: "Success", duration: 1 });
});
};
const teampatch = (item: TTeam) => {
setTeamName(item?.name);
taskController
.taskPatch({ assigned_to_id: item?.id }, recordTask?.id)
.then(() => {
message.success({ content: "Success", duration: 1 });
});
};
const patchTask = () => {
taskController
.taskPatch({ note: text, pti: pti }, recordTask?.id)
.then(() => {
message.success({ content: "Saved!" });
});
};
return (
<Modal
onCancel={handleCancel}

@ -2,18 +2,8 @@ import { Button, Modal, Space, Table, Tooltip } from "antd";
import "../../App.css";
import { useEffect, useMemo, useState } from "react";
import { taskController } from "../../API/LayoutApi/tasks";
import { TPagination } from "../../types/common/TPagination";
import { TTask } from "../../types/Tasks/TTasks";
import {
QueryObserverResult,
RefetchOptions,
RefetchQueryFilters,
UseQueryResult,
} from "react-query";
import { TCompany } from "../../types/Company/TCompany";
import { TService } from "../../types/Service/TService";
import { TCustomer } from "../../types/Customer/TCustomer";
import { TUser } from "../../types/User/TUser";
// @ts-ignore
import zippy from "../../assets/zippyicon.svg";
// @ts-ignore
@ -29,27 +19,18 @@ import tagIcon from "../../assets/tagIcon.png";
// @ts-ignore
import tgIcon from "../../assets/telegram.png";
import { role } from "../../App";
import { render } from "@testing-library/react";
const admin_id = localStorage.getItem("admin_id");
const TaskTable = ({
data,
isLoading,
refetch,
showTaskModal,
}: {
data: {
characters: TTask[] | undefined;
CompanyData: UseQueryResult<TCompany[], unknown>;
CustomerData: UseQueryResult<TCustomer[], unknown>;
ServiceData: UseQueryResult<TService[], unknown>;
AdminData: UseQueryResult<TUser[], unknown>;
};
showTaskModal: any;
isLoading: boolean;
refetch: <TPageData>(
options?: (RefetchOptions & RefetchQueryFilters<TPageData>) | undefined
) => Promise<QueryObserverResult<TPagination<TTask[]>, unknown>>;
}) => {
const moment = require("moment");
const statusClick = (record: any) => {

@ -8,12 +8,22 @@ import { CloseOutlined } from "@ant-design/icons";
import { TTask } from "../../types/Tasks/TTasks";
import { useState } from "react";
import TextArea from "antd/es/input/TextArea";
import {
QueryObserverResult,
RefetchOptions,
RefetchQueryFilters,
} from "react-query";
import { TPagination } from "../../types/common/TPagination";
const TaskUploadModal = ({
uploadOpen,
recordTask,
setUploadOpen,
refetch,
}: {
refetch: <TPageData>(
options?: (RefetchOptions & RefetchQueryFilters<TPageData>) | undefined
) => Promise<QueryObserverResult<TPagination<TTask[]>, unknown>>;
recordTask: TTask | undefined;
uploadOpen: boolean;
setUploadOpen(open: boolean): void;
@ -21,7 +31,7 @@ const TaskUploadModal = ({
const handleCancel = () => {
setUploadOpen(!uploadOpen);
};
const [fileData, setFileData] = useState();
const [fileData, setFileData] = useState<any>([]);
const [text, setText] = useState<any>();
return (
<Modal
@ -43,13 +53,16 @@ const TaskUploadModal = ({
<Button
type="primary"
onClick={() => {
const updatedValues: any = {};
updatedValues.task_id = recordTask?.id;
updatedValues.file = fileData;
updatedValues.description = text;
taskController.addTaskFile(updatedValues).then(() => {
setUploadOpen(!uploadOpen);
});
taskController
.addTaskFile({
task_id: recordTask?.id,
files: fileData,
description: text,
})
.then(() => {
refetch();
setUploadOpen(!uploadOpen);
});
}}
icon={<img alt="" src={createIcon} />}
>
@ -63,7 +76,7 @@ const TaskUploadModal = ({
name="file"
multiple={true}
customRequest={({ file, onSuccess }: any) => {
setFileData(file);
setFileData((prev: any) => [...prev, file]);
if (file) {
onSuccess();
}

@ -1,15 +1,11 @@
import { useCallback, useEffect, useRef, useState } from "react";
import AddTask from "./AddTask";
import { Button, Input, Select, Space, message, notification } from "antd";
import { Button, Input, Select, Space, notification } from "antd";
import TaskTable from "./TaskTable";
import { useTeamData } from "../../Hooks/Teams";
import { StepForwardOutlined, StepBackwardOutlined } from "@ant-design/icons";
import { useTasks } from "../../Hooks/Tasks";
import { TTask } from "../../types/Tasks/TTasks";
import { useCompanyData } from "../../Hooks/Companies";
import { useCustomerData } from "../../Hooks/Customers";
import { useUserData } from "../../Hooks/Users";
import { useServiceData } from "../../Hooks/Services";
import { admin_id, role, team_id } from "../../App";
//@ts-ignore
import addicon from "../../assets/addiconpng.png";
@ -33,11 +29,6 @@ const Task = () => {
const [page, setPage] = useState<any>(1);
const [uploadOpen, setUploadOpen] = useState(false);
const CompanyData = useCompanyData({});
const CustomerData = useCustomerData({});
const AdminData = useUserData({});
const ServiceData = useServiceData();
let taskSocket: WebSocket;
interface newData {
callback_request: TCall;
@ -79,7 +70,7 @@ const Task = () => {
useEffect(() => {
connect();
}, []);
});
const [api, contextHolder] = notification.useNotification();
const openNotification = useCallback(
@ -240,6 +231,7 @@ const Task = () => {
{open && <AddTask open={open} setOpen={setOpen} />}
{uploadOpen && (
<TaskUploadModal
refetch={refetch}
recordTask={recordTask}
uploadOpen={uploadOpen}
setUploadOpen={setUploadOpen}
@ -320,9 +312,8 @@ const Task = () => {
)}
</div>
<TaskTable
data={{ characters, CompanyData, CustomerData, ServiceData, AdminData }}
data={{ characters }}
isLoading={isLoading}
refetch={refetch}
showTaskModal={showTaskModal}
/>
<Space style={{ width: "100%", marginTop: 10 }} direction="vertical">

@ -49,18 +49,18 @@ const AddUpdate = ({
const file = clipboardItem.getAsFile();
const formData = new FormData();
formData.append("file", file);
taskController.addTaskFile(formData).then((response) => {
const fileId = response.id;
const n = [response.file];
setImgname((prev: any) => [...prev, ...n]);
setFileIds((prevFileIds): any => [...prevFileIds, fileId]);
const updatedValues = form.getFieldsValue();
updatedValues.attachment_ids = [
...updatedValues.attachment_ids,
fileId,
];
form.setFieldsValue(updatedValues);
});
// taskController.addTaskFile(formData).then((response) => {
// const fileId = response.id;
// const n = [response.file];
// setImgname((prev: any) => [...prev, ...n]);
// setFileIds((prevFileIds): any => [...prevFileIds, fileId]);
// const updatedValues = form.getFieldsValue();
// updatedValues.attachment_ids = [
// ...updatedValues.attachment_ids,
// fileId,
// ];
// form.setFieldsValue(updatedValues);
// });
}
}
}
@ -162,22 +162,22 @@ const AddUpdate = ({
customRequest={({ file, onSuccess }: any) => {
const formData = new FormData();
formData.append("file", file);
taskController
.addTaskFile(formData)
.then((response) => {
const fileId = response.id;
setFileIds((prevFileIds): any => [...prevFileIds, fileId]);
onSuccess();
const updatedValues = form.getFieldsValue();
updatedValues.attachment_ids = [
...updatedValues.attachment_ids,
fileId,
];
form.setFieldsValue(updatedValues);
})
.catch((error) => {
onSuccess(error);
});
// taskController
// .addTaskFile(formData)
// .then((response) => {
// const fileId = response.id;
// setFileIds((prevFileIds): any => [...prevFileIds, fileId]);
// onSuccess();
// const updatedValues = form.getFieldsValue();
// updatedValues.attachment_ids = [
// ...updatedValues.attachment_ids,
// fileId,
// ];
// form.setFieldsValue(updatedValues);
// })
// .catch((error) => {
// onSuccess(error);
// });
}}
>
<p className="ant-upload-drag-icon">

@ -138,10 +138,10 @@ const UpdateEdit = () => {
const formData = new FormData();
formData.append("file", file);
formData.append("shift_update_id", id);
taskController.addTaskFile(formData).then((response) => {
const n = [response.file];
setImgname((prev: any) => [...prev, ...n]);
});
// taskController.addTaskFile(formData).then((response) => {
// const n = [response.file];
// setImgname((prev: any) => [...prev, ...n]);
// });
}
}
}
@ -384,14 +384,14 @@ const UpdateEdit = () => {
const formData = new FormData();
formData.append("file", file);
formData.append("shift_update_id", id);
taskController
.addTaskFile(formData)
.then(() => {
onSuccess();
})
.catch((error) => {
onSuccess(error);
});
// taskController
// .addTaskFile(formData)
// .then(() => {
// onSuccess();
// })
// .catch((error) => {
// onSuccess(error);
// });
}}
>
<p className="ant-upload-drag-icon">

Loading…
Cancel
Save