main
tteld 4 months ago
parent d9477b2d8c
commit a6fd4e318a

1
.gitignore vendored

@ -21,3 +21,4 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
build.zip

Binary file not shown.

@ -52,7 +52,7 @@ export const companyController = {
return data;
},
async companyOne(Id: number | undefined) {
async companyOne(Id: number | string | undefined) {
if (Id) {
const { data } = await instance.get<TCompany>(`company/${Id}/`);
return data;

@ -10,6 +10,7 @@ export type TCustomerGetParams = {
for_driver_request?: boolean;
is_active?: boolean;
};
export type TCustomerByCompanyGetParams = {
name?: string;
id?: number;
@ -50,21 +51,20 @@ export const customerController = {
}
},
async customerByCompany(
id: number | undefined,
name: string | undefined,
for_driver_request?: boolean
) {
const params = { name, for_driver_request };
if (!!name) params.name = name;
if (!!for_driver_request) params.for_driver_request = for_driver_request;
if (id) {
const { data } = await instance.get<TCustomer[]>(
`customers-by-company/${id}/`,
{ params }
);
return data;
}
async customerByCompany(filterObject: TCustomerGetParams, id?: number) {
const params = { ...filterObject };
if (!!filterObject.name) params.name = filterObject.name;
if (!!filterObject.for_driver_request)
params.for_driver_request = filterObject.for_driver_request;
if (!!filterObject.page) params.page = filterObject.page;
if (!!filterObject.page_size) params.page_size = filterObject.page_size;
const { data } = await instance.get<TPagination<TCustomer[]>>(
`customers-by-company/${id}/`,
{ params }
);
return data;
},
async customerPatch(obj: TCustomerPutParams, id: string) {

@ -96,6 +96,24 @@ export const taskController = {
};
}
},
async taskPatchPatch(obj: TTasksPutParams, task_id: number | undefined) {
try {
const response = await instance.patch<TTask | TMessageResponse>(
`task/${task_id}/`,
obj
);
if (response.status === 202) {
const data = response.data as TMessageResponse;
message.success({ content: data.message });
}
return { data: response?.data as TTask, status: response?.status };
} catch (error: any) {
return {
data: error?.response?.data.data,
status: error?.response.status,
};
}
},
async addTaskController(obj: TTasksPostParams) {
const { data } = await instance.post<TTask>("task/", obj).then((u) => {

@ -2,6 +2,11 @@ import { TTeam } from "../../types/Team/TTeam";
import instance from "../api";
import { message } from "antd";
export type TTeamGetParams = {
name?: string;
company_id?: string | number;
};
export type TTeamPutParams = {
name?: string;
is_active?: boolean;
@ -13,8 +18,15 @@ export type TTeamPostParams = {
};
export const teamController = {
async read(name: string) {
const { data } = await instance.get<TTeam[]>(`teams/?name=${name}`);
async read(obj: TTeamGetParams) {
const params = { ...obj };
if (!!obj.company_id) params.company_id = obj.company_id;
if (!!obj.name) params.name = obj.name;
const { data } = await instance.get<TTeam[]>(`teams/`, {
params,
});
return data;
},

@ -1,7 +1,7 @@
import axios from "axios";
// const instance = axios.create({
// baseURL: "http://10.10.10.19:8080/api/v1/",
// baseURL: "http://10.10.10.64:8080/api/v1/",
// });
const instance = axios.create({
baseURL: "https://api.tteld.co/api/v1/",

@ -32,11 +32,13 @@ export const LoginApi = async ({ username, password }: loginInterface) => {
localStorage.setItem("refresh", data?.data.refresh);
localStorage.setItem("admin_id", data?.data.id);
document.location.replace("/");
} catch (err) {
} catch (err: any) {
setTimeout(() => {
message.error({
content: "Username or password incorrect!",
duration: 2,
content: err?.response?.data
? err?.response?.data?.message
: "Username or password incorrect!!!",
duration: 8,
});
}, 1000);
}

@ -263,7 +263,7 @@ const App: React.FC = () => {
admin_id
) {
// taskSocket = new WebSocket(
// `ws://10.10.10.19:8080/global/?user_id=${admin_id}`
// `ws://10.10.10.64:8080/global/?user_id=${admin_id}`
// );
taskSocket = new WebSocket(
`wss://api.tteld.co/global/?user_id=${admin_id}`

@ -1,51 +1,20 @@
import { Input, Modal, Form as FormAnt, Select } from "antd";
import { Input, Modal, Form as FormAnt } from "antd";
import { customerController } from "../../API/LayoutApi/customers";
import { useCompanyData, useCompanyOne } from "../../Hooks/Companies";
// @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";
import { useState } from "react";
import { useCompanyOne } from "../../Hooks/Companies";
const AddDriver = ({
open,
id,
setOpen,
}: {
id: any;
id: number | undefined;
open: boolean;
setOpen(open: boolean): void;
}) => {
const [form] = FormAnt.useForm();
const companyData = useCompanyOne(id);
const handleCancel = () => {
setOpen(!open);
};
const companyData = useCompanyOne(id);
const companyDataAll = useCompanyData({ name: "" });
const [companyName, setCompanyName] = useState<string>();
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 (
<div>
<Modal
@ -70,6 +39,9 @@ const AddDriver = ({
name="form_in_modal"
initialValues={{ modifier: "public" }}
>
<FormAnt.Item label="Company" name="company_id">
<Input defaultValue={companyData.data?.name} readOnly />
</FormAnt.Item>
<FormAnt.Item
label="Name"
name="name"
@ -77,40 +49,6 @@ const AddDriver = ({
>
<Input />
</FormAnt.Item>
<FormAnt.Item
label="Company"
name="company_id"
rules={[{ required: false, message: "Please input company!" }]}
>
{id ? (
<Input defaultValue={companyData?.data?.name} readOnly />
) : (
<Select
showSearch
placeholder="Search Company"
onSearch={(value: any) => setCompanyName(value)}
options={companyDataAll?.data?.map((item: any) => ({
label: (
<div>
{item?.source && (
<img
style={{ width: 15, height: 20, paddingTop: 7 }}
src={getImageSource(item?.source)}
alt=""
/>
)}{" "}
{item?.name}
</div>
),
value: item?.id,
}))}
value={companyName}
filterOption={false}
autoClearSearchValue={false}
allowClear
/>
)}
</FormAnt.Item>
</FormAnt>
</Modal>
</div>

@ -24,6 +24,7 @@ import AddDriver from "./AddDriver";
import { role } from "../../App";
import { useTeamData } from "../../Hooks/Teams";
import { useCustomerByComanyData } from "../../Hooks/Customers";
import { StepForwardOutlined, StepBackwardOutlined } from "@ant-design/icons";
// @ts-ignore
import zippy from "../../assets/zippyicon.svg";
// @ts-ignore
@ -44,14 +45,13 @@ const TabPane = Tabs.TabPane;
type params = {
readonly id: any;
};
type MyObjectType = {
[key: string | number]: any;
};
const CompanyEdit = () => {
const [open, setOpen] = useState(false);
const [page, setPage] = useState(1);
const { id } = useParams<params>();
const customerData = useCustomerByComanyData({ id: id });
const { data, refetch, status }: MyObjectType = useCompanyOne(id);
const customerData = useCustomerByComanyData({ page, page_size: 10 }, id);
const { data, refetch, status } = useCompanyOne(id);
const showModal = () => {
setOpen(true);
@ -81,7 +81,7 @@ const CompanyEdit = () => {
};
const [activeTab, setActiveTab] = useState("1");
const TeamData = useTeamData("");
const TeamData = useTeamData({});
const noTeamOption = { label: " - - - - - -", value: "" };
const TeamOption: { label: string; value: any }[] | undefined =
TeamData?.data?.map((item) => ({
@ -92,7 +92,19 @@ const CompanyEdit = () => {
TeamOption.unshift(noTeamOption);
}
const [team, setTeam] = useState();
const [team, setTeam] = useState<string | undefined>();
const Next = () => {
const a = Number(page) + 1;
setPage(a);
};
const Previos = () => {
Number(page);
if (page > 1) {
const a = Number(page) - 1;
setPage(a);
}
};
return (
<div>
@ -165,7 +177,7 @@ const CompanyEdit = () => {
<Select
options={TeamOption}
defaultValue={data?.team?.name}
onChange={(e) => setTeam(e)}
onChange={(e: string) => setTeam(e)}
/>
</Form.Item>
</Col>
@ -286,7 +298,7 @@ const CompanyEdit = () => {
},
};
}}
dataSource={customerData?.data?.map((u, i) => ({
dataSource={customerData.data?.data?.map((u, i) => ({
...u,
no: i + 1,
key: u?.id,
@ -327,7 +339,40 @@ const CompanyEdit = () => {
},
},
]}
pagination={false}
/>
<Space
style={{ width: "100%", marginTop: 10 }}
direction="vertical"
>
<Space
style={{ width: "100%", justifyContent: "flex-end" }}
wrap
>
<Button
type="primary"
icon={<StepBackwardOutlined />}
onClick={Previos}
disabled={customerData.data?.previous ? false : true}
></Button>
<Input
style={{ width: 50, textAlign: "right" }}
value={page}
onChange={(e) => {
let num = e.target.value;
if (Number(num) && num !== "0") {
setPage(Number(num));
}
}}
/>
<Button
type="primary"
icon={<StepForwardOutlined />}
onClick={Next}
disabled={customerData.data?.next ? false : true}
></Button>
</Space>
</Space>
{open && (
<AddDriver id={id} open={open} setOpen={setOpen} />
)}

@ -16,10 +16,9 @@ import tt from "../../assets/tticon.svg";
const AddCustomer = ({
open,
setOpen,
refetch,
}: {
open: boolean;
refetch: any;
setOpen(open: boolean): void;
}) => {
const [form] = FormAnt.useForm();
@ -66,7 +65,6 @@ const AddCustomer = ({
setOpen(!open);
}
});
refetch();
});
}}
>

@ -11,7 +11,7 @@ import { Button, Input, Space } from "antd";
const Customer = () => {
const [open, setOpen] = useState(false);
const [page, setPage] = useState(1)
const [page, setPage] = useState(1);
const showModal = () => {
setOpen(true);
};
@ -21,7 +21,7 @@ const Customer = () => {
name: search,
is_active: undefined,
page_size: 10,
page: page
page: page,
});
const Next = () => {
@ -50,7 +50,7 @@ const Customer = () => {
const theme = localStorage.getItem("theme") === "true" ? true : false;
return (
<div>
{open && <AddCustomer open={open} setOpen={setOpen} refetch={refetch} />}
{open && <AddCustomer open={open} setOpen={setOpen} />}
<div className="header d-flex">
<p className="title">Drivers</p>
<button className="btn-add d-flex" onClick={showModal}>

@ -25,11 +25,14 @@ const AssignedEdit = ({ recordData, editOpen, setEditOpen }: any) => {
const [customerName, setCustomerName] = useState<string>();
const companyData = useCompanyData({ name: companyName });
const customerData = useCustomerByComanyData({
id: companyId,
name: customerName,
});
const customerData = useCustomerByComanyData(
{
name: customerName,
page: 1,
page_size: 5,
},
companyId
);
const getImageSource = (source: string) => {
switch (source) {
@ -107,7 +110,7 @@ const AssignedEdit = ({ recordData, editOpen, setEditOpen }: any) => {
showSearch
placeholder="Search Driver"
onSearch={(value: any) => setCustomerName(value)}
options={customerData?.data?.map((item) => ({
options={customerData?.data?.data?.map((item) => ({
label: item?.name,
value: item?.id,
}))}

@ -45,18 +45,22 @@ const RequestsEdit = ({
page_size: 5,
for_driver_request: true,
});
const customerDataByCompany = useCustomerByComanyData({
id: companyId,
name: customerName,
for_driver_request: true,
});
const customerDataByCompany = useCustomerByComanyData(
{
name: customerName,
for_driver_request: true,
},
companyId
);
useEffect(() => {
if (companyId && customerDataByCompany) {
const newCustomerOption = customerDataByCompany.data?.map((item) => ({
label: item.name,
value: item.id,
}));
const newCustomerOption = customerDataByCompany.data?.data?.map(
(item) => ({
label: item.name,
value: item.id,
})
);
if (
JSON.stringify(newCustomerOption) !== JSON.stringify(customerOption)

@ -30,7 +30,7 @@ const Stat = () => {
const [startDate, setStartDate] = useState(start_date);
const [endDate, setEndDate] = useState(end_date);
const teamData = useTeamData("");
const teamData = useTeamData({});
const teamOptions: { label: string; value: any }[] | undefined =
teamData?.data?.map((item) => ({
label: item?.name,

@ -11,11 +11,10 @@ import {
Col,
} from "antd";
import { taskController } from "../../API/LayoutApi/tasks";
import { useState } from "react";
import { useEffect, useState } from "react";
import { useServiceData } from "../../Hooks/Services";
import { UploadOutlined } from "@ant-design/icons";
import { useTeamData } from "../../Hooks/Teams";
import { useCompanyData } from "../../Hooks/Companies";
import { useCustomerByComanyData } from "../../Hooks/Customers";
// @ts-ignore
import zippy from "../../assets/zippyicon.svg";
@ -33,6 +32,10 @@ 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 = ({
@ -48,19 +51,87 @@ const AddTask = ({
setOpen(!open);
};
const [fileIds, setFileIds] = useState([]);
const [companyName, setCompanyName] = useState<string>();
const [searchCompanyName, setSearchCompanyName] = useState<string>("");
const [customerName, setCustomerName] = useState<string>();
const [companyId, setCompanyId] = useState<number>();
const [driverOpen, setDriverOpen] = useState(false);
const [openDrive, setOpenDrive] = useState(false);
const [companyData, setCompanyData] = useState<TCompany[]>();
const [customerData, setCustomerData] = useState<TCustomer[]>();
const ServiceData = useServiceData();
const TeamData = useTeamData({});
const TeamData = useTeamData("");
const companyData = useCompanyData({ name: companyName });
const customerData = useCustomerByComanyData({
id: companyId,
name: customerName,
});
// 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);
const [driverOpen, setDriverOpen] = useState(false);
// 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;
@ -103,50 +174,9 @@ const AddTask = ({
return tt;
}
};
const [openDrive, setOpenDrive] = useState(false);
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);
};
return (
<div onPaste={(event) => handlePaste(event)}>
{openDrive && (
<AddCustomer
refetch={customerData.refetch}
open={openDrive}
setOpen={setOpenDrive}
/>
)}
{openDrive && <AddCustomer open={openDrive} setOpen={setOpenDrive} />}
<AddDriver id={companyId} open={driverOpen} setOpen={setDriverOpen} />
<Modal
open={open}
@ -184,8 +214,8 @@ const AddTask = ({
<Select
showSearch
placeholder="Search Company"
onSearch={(value: any) => setCompanyName(value)}
options={companyData?.data?.map((item) => ({
onSearch={(value: any) => setSearchCompanyName(value)}
options={companyData?.map((item) => ({
label: (
<div>
{item?.source && (
@ -200,7 +230,7 @@ const AddTask = ({
),
value: item?.id,
}))}
value={companyName}
value={searchCompanyName}
filterOption={false}
autoClearSearchValue={false}
allowClear
@ -229,7 +259,7 @@ const AddTask = ({
showSearch
placeholder="Search Driver"
onSearch={(value: any) => setCustomerName(value)}
options={customerData?.data?.map((item) => ({
options={customerData?.map((item) => ({
label: item?.name,
value: item?.id,
}))}
@ -248,6 +278,7 @@ const AddTask = ({
justifyContent: "space-between",
marginTop: isMobile ? 5 : 0,
}}
disabled={!companyId}
>
{isMobile && <img src={addicon} alt="" />}
{!isMobile && "Add"}
@ -277,10 +308,14 @@ const AddTask = ({
]}
>
<Select
placeholder="Teams"
options={TeamData?.data?.map((item) => ({
label: item?.name,
value: item?.id,
}))}
onChange={(value) =>
form.setFieldsValue({ assigned_to_id: value })
}
/>
</FormAnt.Item>
</Col>

@ -106,7 +106,7 @@ const TaskModal = ({
}
}
const teamData = useTeamData("");
const teamData = useTeamData({});
// const teamData = useCustomerData({name: "", page: 1, page_size: 100});
const teams: MenuProps["items"] = teamData?.data?.map((item, index) => ({
key: item?.id,
@ -174,30 +174,20 @@ const TaskModal = ({
const statuspatch = (status: string) => {
setStatus(status);
taskController.taskPatch({ status: status }, recordTask?.id).then(() => {
message.success({ content: "Success", duration: 1 });
});
taskController.taskPatch({ status: status }, recordTask?.id);
};
const teampatch = (item: TTeam) => {
setTeamName(item?.name);
taskController
.taskPatch({ assigned_to_id: item?.id }, recordTask?.id)
.taskPatchPatch({ assigned_to_id: item?.id }, recordTask?.id)
.then(() => {
message.success({
content: "Task forwarded successfully",
duration: 1,
});
setModalOpen(false);
});
};
const patchTask = () => {
taskController
.taskPatch({ note: text, pti: pti }, recordTask?.id)
.then(() => {
message.success({ content: "Saved!" });
});
taskController.taskPatch({ note: text, pti: pti }, recordTask?.id);
setModalOpen(!modalOpen);
};

@ -234,7 +234,11 @@ const TaskTable = ({
},
render: (item?: { title?: string; id: number }, record?: TTask) => (
<Tooltip placement="topLeft" title={item?.title}>
{item?.title}
{item?.title === "Break" || item?.title === "PTI" ? (
<p className="status-Rejected">{item?.title}</p>
) : (
<p style={{ textAlign: "center" }}>{item?.title}</p>
)}
</Tooltip>
),
},

@ -117,7 +117,7 @@ const Task = ({
}
}, [socketData]);
const teamData = useTeamData("");
const teamData = useTeamData({});
const teamOptions: { label: string; value: any }[] | undefined =
teamData?.data?.map((item) => ({

@ -6,7 +6,7 @@ import addicon from "../../assets/addiconpng.png";
import AddTeam from "./AddTeam";
const Team = () => {
const { data, isLoading, refetch } = useTeamData("");
const { data, isLoading, refetch } = useTeamData({});
const [open, setOpen] = useState(false);
const showModal = () => {
setOpen(true);

@ -33,10 +33,14 @@ const AddUpdate = ({
const [companyId, setCompanyId] = useState<number>();
const companyData = useCompanyData({ name: companyName });
const customerData = useCustomerByComanyData({
id: companyId,
name: customerName,
});
const customerData = useCustomerByComanyData(
{
name: customerName,
page: 1,
page_size: 10,
},
companyId
);
function handlePaste(event: any) {
const clipboardData = event.clipboardData || window.Clipboard;
@ -117,7 +121,7 @@ const AddUpdate = ({
showSearch
placeholder="Search Driver"
onSearch={(value: any) => setCustomerName(value)}
options={customerData?.data?.map((item) => ({
options={customerData?.data?.data?.map((item) => ({
label: item?.name,
value: item?.id,
}))}

@ -47,7 +47,7 @@ const UserEdit = () => {
refetch();
document.location.replace("/#/users/");
};
const TeamData = useTeamData("");
const TeamData = useTeamData({});
const noTeamOption = { label: " - - - - - -", value: "" };
const TeamOption: { label: string; value: any }[] | undefined =
TeamData?.data?.map((item) => ({

@ -28,7 +28,7 @@ export const useCompanyPaginated = ({
);
};
export const useCompanyOne = (id: number | undefined) => {
export const useCompanyOne = (id: number | string | undefined) => {
return useQuery(
[`company/${id}/`, id],
() => companyController.companyOne(id),

@ -1,6 +1,5 @@
import { useQuery } from "react-query";
import {
TCustomerByCompanyGetParams,
TCustomerGetParams,
customerController,
} from "../../API/LayoutApi/customers";
@ -26,14 +25,13 @@ export const useCustomerData = ({
);
};
export const useCustomerByComanyData = ({
name,
id,
for_driver_request,
}: TCustomerByCompanyGetParams) => {
export const useCustomerByComanyData = (
obj: TCustomerGetParams,
id?: number
) => {
return useQuery(
[`customers-by-company/${id}`, name, for_driver_request],
() => customerController.customerByCompany(id, name, for_driver_request),
[`customers-by-company/${id}`, obj],
() => customerController.customerByCompany(obj, id),
{ refetchOnWindowFocus: false }
);
};

@ -1,10 +1,14 @@
import { useQuery } from "react-query";
import { teamController } from "../../API/LayoutApi/teams";
import { TTeamGetParams, teamController } from "../../API/LayoutApi/teams";
export const useTeamData = (name: string) => {
return useQuery([`teams/?name=${name}/`], () => teamController.read(name), {
refetchOnWindowFocus: false,
});
export const useTeamData = ({ name, company_id }: TTeamGetParams) => {
return useQuery(
[`teams`, name, company_id],
() => teamController.read({ name, company_id }),
{
refetchOnWindowFocus: false,
}
);
};
export const useTeamOne = (teamId: number | string | undefined): any => {

Loading…
Cancel
Save