diff --git a/src/API/LayoutApi/tasks.ts b/src/API/LayoutApi/tasks.ts index 685c638..b89a3e9 100644 --- a/src/API/LayoutApi/tasks.ts +++ b/src/API/LayoutApi/tasks.ts @@ -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; diff --git a/src/Components/Tasks/AddTask.tsx b/src/Components/Tasks/AddTask.tsx index d73e43f..b0e3487 100644 --- a/src/Components/Tasks/AddTask.tsx +++ b/src/Components/Tasks/AddTask.tsx @@ -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 = ({ { - 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); }); }} > diff --git a/src/Components/Tasks/TaskModal.tsx b/src/Components/Tasks/TaskModal.tsx index 3d85f0f..611b3ff 100644 --- a/src/Components/Tasks/TaskModal.tsx +++ b/src/Components/Tasks/TaskModal.tsx @@ -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, unknown>>; }) => { const moment = require("moment-timezone"); + const [text, setText] = useState(recordTask?.note); + const [pti, setPti] = useState(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 ; } } - const [text, setText] = useState(recordTask?.note); - const [pti, setPti] = useState(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 ( ; - CustomerData: UseQueryResult; - ServiceData: UseQueryResult; - AdminData: UseQueryResult; }; showTaskModal: any; isLoading: boolean; - refetch: ( - options?: (RefetchOptions & RefetchQueryFilters) | undefined - ) => Promise, unknown>>; }) => { const moment = require("moment"); const statusClick = (record: any) => { diff --git a/src/Components/Tasks/TaskUploadModal.tsx b/src/Components/Tasks/TaskUploadModal.tsx index 93acd40..18ac005 100644 --- a/src/Components/Tasks/TaskUploadModal.tsx +++ b/src/Components/Tasks/TaskUploadModal.tsx @@ -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: ( + options?: (RefetchOptions & RefetchQueryFilters) | undefined + ) => Promise, 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([]); const [text, setText] = useState(); return ( { - 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={} > @@ -63,7 +76,7 @@ const TaskUploadModal = ({ name="file" multiple={true} customRequest={({ file, onSuccess }: any) => { - setFileData(file); + setFileData((prev: any) => [...prev, file]); if (file) { onSuccess(); } diff --git a/src/Components/Tasks/Tasks.tsx b/src/Components/Tasks/Tasks.tsx index 2e4ed5d..290f5aa 100644 --- a/src/Components/Tasks/Tasks.tsx +++ b/src/Components/Tasks/Tasks.tsx @@ -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(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 && } {uploadOpen && ( { )} diff --git a/src/Components/Updates/AddUpdate.tsx b/src/Components/Updates/AddUpdate.tsx index fded565..a3787a4 100644 --- a/src/Components/Updates/AddUpdate.tsx +++ b/src/Components/Updates/AddUpdate.tsx @@ -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); + // }); }} >

diff --git a/src/Components/Updates/UpdateEdit.tsx b/src/Components/Updates/UpdateEdit.tsx index 284a6ac..7b211cc 100644 --- a/src/Components/Updates/UpdateEdit.tsx +++ b/src/Components/Updates/UpdateEdit.tsx @@ -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); + // }); }} >