import { Modal, Form as FormAnt, Select, Upload, Switch, Button, Radio, RadioChangeEvent, Row, Col, } from "antd"; import { taskController } from "../../API/LayoutApi/tasks"; import { useEffect, useState } from "react"; import { useServiceData } from "../../Hooks/Services"; import { UploadOutlined } from "@ant-design/icons"; import { useTeamData } from "../../Hooks/Teams"; import { useCustomerByComanyData } from "../../Hooks/Customers"; // @ts-ignore import zippy from "../../assets/zippyicon.svg"; // @ts-ignore import evo from "../../assets/evoicon.png"; // @ts-ignore import zeelog from "../../assets/zeelogicon.svg"; // @ts-ignore import ontime from "../../assets/ontimeicon.svg"; // @ts-ignore import tt from "../../assets/tticon.svg"; //@ts-ignore import addicon from "../../assets/addiconpng.png"; import AddCustomer from "../Customers/AddCustomer"; import AddDriver from "../Companies/AddDriver"; import TextArea from "antd/es/input/TextArea"; import { isMobile } from "../../App"; import { companyController } from "../../API/LayoutApi/companies"; import { TCompany } from "../../types/Company/TCompany"; import { customerController } from "../../API/LayoutApi/customers"; import { TCustomer } from "../../types/Customer/TCustomer"; const { Option } = Select; const AddTask = ({ open, setOpen, }: { open: boolean; setOpen(open: boolean): void; }) => { const [form] = FormAnt.useForm(); const handleCancel = () => { setOpen(!open); }; const [fileIds, setFileIds] = useState([]); const [searchCompanyName, setSearchCompanyName] = useState(""); const [customerName, setCustomerName] = useState(); const [companyId, setCompanyId] = useState(); const [driverOpen, setDriverOpen] = useState(false); const [openDrive, setOpenDrive] = useState(false); const [companyData, setCompanyData] = useState(); const [customerData, setCustomerData] = useState(); const ServiceData = useServiceData(); const TeamData = useTeamData({}); // company and driver search useEffect(() => { companyController .readPaginated({ name: searchCompanyName, page: 1, page_size: 3 }) .then((data) => { setCompanyData(data.data); }); }, [searchCompanyName]); // const customerData = useCustomerByComanyData( // { name: customerName, page: 1, page_size: 5 }, // companyId // ); // console.log(customerData.data); // team select useEffect(() => { if (companyId) { const selectedCompany = companyData?.find( (item) => item.id === companyId ); form.setFieldsValue({ assigned_to_id: selectedCompany?.team?.id || undefined, }); customerController .customerByCompany( { name: customerName, page: 1, page_size: 5, }, companyId ) .then((data) => { setCustomerData(data.data); }); } }, [companyId]); // service select const serviceOptions = ServiceData?.data?.map((item) => ({ label: item?.title, value: item?.id, })); const sortByLabel = (a: any, b: any) => { if (a.label === "Shift") return -1; if (b.label === "Shift") return 1; return 0; }; const noteOptions = [ { label: "No", value: "" }, { label: "Empty", value: "Empty" }, { label: "Bobtail", value: "Bobtail" }, ]; const [note, setNote] = useState(""); const onChange = ({ target: { value } }: RadioChangeEvent) => { setNote(value); }; const noteOptions2 = [ { label: "No", value: "" }, { label: "+1 soat", value: "+1 soat" }, { label: "+3 soat", value: "+3 soat" }, ]; const [note2, setNote2] = useState(""); const onChange2 = ({ target: { value } }: RadioChangeEvent) => { setNote2(value); }; const [text, setText] = useState(""); const changeText = (e: any) => { setText(e.target.value); }; function handlePaste(event: any) { const clipboardData = event.clipboardData || window.Clipboard; if (clipboardData && clipboardData.items.length > 0) { const clipboardItem = clipboardData.items[0]; if (clipboardItem.kind === "file") { const file = clipboardItem.getAsFile(); const reader = new FileReader(); reader.readAsDataURL(file); taskController .addTaskFile({ files: [file] }) .then((response) => { const fileId = response.id; setFileIds((prevFileIds): any => [...prevFileIds, fileId]); const updatedValues = form.getFieldsValue(); updatedValues.attachment_ids = [ ...updatedValues.attachment_ids, fileId, ]; form.setFieldsValue(updatedValues); }) .catch((error) => {}); } } } const getImageSource = (source: string) => { switch (source) { case "Zippy": return zippy; case "EVO": return evo; case "Ontime": return ontime; case "Zeelog": return zeelog; case "TT": return tt; default: return tt; } }; return (
handlePaste(event)}> {openDrive && } { form.validateFields().then(async (values) => { values.attachment_ids = fileIds; values.note = (text ? text + ", " : "") + (note ? note + ", " : "") + (note2 ? note2 + ", " : ""); form.resetFields(); await taskController.addTaskController(values); setOpen(!open); }); }} > setCustomerName(value)} options={customerData?.map((item) => ({ label: item?.name, value: item?.id, }))} value={customerName} filterOption={false} autoClearSearchValue={false} allowClear />
({ label: item?.name, value: item?.id, }))} onChange={(value) => form.setFieldsValue({ assigned_to_id: value }) } />