diff --git a/build.zip b/build.zip index add7793..418566c 100644 Binary files a/build.zip and b/build.zip differ diff --git a/src/API/LayoutApi/callrequests.ts b/src/API/LayoutApi/callrequests.ts index 00976d3..3ba238b 100644 --- a/src/API/LayoutApi/callrequests.ts +++ b/src/API/LayoutApi/callrequests.ts @@ -1,23 +1,26 @@ import { message } from "antd"; import { TCall } from "../../types/CallRequests/TCall"; import instance from "../api"; +import { TPagination } from "../../types/common/TPagination"; export const callController = { - async read(obj: { status: string }) { + async read(obj: { status: string; page: number; page_size: number }) { const params = { ...obj }; if (!!obj.status) params.status = obj.status; + if (!!obj.page) params.page = obj.page; + if (!!obj.page_size) params.page_size = obj.page_size; - const { data } = await instance.get(`callback-requests/`, { - params, - }); + const { data } = await instance.get>( + `callback-requests/`, + { + params, + } + ); return data; }, - async callPatch( - obj: { note?: string; status?: string }, - id: number - ) { + async callPatch(obj: { note?: string; status?: string }, id: number) { const params = { ...obj }; if (!!obj.note) params.note = obj.note; if (!!obj.status) params.status = obj.status; @@ -26,7 +29,7 @@ export const callController = { .put(`callback-request/${id}/`, params) .then((u) => { setTimeout(() => { - message.success({ content: "Loaded!", duration: 2 }); + message.success({ content: "Success!", duration: 2 }); }, 1000); return u; }); diff --git a/src/API/LayoutApi/companies.ts b/src/API/LayoutApi/companies.ts index 971726c..85a53bd 100644 --- a/src/API/LayoutApi/companies.ts +++ b/src/API/LayoutApi/companies.ts @@ -1,11 +1,13 @@ import { TCompany } from "../../types/Company/TCompany"; +import { TPagination } from "../../types/common/TPagination"; import instance from "../api"; import { message } from "antd"; export type TCompanyGetParams = { name?: string; - page?: string | number; + page?: number; is_active?: boolean; + page_size?: number; }; export type TCompanyPutParams = { name?: string; @@ -29,7 +31,23 @@ export const companyController = { if (!!filterObject.is_active) params.is_active = filterObject.is_active; if (!!filterObject.page) params.page = filterObject.page; - const { data } = await instance.get(`companies/`, { params }); + const { data } = await instance.get(`companies/`, { + params, + }); + + return data; + }, + async readPaginated(filterObject: TCompanyGetParams) { + const params = { ...filterObject }; + + if (!!filterObject.name) params.name = filterObject.name; + if (!!filterObject.is_active) params.is_active = filterObject.is_active; + if (!!filterObject.page) params.page = filterObject.page; + if (!!filterObject.page_size) params.page_size = filterObject.page_size; + + const { data } = await instance.get>(`companies/`, { + params, + }); return data; }, diff --git a/src/API/LayoutApi/customers.ts b/src/API/LayoutApi/customers.ts index 7b6eaad..44e22f4 100644 --- a/src/API/LayoutApi/customers.ts +++ b/src/API/LayoutApi/customers.ts @@ -1,16 +1,19 @@ import { TCustomer } from "../../types/Customer/TCustomer"; +import { TPagination } from "../../types/common/TPagination"; import instance from "../api"; import { message } from "antd"; export type TCustomerGetParams = { name?: string; - pageSize?: string | number; + page_size?: string | number; page?: string | number; + for_driver_request?: boolean; is_active?: boolean; }; export type TCustomerByCompanyGetParams = { name?: string; - id?: string; + id?: number; + for_driver_request?: boolean; }; export type TCustomerPutParams = { name?: string; @@ -29,9 +32,14 @@ export const customerController = { if (!!filterObject.name) params.name = filterObject.name; if (!!filterObject.is_active) params.is_active = filterObject.is_active; if (!!filterObject.page) params.page = filterObject.page; - if (!!filterObject.page) params.pageSize = filterObject.pageSize; + if (!!filterObject.page_size) params.page_size = filterObject.page_size; + if (!!filterObject.for_driver_request) + params.for_driver_request = filterObject.for_driver_request; - const { data } = await instance.get(`customers/`, { params }); + const { data } = await instance.get>( + `customers/`, + { params } + ); return data; }, @@ -42,9 +50,14 @@ export const customerController = { } }, - async customerByCompany(id: string | undefined, name: string | undefined) { - const params = { name }; + 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( `customers-by-company/${id}/`, diff --git a/src/API/LayoutApi/profile.ts b/src/API/LayoutApi/profile.ts index ce652a4..e69ef69 100644 --- a/src/API/LayoutApi/profile.ts +++ b/src/API/LayoutApi/profile.ts @@ -67,6 +67,11 @@ export const prof = { `users/my-profile/`, { ...params } ); + message.success({ content: "Changes saved" }); + if (params.username) { + localStorage.setItem("username", params.username); + } + window.location.reload() return data; } catch (error: any) { setTimeout(() => { diff --git a/src/API/LayoutApi/requests.ts b/src/API/LayoutApi/requests.ts index 020c0f9..1112b6f 100644 --- a/src/API/LayoutApi/requests.ts +++ b/src/API/LayoutApi/requests.ts @@ -1,10 +1,14 @@ import { message } from "antd"; import { TRequests } from "../../types/Requests/TRequests"; import instance from "../api"; +import { TPagination } from "../../types/common/TPagination"; export type TRequestsGetParams = { search?: string; status?: string; + for_driver_request?: boolean; + page?: number; + page_size?: number; }; export const requestsController = { @@ -13,10 +17,17 @@ export const requestsController = { if (!!filterObject.search) params.search = filterObject.search; if (!!filterObject.status) params.status = filterObject.status; + if (!!filterObject.page) params.page = filterObject.page; + if (!!filterObject.page_size) params.page_size = filterObject.page_size; + if (!!filterObject.for_driver_request) + params.for_driver_request = filterObject.for_driver_request; - const { data } = await instance.get(`driver-requests/`, { - params, - }); + const { data } = await instance.get>( + `driver-requests/`, + { + params, + } + ); return data; }, @@ -36,16 +47,27 @@ export const requestsController = { }); return data; }, + async rejectPatch(obj: TRequestsGetParams, id: string | number | undefined) { + const { data } = await instance + .patch(`driver-request/${id}/`, obj) + .then((u) => { + setTimeout(() => { + message.success({ content: "Loaded!", duration: 2 }); + }, 1000); + return u; + }); + return data; + }, async delete(id: string | number | undefined) { let res; let error = ""; try { const { data } = await instance - .patch(`driver-request/${id}/`, { status: "Rejected" }) + .delete(`driver-request/${id}/`) .then((u) => { setTimeout(() => { - message.success({ content: "Rejected!", key: id, duration: 2 }); + message.success({ content: "Deleted!", key: id, duration: 2 }); }, 1000); return u; }); diff --git a/src/API/LayoutApi/services.ts b/src/API/LayoutApi/services.ts index 41d2c52..273c868 100644 --- a/src/API/LayoutApi/services.ts +++ b/src/API/LayoutApi/services.ts @@ -38,7 +38,10 @@ export const serviceController = { } catch (error: any) { setTimeout(() => { message.error({ - content: error?.response?.data?.title, + content: + error?.response?.data?.title || + error?.response?.data?.points || + "Something went wrong!", key: 2, duration: 2, }); diff --git a/src/API/LayoutApi/tasks.ts b/src/API/LayoutApi/tasks.ts index b89a3e9..5d1a1a7 100644 --- a/src/API/LayoutApi/tasks.ts +++ b/src/API/LayoutApi/tasks.ts @@ -1,12 +1,15 @@ +import { message } from "antd"; import { TTask, TTaskHistory } from "../../types/Tasks/TTasks"; import { TPagination } from "../../types/common/TPagination"; import instance from "../api"; +import { isMobile } from "../../App"; export type TTasksGetParams = { search?: string; status?: string; team?: string; - page?: string; + page?: number; + page_size: number; }; export type TTasksPutParams = { @@ -45,8 +48,9 @@ export const taskController = { async read(filterObject: TTasksGetParams) { const params = { ...filterObject }; - if (!!filterObject.page && filterObject.page !== "0") + if (!!filterObject.page && filterObject.page !== 0) params.page = filterObject.page; + params.page_size = isMobile ? 10 : 15; if (!!filterObject.search) params.search = filterObject.search; if (Array.isArray(filterObject.status)) { params.status = filterObject.status.join(","); @@ -66,7 +70,7 @@ export const taskController = { return data; }, - async taskOne(Id: number) { + async taskOne(Id: number | undefined) { const { data } = await instance.get(`task/${Id}/`); return data; }, @@ -97,7 +101,6 @@ export const taskController = { for (const file of formData.files) { form.append("files", file); } - console.log(form); // if (Array.isArray(formData.files)) { // params.files = formData.files; @@ -106,13 +109,17 @@ export const taskController = { // 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", - }, - }); - return data; + try { + const { data } = await instance.post("attachment/", form, { + headers: { + "Content-Type": "multipart/form-data", + }, + }); + message.success({ content: "Success!" }); + return data; + } catch (err) { + message.error({ content: `${err}` }); + } }, async deleteTaskController(id: number) { diff --git a/src/API/LayoutApi/users.ts b/src/API/LayoutApi/users.ts index 668e604..3e9af08 100644 --- a/src/API/LayoutApi/users.ts +++ b/src/API/LayoutApi/users.ts @@ -44,7 +44,7 @@ export const userController = { }, async userOne(Id: string | number | undefined) { - const { data }: { data: any } = await instance(`users/admin/${Id}/`); + const { data } = await instance.get(`users/admin/${Id}/`); return data; }, diff --git a/src/API/api.ts b/src/API/api.ts index 3a7033a..6c0d45b 100644 --- a/src/API/api.ts +++ b/src/API/api.ts @@ -1,11 +1,11 @@ import axios from "axios"; -const instance = axios.create({ - baseURL: "http://10.10.10.45:8080/api/v1/", -}); // const instance = axios.create({ -// baseURL: "https://api.tteld.co/api/v1/", +// baseURL: "http://10.10.10.12:8080/api/v1/", // }); +const instance = axios.create({ + baseURL: "https://api.tteld.co/api/v1/", +}); const token: string | null = localStorage.getItem("access"); if (token) { diff --git a/src/API/auth/Login.ts b/src/API/auth/Login.ts index f5b9489..322373b 100644 --- a/src/API/auth/Login.ts +++ b/src/API/auth/Login.ts @@ -13,20 +13,21 @@ export const LoginApi = async ({ username, password }: loginInterface) => { data: { username, password }, headers: { "Content-Type": "application/json" }, }); - console.log(data); - const userObject = { id: data?.data?.id, first_name: data?.data?.first_name, last_name: data?.data?.last_name, username: data?.data?.username, - timezone: data?.data?.timezone, + email: data?.data?.email, role: data?.data?.role, - team_id: data?.data?.team_id, + team: data?.data?.team, + business: data?.data?.business, + timezone: data?.data?.timezone || data?.data?.business?.timezone, }; const userJSON = JSON.stringify(userObject); localStorage.setItem("user", userJSON); + localStorage.setItem("username", data?.data?.username); localStorage.setItem("access", data?.data.access); localStorage.setItem("refresh", data?.data.refresh); localStorage.setItem("admin_id", data?.data.id); diff --git a/src/API/auth/activate.ts b/src/API/auth/activate.ts index bd82789..b006a9a 100644 --- a/src/API/auth/activate.ts +++ b/src/API/auth/activate.ts @@ -27,17 +27,17 @@ export const registryVerify = async (value: activateInterface) => { timezone: data?.data.timezone, role: data?.data.role, }; + console.log(data); + const userJSON = JSON.stringify(userObject); localStorage.setItem("user", userJSON); - localStorage.setItem("access_token", data?.data.access_token); - localStorage.setItem("refresh_token", data?.data.refresh_token); + localStorage.setItem("access", data?.data.access); + localStorage.setItem("refresh", data?.data.refresh); document.location.replace("/"); return status; } catch (error) { - console.log(error); - setTimeout(() => { message.error({ content: "Something went wrong", duration: 2 }); }, 1000); diff --git a/src/API/auth/register.ts b/src/API/auth/register.ts index 1c2c2d3..a895e4b 100644 --- a/src/API/auth/register.ts +++ b/src/API/auth/register.ts @@ -33,7 +33,6 @@ export const RegisterApi = async (value: registerInterface) => { document.location.replace("/"); return status; } catch (error:any) { - console.log(error); setTimeout(() => { message.error({ content: ' ', duration: 2 }); }, 1000); diff --git a/src/API/auth/resetPass.ts b/src/API/auth/resetPass.ts index e0f6908..b6af69f 100644 --- a/src/API/auth/resetPass.ts +++ b/src/API/auth/resetPass.ts @@ -42,4 +42,4 @@ export const resetPassEmail = async (value: resetPassType) => { message.error({ content: "Something went wrong", duration: 2 }); }, 1000); } -}; +} diff --git a/src/App.css b/src/App.css index 13e4b33..b7e640e 100644 --- a/src/App.css +++ b/src/App.css @@ -257,6 +257,14 @@ justify-content: end; } +.mobile-filter { + display: flex; + align-items: end; + justify-content: space-between; + flex-direction: column; +} + + .search-input-false { border: none; outline: none; @@ -561,7 +569,7 @@ display: flex; align-items: center; justify-content: space-between; - margin: 20px 24px 24px; + margin: 12px 24px 12px; } .TaskModal-header-dark { display: flex; @@ -641,9 +649,9 @@ color: rgb(211, 211, 211); } -.info-div { - margin: 16px 24px; -} +/* .info-div { + margin: 0 !important; +} */ .info-body { border-radius: 12px; @@ -765,3 +773,21 @@ align-items: center; justify-content: space-between; } + +.call-requests { + background: rgba(246, 137, 0, 1); + padding: 3px 5px; + border-radius: 20px; + font-size: 10px; + margin-left: 5px; + color: #000000; +} + +.call-none { + display: none; +} + +.ant-upload-list-text{ + overflow: scroll; + height: 50px; +} \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 66afc36..ba0fea8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,29 +1,58 @@ -import React, { useEffect, useState } from "react"; +import React, { useCallback, useEffect, useState } from "react"; import "./App.css"; -import { Layout, Menu, ConfigProvider, Dropdown } from "antd"; +import { Layout, Menu, ConfigProvider, Dropdown, notification } from "antd"; import { Routes, Route, Navigate, useLocation } from "react-router-dom"; -import { allMenu, mainItems, superItems } from "./Utils/sidebar"; +import { mainItems, superItems } from "./Utils/sidebar"; import Login from "./Auth/Login"; import Notfound from "./Utils/Notfound"; import { LogoutApi } from "./API/auth/Logout"; import { Link } from "react-router-dom"; +import { MenuProps } from "antd"; // @ts-ignore import themeBtn from "./assets/theme-btn.svg"; // @ts-ignore import avatar from "./assets/avatar-img.svg"; +// @ts-ignore +import taskIcon from "./assets/tasknavicon.png"; +// @ts-ignore +import companyIcon from "./assets/companynavicon.png"; +// @ts-ignore +import serviceIcon from "./assets/servicenavicon.png"; +// @ts-ignore +import teamIcon from "./assets/teamnavicon.png"; +// @ts-ignore +import statisticIcon from "./assets/statnavicon.png"; +// @ts-ignore +import updateIcon from "./assets/updatenavicon.png"; +// @ts-ignore +import userIcon from "./assets/usernavicon.png"; +// @ts-ignore +import driverIcon from "./assets/customersIcon.png"; +// @ts-ignore +import requestIcon from "./assets/requestIcon.png"; +// @ts-ignore +import callIcon from "./assets/callIcon.png"; import Register from "./Auth/Register"; import Activate from "./Auth/Activate"; import Invite from "./Auth/Invite"; import ResetPassword from "./Auth/ResetPassword"; import ResetByEmail from "./Auth/ResetByEmail"; - +import { NotificationPlacement } from "antd/es/notification/interface"; +import { TCall } from "./types/CallRequests/TCall"; +import Task from "./Components/Tasks/Tasks"; +import Requests from "./Components/Requests/Requests"; +import { callController } from "./API/LayoutApi/callrequests"; +import Call from "./Components/CallRequests/Call"; +import { dark, light } from "./Utils/styles"; const { Header, Sider, Content } = Layout; const userJSON: any = localStorage.getItem("user"); const userObject = JSON.parse(userJSON); export const timeZone = userObject?.timezone; export const role = userObject?.role; export const admin_id = localStorage.getItem("admin_id"); -export const team_id = userObject?.team_id; +export const team_id = userObject?.team?.id; +export const isMobile = window.innerWidth <= 768; +const username = localStorage.getItem("username"); const App: React.FC = () => { const isAuthenticated = localStorage.getItem("access") as string; @@ -34,6 +63,126 @@ const App: React.FC = () => { const [theme, setTheme] = useState( localStorage.getItem("theme") === "true" ? true : false ); + const [calls, setCalls] = useState(0); + const [data, setData] = useState(); + useEffect(() => { + if (admin_id) { + callController + .read({ status: "Awaiting", page: 1, page_size: 100 }) + .then((data: any) => { + setData(data); + }); + } + }, [admin_id]); + + useEffect(() => { + if (data) { + setCalls(data.data?.length); + } + }, [data]); + type MenuItem = Required["items"][number]; + + function getItem( + label: React.ReactNode, + key: React.Key, + icon?: React.ReactNode, + children?: MenuItem[] + ): MenuItem { + return { + key, + icon, + children, + label, + } as MenuItem; + } + const allMenu: MenuItem[] = [ + getItem(Tasks, "/", ), + getItem( + Companies, + "companies/", + + ), + getItem( + Drivers, + "customers/", + + ), + getItem( + Services, + "services/", + + ), + ]; + + if (role === "Tech Support") { + allMenu.push( + getItem( + Users, + "users/", + + ), + getItem( + Teams, + "teams/", + + ), + getItem( + Updates, + "updates/", + + ), + getItem( + Driver Requests, + "requests/", + + ), + getItem( + Call Requests, + "call/", + + ) + ); + } + + if (role === "Owner") { + allMenu.push( + getItem( + Users, + "users/", + + ), + getItem( + Teams, + "teams/", + + ), + getItem( + Statistics, + "stats/", + + ), + getItem( + Updates, + "updates/", + + ), + getItem( + Driver Requests, + "requests/", + + ), + getItem( + + Call Requests{" "} + + {calls} + + , + "calls/", + + ) + ); + } useEffect(() => { localStorage.setItem("theme", theme); @@ -46,172 +195,7 @@ const App: React.FC = () => { const clickLogout = () => { LogoutApi(); }; - const dark = { - components: { - Table: { - colorBgContainer: "#202020", - colorText: "#BBBBBB", - headerColor: "#BBBBBB", - borderColor: "#3A3A3A", - headerSplitColor: "#3A3A3A", - rowHoverBg: "#333333", - colorBorder: "#3A3A3A", - }, - Layout: { - bodyBg: "#181818", - }, - Input: { - colorBgContainer: "#2A2A2A", - colorBgContainerDisabled: "#2A2A2A", - colorText: "#BBBBBB", - colorTextPlaceholder: "#BBBBBB", - colorBorder: "#3A3A3A", - colorFillSecondary: "rgba(0, 0, 0, 0.02)", - activeBorderColor: "#3A3A3A", - activeShadow: "#3A3A3A", - hoverBorderColor: "#3A3A3A", - // colorIcon: "#BBBBBB", - // colorIconHover: "#BBBBBB", - }, - Select: { - colorBgContainer: "#2A2A2A", - colorText: "#BBBBBB", - colorTextPlaceholder: "#BBBBBB", - colorBorder: "rgba(150, 150, 150, 0.493)", - colorPrimaryHover: "rgba(249, 158, 44, 1)", - colorIconHover: "#BBB", - optionSelectedBg: "#2A2A2A", - colorBgElevated: "#333", - controlOutline: "none", - optionActiveBg: "#333333", - colorTextQuaternary: "#3A3A3A", - }, - Button: { - colorBorderSecondary: "rgba(249, 158, 44, 1)", - colorPrimary: "rgba(249, 158, 44, 1)", - colorPrimaryHover: "#BBBBBB", - colorIcon: "rgba(249, 158, 44, 1)", - colorIconHover: "rgba(249, 158, 44, 1)", - primaryShadow: "none", - dangerShadow: "none", - colorTextDisabled: "#AAAAAA", - borderColorDisabled: "#3A3A3A", - }, - // Form: { - // labelColor: "#BBBBBB", - // }, - Tabs: { - itemColor: "#BBBBBB", - itemHoverColor: "#FFFFFF", - itemSelectedColor: "rgba(249, 158, 44, 1)", - colorPrimaryActive: "rgba(249, 158, 44, 1)", - inkBarColor: "rgba(249, 158, 44, 1)", - }, - // Upload: { - // colorText: "#FFFFFF", - // colorInfoBgHover: "#1E1E1E", - // }, - // Pagination: { - // colorText: "#BBBBBB", - // colorPrimary: "#FFFFFF", - // colorBgContainer: "#1A1A1A", - // colorBorderSecondary: "#3A3A3A", - // }, - Modal: { - contentBg: "#3A3A3A", - headerBg: "#3A3A3A", - titleColor: "#FFFFFF", - colorText: "#BBBBBB", - colorBgTextActive: "#BBBBBB", - colorBgTextHover: "#BBBBBB", - }, - Menu: { - darkItemSelectedBg: "#3A3A3A", - colorBgContainer: "#fff", - }, - Switch: { - colorPrimary: "#565656", - colorPrimaryHover: "#737373", - }, - Radio: { - colorText: "#737373", - colorBorder: "#3A3A3A", - colorPrimaryActive: "#BBBBBB", - buttonCheckedBg: "rgba(249, 158, 44, 1)", - colorPrimaryHover: "#737373", - colorPrimary: "#565656", - }, - Dropdown: { - colorBgContainer: "#3A3A3A", - colorText: "#BBBBBB", - colorPrimaryHover: "#565656", - colorPrimary: "#333333", - }, - DatePicker: { - colorBgContainer: "#3A3A3A", - colorBgElevated: "#3A3A3A", - colorText: "#BBBBBB", - colorTextPlaceholder: "#BBBBBB", - colorIcon: "#fff", - colorIconHover: "#fff", - colorPrimary: "rgba(249, 158, 44, 1)", - hoverBorderColor: "#BBBBBB", - }, - Empty: { - colorText: "rgba(249, 158, 44, 1)", - colorTextDisabled: "rgba(249, 158, 44, 1)", - }, - }, - token: { - fontFamily: "Inter, sans-serif", - colorText: "#bbb", - borderRadius: 8, - }, - }; - const light = { - components: { - Table: { - rowHoverBg: "#bae0ff", - headerBg: "none", - colorText: "rgba(24, 26, 41, 1)", - fontWeightStrong: 500, - colorTextHeading: "rgba(161, 162, 171, 1)", - }, - Select: { - colorTextPlaceholder: "rgba(155, 157, 170, 1)", - colorPrimary: "rgba(249, 158, 44, 1)", - colorPrimaryHover: "rgba(249, 158, 44, 1)", - }, - Tabs: { - inkBarColor: "rgba(249, 158, 44, 1)", - itemSelectedColor: "rgba(24, 26, 41, 1)", - itemHoverColor: "rgba(24, 26, 41, 1)", - }, - Input: { - hoverBorderColor: "rgba(249, 158, 44, 1)", - activeBorderColor: "rgba(249, 158, 44, 1)", - colorTextPlaceholder: "rgba(155, 157, 170, 1)", - }, - Upload: { - colorPrimaryHover: "rgba(249, 158, 44, 1)", - }, - Button: { - colorPrimary: "rgba(249, 158, 44, 1)", - colorPrimaryHover: "rgba(249, 158, 44, 1)", - }, - Textarea: { - colorBorder: "0px 1px 3px 0px rgba(20, 22, 41, 0.1)", - }, - Menu: { - darkItemSelectedBg: "rgba(255, 255, 255, 0.08)", - }, - }, - token: { - fontFamily: "Inter, sans-serif", - color: "#262626", - borderRadius: 8, - }, - }; + const rep = () => { document.location.replace("/"); }; @@ -225,6 +209,63 @@ const App: React.FC = () => { ); + let taskSocket: WebSocket; + const [isLive, setIslive] = useState(true); + const [socketData, setSocketData] = useState(); + const connect = async () => { + try { + if ( + (!taskSocket || taskSocket.readyState === WebSocket.CLOSED) && + admin_id + ) { + // taskSocket = new WebSocket( + // `ws://10.10.10.12:8080/global/?user_id=${admin_id}` + // ); + taskSocket = new WebSocket( + `wss://api.tteld.co/global/?user_id=${admin_id}` + ); + + taskSocket.addEventListener("open", (event) => { + setIslive(true); + }); + taskSocket.addEventListener("message", (event) => { + const newData: any = JSON.parse(event.data); + setSocketData(newData); + }); + taskSocket.addEventListener("error", (errorEvent) => { + console.error("WebSocket error:", errorEvent); + }); + taskSocket.addEventListener("close", (event) => { + setIslive(false); + }); + } + } catch (err) {} + }; + + useEffect(() => { + connect(); + }, []); + const [api, contextHolder] = notification.useNotification(); + const openNotification = useCallback( + (placement: NotificationPlacement, data: TCall) => { + api.info({ + message: `Driver ${data?.driver?.name} from ${data?.company?.name} company has made a call request`, + placement, + }); + }, + [api] + ); + useEffect(() => { + if (socketData?.type === "callback_request") { + let status = socketData?.callback_request.status; + if (status === "Awaiting") { + openNotification("bottomRight", socketData?.callback_request); + setCalls((prev: any) => prev + 1); + } else if (status === "Resolved" && calls !== 0) { + setCalls((prev: any) => prev - 1); + } + } + }, [socketData, openNotification]); return ( @@ -253,91 +294,134 @@ const App: React.FC = () => { )} {authorized ? ( - setCollapsed(value)} - style={{ - height: "100vh", - background: theme === true ? "#202020" : "rgba(20, 22, 41, 1)", - }} - > -

- TT ELD -

- + ) : ( + setCollapsed(value)} style={{ + height: "100vh", background: theme === true ? "#202020" : "rgba(20, 22, 41, 1)", - color: "rgba(255, 255, 255, 0.6)", - }} - > -
- -
-
+ TT ELD +

+ + + )} + + {isMobile ? ( +
+
+ +
+ ) : ( +
- - -
e.preventDefault()} + + +
e.preventDefault()} + > +
+
+ +
+
+

+ {username} + {isLive ? ( +

+
+

+ online +

+
+ ) : ( +
+
+

offline

+
+ )} +

+
-
-
-
-
+ + + + )} { }} > + } + /> {mainItems && mainItems.map((u) => ( @@ -357,6 +446,20 @@ const App: React.FC = () => { superItems.map((u) => ( ))} + {superItems && ( + } + /> + )} + {superItems && ( + } + /> + )} } /> diff --git a/src/Auth/Activate.tsx b/src/Auth/Activate.tsx index 96b5202..c345e03 100644 --- a/src/Auth/Activate.tsx +++ b/src/Auth/Activate.tsx @@ -1,6 +1,6 @@ -import { Navigate, useLocation } from "react-router-dom"; +import { useLocation } from "react-router-dom"; import { registryVerify } from "../API/auth/activate"; -import { message } from "antd"; + const Activate = () => { const location = useLocation(); @@ -15,7 +15,7 @@ const Activate = () => { }) } - return
; + return

OOOOOOO Bratim qandoysiz?!

; }; export default Activate; diff --git a/src/Auth/Invite.tsx b/src/Auth/Invite.tsx index 2b0855a..eb0d171 100644 --- a/src/Auth/Invite.tsx +++ b/src/Auth/Invite.tsx @@ -16,8 +16,6 @@ const Invite = () => { role_id: role_id, business_id: business_id, }).then((status) => { - console.log(status); - if (status === 200) { document.location.replace("/"); } diff --git a/src/Auth/Login.tsx b/src/Auth/Login.tsx index 0c7c054..63ad056 100644 --- a/src/Auth/Login.tsx +++ b/src/Auth/Login.tsx @@ -3,6 +3,7 @@ import { Button, Card, Input, Space } from "antd"; import { Form, Field } from "react-final-form"; import { LockOutlined, UserOutlined } from "@ant-design/icons"; import { LoginApi } from "../API/auth/Login"; +import { Link } from "react-router-dom"; const Login: React.FC = () => { const validate = (val: any) => { @@ -106,12 +107,12 @@ const Login: React.FC = () => { > Log In - {/*
+
Forgot password?
Don't have an account? Create one now -
*/} + diff --git a/src/Auth/Register.tsx b/src/Auth/Register.tsx index ee7dd75..d24064d 100644 --- a/src/Auth/Register.tsx +++ b/src/Auth/Register.tsx @@ -71,7 +71,7 @@ const Register: React.FC = () => { }} >

Sign up

- {emailDom && ( + {/* { && ( */} { - {/* { placeholder="E-mail" /> )} - */} + { - )} + {/* )} */} diff --git a/src/Components/CallRequests/Call.tsx b/src/Components/CallRequests/Call.tsx index ba1998c..53fd7b0 100644 --- a/src/Components/CallRequests/Call.tsx +++ b/src/Components/CallRequests/Call.tsx @@ -1,11 +1,74 @@ -import React, { useState } from "react"; +import { useEffect, useState } from "react"; import CallTable from "./CallTable"; +import { StepForwardOutlined, StepBackwardOutlined } from "@ant-design/icons"; import { useCallData } from "../../Hooks/CallRequests"; -import { Radio, RadioChangeEvent } from "antd"; +import { Button, Input, Radio, RadioChangeEvent, Space } from "antd"; +import { TCall } from "../../types/CallRequests/TCall"; +import { TSocket } from "../../types/common/TSocket"; -const Call = () => { +const Call = ({ socketData }: { socketData: TSocket | undefined }) => { const [status, setStatus] = useState("Awaiting"); - const { data, isLoading, refetch } = useCallData({ status: status }); + const [page, setPage] = useState(1); + const [tableData, setTableData] = useState(); + const { data, isLoading, refetch } = useCallData({ + status: status, + page: page, + page_size: 10, + }); + + useEffect(() => { + setTableData(data?.data); + }, [data]); + useEffect(() => { + let dataStatus = socketData?.callback_request?.status; + if (socketData?.type === "callback_request") { + if (status === "Awaiting") { + setTableData((prev) => { + if (prev && prev.length >= 15) { + prev.pop(); + } + if (dataStatus === "Resolved") { + const data = (prev || []).filter( + (b: TCall) => b?.id !== socketData?.callback_request?.id + ); + return data; + } + if (dataStatus === "Awaiting") { + return [socketData?.callback_request, ...(prev || [])] as TCall[]; + } + return prev; + }); + } else if (status === "Resolved") { + setTableData((prev) => { + if (prev && prev.length >= 15) { + prev.pop(); + } + if (dataStatus === "Awaiting") { + const data = (prev || []).filter( + (b: TCall) => b?.id !== socketData?.callback_request?.id + ); + return data; + } + if (dataStatus === "Resolved") { + return [socketData?.callback_request, ...(prev || [])] as TCall[]; + } + return prev; + }); + } + } + }, [socketData]); + + const Next = () => { + const a = Number(page) + 1; + setPage(a); + }; + const Previos = () => { + Number(page); + if (page > 1) { + const a = Number(page) - 1; + setPage(a); + } + }; return (
@@ -25,7 +88,33 @@ const Call = () => {
- + + + + + { + let num = e.target.value; + if (Number(num) && num !== "0") { + setPage(Number(num)); + } + }} + /> + + + ); }; diff --git a/src/Components/CallRequests/CallTable.tsx b/src/Components/CallRequests/CallTable.tsx index 72f9985..2747b88 100644 --- a/src/Components/CallRequests/CallTable.tsx +++ b/src/Components/CallRequests/CallTable.tsx @@ -11,6 +11,7 @@ import { RefetchQueryFilters, } from "react-query"; import { useState } from "react"; +import { TPagination } from "../../types/common/TPagination"; const CallTable = ({ data, isLoading, @@ -20,7 +21,7 @@ const CallTable = ({ isLoading: boolean; refetch: ( options?: (RefetchOptions & RefetchQueryFilters) | undefined - ) => Promise>; + ) => Promise, unknown>>; }) => { const statusClick = (record: TCall | any) => { callController diff --git a/src/Components/Companies/AddCompanies.tsx b/src/Components/Companies/AddCompanies.tsx index 36e0bc5..a6e1d94 100644 --- a/src/Components/Companies/AddCompanies.tsx +++ b/src/Components/Companies/AddCompanies.tsx @@ -6,6 +6,7 @@ import { RefetchQueryFilters, } from "react-query"; import { TCompany } from "../../types/Company/TCompany"; +import { TPagination } from "../../types/common/TPagination"; const AddCompany = ({ open, @@ -14,7 +15,7 @@ const AddCompany = ({ }: { refetch: ( options?: (RefetchOptions & RefetchQueryFilters) | undefined - ) => Promise>; + ) => Promise, unknown>>; open: boolean; setOpen(open: boolean): void; }) => { diff --git a/src/Components/Companies/Companies.tsx b/src/Components/Companies/Companies.tsx index 8133ec2..3136111 100644 --- a/src/Components/Companies/Companies.tsx +++ b/src/Components/Companies/Companies.tsx @@ -1,12 +1,15 @@ import { useRef, useState } from "react"; import AddCompany from "./AddCompanies"; import CompanyTable from "./CompaniesTable"; +import { StepForwardOutlined, StepBackwardOutlined } from "@ant-design/icons"; +import { useCompanyPaginated } from "../../Hooks/Companies"; +import { Button, Input, Space } from "antd"; // @ts-ignore import IconSearch from "../../assets/searchIcon.png"; - -import { useCompanyData } from "../../Hooks/Companies"; //@ts-ignore import addicon from "../../assets/addiconpng.png"; +import { role } from "../../App"; + const theme = localStorage.getItem("theme") === "true" ? true : false; const Company = () => { @@ -15,10 +18,13 @@ const Company = () => { setOpen(true); }; - const [search, setSearch] = useState(""); - const { data, isLoading, refetch } = useCompanyData({ + const [search, setSearch] = useState(); + const [page, setPage] = useState(1); + const { data, isLoading, refetch } = useCompanyPaginated({ name: search, is_active: undefined, + page: page, + page_size: 10, }); const timerRef = useRef(null); @@ -33,19 +39,33 @@ const Company = () => { }, 1000); }; + const Next = () => { + const a = Number(page) + 1; + setPage(a); + }; + const Previos = () => { + Number(page); + if (page > 1) { + const a = Number(page) - 1; + setPage(a); + } + }; + return (
{open && }

Companies

- + {role !== "Checker" && ( + + )}
@@ -59,7 +79,33 @@ const Company = () => {
- + + + + + { + let num = e.target.value; + if (Number(num) && num !== "0") { + setPage(Number(num)); + } + }} + /> + + +
); }; diff --git a/src/Components/Companies/CompaniesEdit.tsx b/src/Components/Companies/CompaniesEdit.tsx index 3a7e771..f308dca 100644 --- a/src/Components/Companies/CompaniesEdit.tsx +++ b/src/Components/Companies/CompaniesEdit.tsx @@ -21,8 +21,9 @@ import { DashboardOutlined } from "@ant-design/icons"; import Notfound from "../../Utils/Notfound"; import Table from "antd/es/table"; import AddDriver from "./AddDriver"; +import { role } from "../../App"; +import { useTeamData } from "../../Hooks/Teams"; import { useCustomerByComanyData } from "../../Hooks/Customers"; - // @ts-ignore import zippy from "../../assets/zippyicon.svg"; // @ts-ignore @@ -39,9 +40,6 @@ import tagIcon from "../../assets/tagIcon.png"; import infoIcon from "../../assets/infoIcon.png"; // @ts-ignore import infoIconActive from "../../assets/infoIconActive.png"; -import { role } from "../../App"; -import { useTeamData } from "../../Hooks/Teams"; -import { validateLocaleAndSetLanguage } from "typescript"; const TabPane = Tabs.TabPane; type params = { readonly id: any; @@ -79,7 +77,6 @@ const CompanyEdit = () => { }; const [value, setValue] = useState(1); const onChange = (e: RadioChangeEvent) => { - console.log("radio checked", e.target.value); setValue(e.target.value); }; const [activeTab, setActiveTab] = useState("1"); diff --git a/src/Components/Companies/CompaniesTable.tsx b/src/Components/Companies/CompaniesTable.tsx index e067fe7..fde17df 100644 --- a/src/Components/Companies/CompaniesTable.tsx +++ b/src/Components/Companies/CompaniesTable.tsx @@ -117,32 +117,10 @@ function CompanyTable({ responsive: ["lg"], }, { - width: "20%", + width: "10%", title: "Actions", dataIndex: "action", - render: ({ id, api }: { id: string; api: string }) => { - const enterLoading = (index: number, api: string) => { - setLoadings((prevLoadings) => { - const newLoadings = [...prevLoadings]; - newLoadings[index] = true; - return newLoadings; - }); - if (api && api !== "") { - companyController.SyncCompany(index); - } else { - message.error({ - content: "This company doesn't have an api key", - duration: 2, - }); - } - setTimeout(() => { - setLoadings((prevLoadings) => { - const newLoadings = [...prevLoadings]; - newLoadings[index] = false; - return newLoadings; - }); - }, 6000); - }; + render: ({ id }: { id: string }) => { return ( @@ -151,15 +129,6 @@ function CompanyTable({ )} - - {role !== "Checker" && ( - + { + let num = e.target.value; + if (Number(num) && num !== "0") { + setPage(Number(num)); + } + }} + /> + + + ); }; diff --git a/src/Components/Customers/CustomersEdit.tsx b/src/Components/Customers/CustomersEdit.tsx index e00a9ee..790c0a5 100644 --- a/src/Components/Customers/CustomersEdit.tsx +++ b/src/Components/Customers/CustomersEdit.tsx @@ -1,5 +1,6 @@ -import { useParams } from "react-router-dom"; +import { useParams, useNavigate } from "react-router-dom"; import { useCustomerOne } from "../../Hooks/Customers"; + import { Form, Spin, @@ -13,7 +14,6 @@ import { } from "antd"; import { customerController } from "../../API/LayoutApi/customers"; import Notfound from "../../Utils/Notfound"; -import { useCompanyOne } from "../../Hooks/Companies"; import { role } from "../../App"; import { useState } from "react"; // @ts-ignore @@ -30,22 +30,19 @@ type params = { const CustomerEdit = () => { const { id } = useParams(); const { data, refetch, status } = useCustomerOne(id); + let navigate = useNavigate(); const onSubmit = async (value: any) => { await customerController.customerPatch(value, id); - refetch(); - window.location.replace("/#/customers/"); + navigate(-1); }; - const companyData = useCompanyOne(data?.id); - const ClickDelete = () => { const shouldDelete = window.confirm( "Are you sure, you want to delete this Driver?" ); if (shouldDelete && id !== undefined) { - customerController.deleteCustomerController(id).then((data: any) => { - document.location.replace(`/#/customers`); - }); + customerController.deleteCustomerController(id); + navigate(-1); } }; const [activeTab, setActiveTab] = useState("1"); @@ -94,19 +91,18 @@ const CustomerEdit = () => { autoComplete="off" > - {companyData?.data && ( - - - - - - )} + + + + + + { + 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 (
({ ...u, no: i + 1, - company_id: - CompanyData?.data?.find( - (company: any) => company.id === u?.company_id - )?.name || "", + company: u?.company, }))} columns={[ { @@ -55,12 +73,27 @@ function CustomerTable({ }, { title: "Company", - dataIndex: "company_id", + dataIndex: "company", + render: (text: any, record: any) => ( + +
+ {text?.source && ( + + )} + {text?.name} +
+
+ ), }, ]} rowClassName={(record, index) => index % 2 === 0 ? "odd-row" : "even-row" } + pagination={false} /> ); diff --git a/src/Components/Profile/ChangePassword.tsx b/src/Components/Profile/ChangePassword.tsx index 5836f50..6a54a4c 100644 --- a/src/Components/Profile/ChangePassword.tsx +++ b/src/Components/Profile/ChangePassword.tsx @@ -7,7 +7,6 @@ const ChangePassword = () => { const submit = () => { form.validateFields().then(async (values) => { form.resetFields(); - console.log(values); await prof.changePass(values); }); }; diff --git a/src/Components/Profile/Profile.tsx b/src/Components/Profile/Profile.tsx index 8928863..d9e9dfe 100644 --- a/src/Components/Profile/Profile.tsx +++ b/src/Components/Profile/Profile.tsx @@ -32,7 +32,7 @@ const Profile = () => { const [range, setRange] = useState(1); const onSubmit = async (value: TProfilePutParams) => { - await prof.profPatch(value); + await prof.profPatch(value) refetch(); }; diff --git a/src/Components/Requests/AssignedEdit.tsx b/src/Components/Requests/AssignedEdit.tsx new file mode 100644 index 0000000..83652f7 --- /dev/null +++ b/src/Components/Requests/AssignedEdit.tsx @@ -0,0 +1,132 @@ +import { Form, Tabs, Row, Col, Input, Modal, Button, Select } from "antd"; +import { useState } from "react"; +import { useCompanyData } 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 { useCustomerByComanyData } from "../../Hooks/Customers"; +const TabPane = Tabs.TabPane; + +const AssignedEdit = ({ recordData, editOpen, setEditOpen }: any) => { + const handleCancel = () => { + setEditOpen(!editOpen); + }; + const onSubmit = () => {}; + + const [companyName, setCompanyName] = useState(); + const [companyId, setCompanyId] = useState(); + const [customerName, setCustomerName] = useState(); + + const companyData = useCompanyData({ name: companyName }); + const customerData = useCustomerByComanyData({ + id: companyId, + name: customerName, + }); + + + 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 ( + +
+ +
+ + setCustomerName(value)} + options={customerData?.data?.map((item) => ({ + label: item?.name, + value: item?.id, + }))} + value={customerName} + filterOption={false} + autoClearSearchValue={false} + allowClear + /> + + + + + + + + + ); +}; + +export default AssignedEdit; diff --git a/src/Components/Requests/Requests.tsx b/src/Components/Requests/Requests.tsx index 890dd51..06ef72d 100644 --- a/src/Components/Requests/Requests.tsx +++ b/src/Components/Requests/Requests.tsx @@ -1,22 +1,28 @@ -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { useRequestsData } from "../../Hooks/Requests"; +import { StepForwardOutlined, StepBackwardOutlined } from "@ant-design/icons"; +import { Button, Input, Radio, RadioChangeEvent, Space } from "antd"; +import { TRequests } from "../../types/Requests/TRequests"; +import { TSocket } from "../../types/common/TSocket"; +import RequestsEdit from "./RequestsEdit"; import RequestsTable from "./RequestsTable"; // @ts-ignore import IconSearch from "../../assets/searchIcon.png"; -import { Radio, RadioChangeEvent } from "antd"; -import RequestsEdit from "./RequestsEdit"; -import { TRequests } from "../../types/Requests/TRequests"; -const Requests = () => { +const Requests = ({ socketData }: { socketData: TSocket | undefined }) => { const [search, setSearch] = useState(""); - const [status, setStatus] = useState("Pending"); const [modalOpen, setModalOpen] = useState(false); - const [requestData, setRequestData] = useState(); + const [requestData, setRequestData] = useState(); + const [status, setStatus] = useState("Pending"); + const [page, setPage] = useState(1); const { data, refetch, isLoading } = useRequestsData({ search: search, status: status, + page: page, + page_size: 10, }); + const [mainData, setMainData] = useState(); const timerRef = useRef(null); const handleSearchChange = (e: React.ChangeEvent) => { @@ -31,6 +37,37 @@ const Requests = () => { }; const theme = localStorage.getItem("theme") === "true" ? true : false; + + useEffect(() => { + if (data) { + setMainData(data.data); + } + }, [data]); + + // useEffect(() => { + // if (socketData) { + // setMainData((prev: TRequests[] | undefined) => { + // if (prev && prev?.length >= 15) { + // prev?.pop(); + // } + // if (socketData.type === "driver_request") { + // } + // return prev; + // }); + // } + // }, [socketData]); + + const Next = () => { + const a = Number(page) + 1; + setPage(a); + }; + const Previos = () => { + Number(page); + if (page > 1) { + const a = Number(page) - 1; + setPage(a); + } + }; return (
{modalOpen && ( @@ -63,16 +100,41 @@ const Requests = () => { Pending Assigned Rejected - All
+ + + + { + let num = e.target.value; + if (Number(num) && num !== "0") { + setPage(Number(num)); + } + }} + /> + + + ); }; diff --git a/src/Components/Requests/RequestsEdit.tsx b/src/Components/Requests/RequestsEdit.tsx index 6765244..fa0a3ff 100644 --- a/src/Components/Requests/RequestsEdit.tsx +++ b/src/Components/Requests/RequestsEdit.tsx @@ -1,7 +1,10 @@ import { Modal, Select, Button } from "antd"; import { TRequests } from "../../types/Requests/TRequests"; -import { useState } from "react"; -import { useCustomerData } from "../../Hooks/Customers"; +import { useEffect, useState } from "react"; +import { + useCustomerByComanyData, + useCustomerData, +} from "../../Hooks/Customers"; import { requestsController } from "../../API/LayoutApi/requests"; // @ts-ignore import plus from "../../assets/add-icon.png"; @@ -10,6 +13,8 @@ import { RefetchOptions, RefetchQueryFilters, } from "react-query"; +import { useCompanyData } from "../../Hooks/Companies"; +import { TPagination } from "../../types/common/TPagination"; const RequestsEdit = ({ modalOpen, setModalOpen, @@ -18,7 +23,7 @@ const RequestsEdit = ({ }: { refetch: ( options?: (RefetchOptions & RefetchQueryFilters) | undefined - ) => Promise>; + ) => Promise, unknown>>; modalOpen: any; setModalOpen: any; requestData: TRequests | undefined; @@ -28,15 +33,49 @@ const RequestsEdit = ({ setModalOpen(!modalOpen); }; + const [companyName, setCompanyName] = useState(); const [customerName, setCustomerName] = useState(); const [driverId, setDriverId] = useState(); + const companyData = useCompanyData({ name: companyName }); + const [companyId, setCompanyId] = useState(); + const [customerOption, setCustomerOption] = useState(); const customerData = useCustomerData({ name: customerName, + page: 1, + page_size: 5, + for_driver_request: true, + }); + const customerDataByCompany = useCustomerByComanyData({ + id: companyId, + name: customerName, + for_driver_request: true, }); - const optionClick = (value: number) => { - setDriverId(value); - }; + useEffect(() => { + if (companyId && customerDataByCompany) { + const newCustomerOption = customerDataByCompany.data?.map((item) => ({ + label: item.name, + value: item.id, + })); + + if ( + JSON.stringify(newCustomerOption) !== JSON.stringify(customerOption) + ) { + setCustomerOption(newCustomerOption); + } + } else if (!companyId && customerData) { + const newCustomerOption = customerData.data?.data.map((item) => ({ + label: `${item?.name} - ${item.company?.name}`, + value: item.id, + })); + + if ( + JSON.stringify(newCustomerOption) !== JSON.stringify(customerOption) + ) { + setCustomerOption(newCustomerOption); + } + } + }, [companyId, customerData, customerDataByCompany, customerOption]); const assignClick = () => { const value = { @@ -48,15 +87,15 @@ const RequestsEdit = ({ refetch(); setModalOpen(false); }); - // console.log(value); }; + return (
@@ -100,6 +139,18 @@ const RequestsEdit = ({ {requestData?.company_usdot}

+ {requestData?.telegram_user_link && ( +
+

Telegram User

+

+ {requestData?.telegram_user_link ? ( + Open Chat + ) : ( + "This user has no username" + )} +

+ + )} {requestData?.status === "Assigned" && ( @@ -138,15 +189,22 @@ const RequestsEdit = ({ )} {requestData?.status === "Pending" && ( -
-
+
+
setCustomerName(value)} + onChange={(value: number) => setDriverId(value)} + options={customerOption} + filterOption={false} + autoClearSearchValue={false} + allowClear + />
- + +
)}
diff --git a/src/Components/Requests/RequestsTable.tsx b/src/Components/Requests/RequestsTable.tsx index d1dd6cc..5b53f6e 100644 --- a/src/Components/Requests/RequestsTable.tsx +++ b/src/Components/Requests/RequestsTable.tsx @@ -10,6 +10,7 @@ import moment from "moment"; import { TRequests } from "../../types/Requests/TRequests"; import { useEffect, useState } from "react"; import { requestsController } from "../../API/LayoutApi/requests"; +import { TPagination } from "../../types/common/TPagination"; const RequestsTable = ({ data, @@ -24,7 +25,7 @@ const RequestsTable = ({ isLoading: boolean; refetch: ( options?: (RefetchOptions & RefetchQueryFilters) | undefined - ) => Promise>; + ) => Promise, unknown>>; }) => { const [isTextSelected, setIsTextSelected] = useState(false); @@ -55,11 +56,18 @@ const RequestsTable = ({ }; const patchRequest = (record: TRequests) => { - requestsController.delete(record?.id).then(() => { + requestsController + .rejectPatch({ status: "Rejected" }, record?.id) + .then(() => { + refetch(); + }); + }; + + const deleteRequest = (record: any) => { + requestsController.delete(record.id).then(() => { refetch(); }); }; - return (
{ return ( -
+
{record?.status === "Pending" && ( + + )}
); }, diff --git a/src/Components/Tasks/AddTask.tsx b/src/Components/Tasks/AddTask.tsx index b0e3487..60648fc 100644 --- a/src/Components/Tasks/AddTask.tsx +++ b/src/Components/Tasks/AddTask.tsx @@ -1,11 +1,12 @@ import { - Input, Modal, Form as FormAnt, Select, Upload, Switch, Button, + Radio, + RadioChangeEvent, Row, Col, } from "antd"; @@ -26,9 +27,12 @@ import zeelog from "../../assets/zeelogicon.svg"; 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"; const { Option } = Select; const AddTask = ({ @@ -46,7 +50,7 @@ const AddTask = ({ const [fileIds, setFileIds] = useState([]); const [companyName, setCompanyName] = useState(); const [customerName, setCustomerName] = useState(); - const [companyId, setCompanyId] = useState(); + const [companyId, setCompanyId] = useState(); const ServiceData = useServiceData(); const TeamData = useTeamData(""); @@ -58,20 +62,13 @@ const AddTask = ({ const [driverOpen, setDriverOpen] = useState(false); - const [previewImage, setPreviewImage] = useState(null); 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.onload = (e) => { - if (e.target && e.target.result) { - setPreviewImage(e.target.result as string); - } - }; reader.readAsDataURL(file); taskController .addTaskFile({ files: [file] }) @@ -108,6 +105,39 @@ const AddTask = ({ }; 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 (
handlePaste(event)}> {openDrive && ( @@ -127,8 +157,11 @@ const AddTask = ({ onCancel={handleCancel} onOk={() => { form.validateFields().then(async (values) => { - // const updatedValues = { ...values }; values.attachment_ids = fileIds; + values.note = + (text ? text + ", " : "") + + (note ? note + ", " : "") + + (note2 ? note2 + ", " : ""); form.resetFields(); await taskController.addTaskController(values); setOpen(!open); @@ -137,184 +170,241 @@ const AddTask = ({ > - - setCustomerName(value)} - options={customerData?.data?.map((item) => ({ - label: item?.name, - value: item?.id, - }))} - value={customerName} - filterOption={false} - autoClearSearchValue={false} - allowClear - /> - - -
+ +
+ + setCustomerName(value)} + options={customerData?.data?.map((item) => ({ + label: item?.name, + value: item?.id, + }))} + value={customerName} + filterOption={false} + autoClearSearchValue={false} + allowClear + /> + + + + - - + + - - ({ + label: item?.name, + value: item?.id, + }))} + /> + + - - - + + + + + - - - + + + + + - -