Abdujamol 7 months ago
parent 797c942269
commit 5eae5d0d74

@ -34,6 +34,13 @@ export type TTasksPostParams = {
attachment_ids?: number[]; attachment_ids?: number[];
}; };
export type TTaskPostFileParams = {
files: any[];
task_id?: number;
shift_update_id?: number;
description?: string;
};
export const taskController = { export const taskController = {
async read(filterObject: TTasksGetParams) { async read(filterObject: TTasksGetParams) {
const params = { ...filterObject }; const params = { ...filterObject };
@ -80,10 +87,29 @@ export const taskController = {
return data; return data;
}, },
async addTaskFile(formData: any) { async addTaskFile(formData: TTaskPostFileParams) {
const { data } = await instance.post("attachment/", formData, { 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: { headers: {
"Content-Type": "multipart/form-data", // Установите правильный Content-Type "Content-Type": "multipart/form-data",
}, },
}); });
return data; return data;

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

@ -56,7 +56,7 @@ import {
import { TPagination } from "../../types/common/TPagination"; import { TPagination } from "../../types/common/TPagination";
import { useTeamData } from "../../Hooks/Teams"; import { useTeamData } from "../../Hooks/Teams";
import { TTeam } from "../../types/Team/TTeam"; import { TTeam } from "../../types/Team/TTeam";
import { EditOutlined, UserOutlined } from "@ant-design/icons"; import { EditOutlined } from "@ant-design/icons";
const TaskModal = ({ const TaskModal = ({
modalOpen, modalOpen,
@ -76,12 +76,20 @@ const TaskModal = ({
) => Promise<QueryObserverResult<TPagination<TTask[]>, unknown>>; ) => Promise<QueryObserverResult<TPagination<TTask[]>, unknown>>;
}) => { }) => {
const moment = require("moment-timezone"); 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 = () => { const handleCancel = () => {
setModalOpen(!modalOpen); setModalOpen(!modalOpen);
}; };
const showUploadModal = () => { const showUploadModal = () => {
setUploadOpen(!uploadOpen); setUploadOpen(!uploadOpen);
}; };
function getFileType(fileName: any) { function getFileType(fileName: any) {
var fileExtension = fileName.split(".").pop()?.toLowerCase(); var fileExtension = fileName.split(".").pop()?.toLowerCase();
@ -102,36 +110,7 @@ const TaskModal = ({
return <img style={{ marginRight: 12 }} src={docicon} alt="" />; 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 teamData = useTeamData("");
const teams: MenuProps["items"] = teamData?.data?.map((item) => ({ const teams: MenuProps["items"] = teamData?.data?.map((item) => ({
key: item?.id, key: item?.id,
@ -155,7 +134,6 @@ const TaskModal = ({
onClick: () => statuspatch("Done"), onClick: () => statuspatch("Done"),
}, },
]; ];
const getImageSource = (source: string) => { const getImageSource = (source: string) => {
switch (source) { switch (source) {
case "driver": 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 ( return (
<Modal <Modal
onCancel={handleCancel} onCancel={handleCancel}

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

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

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

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

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

Loading…
Cancel
Save