- // {response.data.landfill.name} - //
- //- // Distance {response.data.bill.distance} KM .It will take{' '} - // {Number(response.data.bill.duration).toFixed(2)} min. - //
- //+ // {response.data.landfill.name} + //
+ //+ // Distance {response.data.bill.distance} KM .It will take{' '} + // {Number(response.data.bill.duration).toFixed(2)} min. + //
+ //+ Loading Contractors... +
+ ) : managedContractors.length > 0 ? ( + managedContractors.map((contractor, index) => ( ++ No ContractorManager found +
+ )} + > + )} + diff --git a/react-app/pages/contractor/[contractirId].js b/react-app/pages/contractor/[contractirId].js new file mode 100644 index 0000000..e7afee4 --- /dev/null +++ b/react-app/pages/contractor/[contractirId].js @@ -0,0 +1,183 @@ +/* eslint-disable multiline-ternary */ +/* eslint-disable react/react-in-jsx-scope */ +import { useEffect, useState } from 'react' +import axios from 'axios' +import { useRouter } from 'next/router' +import { getBaseUrl } from '../../utils/url' +import StsItemsSkeleton from '../../components/Stss/StsItemsSkeleton' +import StsEntryItems from '../../components/StsEntrys/StsEntryItems' +import Layout from '../../components/layout' +import MapView from '../../components/common/MapView' +import AddWasteEntry from '../../components/WasteEntry/AddWasteEntry' +import WasteItemsSkeleton from '../../components/WasteEntrys/WasteEntryItemsSkeleton' +import WasteEntryItems from '../../components/WasteEntrys/WasteEntryItems' +import { NoSSR } from '../../components/common/NoSSR' +import ProgressBar from '../../components/common/ProgressBar' +import AddStsEntry from '../../components/StsEntry/AddStsEntry' + +export default function VehicleEntry () { + const [loading, setLoading] = useState(true) + const [loadingInfo, setLoadingInfo] = useState(true) + const [vehicleEntries, setVehicleEntries] = useState([]) + const [wasteEntries, setWasteEntries] = useState([]) + + const [sts, setSts] = useState({}) + + const [contractorId, setStsId] = useState(null) + + const router = useRouter() + + useEffect(() => { + setStsId(router.query.contractorId) + }, [router.query.contractorId]) + + useEffect(() => { + if (contractorId === null) return + setLoadingInfo(true) + const token = localStorage.getItem('token') + if (token) { + axios + .get(getBaseUrl() + `/contractor/${contractorId}`, { + headers: { + Authorization: `Bearer ${token}` + } + }) + .then((res) => { + setLoadingInfo(false) + setSts(res.data) + console.log(res.data) + }) + .catch((err) => { + setLoadingInfo(false) + console.log(err) + }) + } + }, [contractorId]) + + useEffect(() => { + if (contractorId === null) return + setLoading(true) + const token = localStorage.getItem('token') + if (token.length > 0) { + axios + .get(getBaseUrl() + `/sts/${contractorId}/entry`, { + headers: { + Authorization: `Bearer ${token}` + } + }) + .then((res) => { + console.log(res.data) + res.data.sort((a, b) => b.id - a.id) + setVehicleEntries(res.data) + setLoading(false) + }) + .catch((err) => { + setLoading(false) + console.log(err) + }) + } + }, [contractorId]) + + useEffect(() => { + if (contractorId === null) return + setLoading(true) + const token = localStorage.getItem('token') + if (token.length > 0) { + axios + .get(getBaseUrl() + `/sts/${contractorId}/add`, { + headers: { + Authorization: `Bearer ${token}` + } + }) + .then((res) => { + console.log(res.data) + res.data.sort((a, b) => b.id - a.id) + setWasteEntries(res.data) + setLoading(false) + }) + .catch((err) => { + setLoading(false) + console.log(err) + }) + } + }, [contractorId]) + + return ( +Ward: {sts.wardNumber}
+Address: {sts.address}
+