diff --git a/react-app/components/ContractorEntry/AddContractorEntry.js b/react-app/components/ContractorEntry/AddContractorEntry.js index 00b2437..5db8931 100644 --- a/react-app/components/ContractorEntry/AddContractorEntry.js +++ b/react-app/components/ContractorEntry/AddContractorEntry.js @@ -16,19 +16,23 @@ const AddContractorEntry = ({ props, contractorId }) => { const onFormSubmit = async (data) => { try { console.log(data) + const submitData = { + ...data, + contractorId, + } toast('Adding the entry!', { icon: '👏', }) const token = localStorage.getItem('token') await axios - .post(getBaseUrl() + `/contractor/${contractorId}/entry`, data, { + .post(getBaseUrl() + `/employee`, submitData, { headers: { Authorization: `Bearer ${token}`, }, }) .then((response) => { console.log(response) - toast.success('Worker Entry added successfully') + toast.success('Employee Entry added successfully') // toast.custom((t) => ( //
{ as="div" className="mb-5 flex items-center justify-between text-lg font-semibold leading-6 text-gray-800" > -

Add Worker Entry

+

Add Employee Entry

diff --git a/react-app/components/ContractorEntry/ViewContractorEntry.js b/react-app/components/ContractorEntry/ViewContractorEntry.js index 6929683..30e0467 100644 --- a/react-app/components/ContractorEntry/ViewContractorEntry.js +++ b/react-app/components/ContractorEntry/ViewContractorEntry.js @@ -12,7 +12,7 @@ const Section = ({ title, children, ...props }) => ( ) -const STSEntryInfo = ({ vehicleEntry, ...props }) => { +const ContractorEntryInfo = ({ employeeEntry, ...props }) => { const [isOpen, setIsOpen] = useState(false) const handleClose = () => setIsOpen(false) const handleOpen = () => setIsOpen(true) @@ -55,73 +55,47 @@ const STSEntryInfo = ({ vehicleEntry, ...props }) => { as="div" className="mb-5 flex items-center justify-between text-lg font-semibold leading-6 text-gray-800" > -

Vehicle Entry Information

+

Employee Entry Information

-
-
-

- Ward No: {vehicleEntry?.sts?.wardNumber} -

-

- {' '} - {vehicleEntry?.sts?.address} -

-
-
- -
-
-

- Reg No: {vehicleEntry?.vehicle?.registrationNumber} -

-

- {' '} - Capacity No: {vehicleEntry?.vehicle?.capacity} -

-

- {' '} - Truck Type: {vehicleEntry?.vehicle?.type} -

-
-
- -
-

- Waste Volume Carried : {vehicleEntry?.volumeOfWaste}{' '} - Ton +
+

+ Name: {employeeEntry.name}

-
+

+ Date of Birth:{' '} + {new Date(employeeEntry?.dateOfBirth) + .toISOString() + .slice(0, 10)} +

+

+ Date of Hire:{' '} + {new Date(employeeEntry?.dateOfHire) + .toISOString() + .slice(0, 10)} +

+

+ {' '} + Job Title: {employeeEntry?.jobTitle} +

+

+ {' '} + Payment/hour: {employeeEntry?.paymentRatePerHour} BDT +

-
-

- Arrival Time :{' '} - {new Date( - vehicleEntry?.timeOfArrival - ).toLocaleString()} -

-

- Departure Time :{' '} - {new Date( - vehicleEntry?.timeOfDeparture - ).toLocaleString()} -

-
+

+ {' '} + Phone Number: {employeeEntry?.phone} +

-
-

- Destination : {vehicleEntry.landfill?.name} -

-

- Distance : {vehicleEntry.bill?.distance} KM -

-

- Duration : {vehicleEntry.bill?.duration} Min -

-
+

+ {' '} + Routes: {employeeEntry?.assignedCollectionRoute} +

+

@@ -134,4 +108,4 @@ const STSEntryInfo = ({ vehicleEntry, ...props }) => { ) } -export default STSEntryInfo +export default ContractorEntryInfo diff --git a/react-app/components/ContractorEntryForm/index.js b/react-app/components/ContractorEntryForm/index.js index e69de29..90203c9 100644 --- a/react-app/components/ContractorEntryForm/index.js +++ b/react-app/components/ContractorEntryForm/index.js @@ -0,0 +1,187 @@ +/* eslint-disable no-unused-expressions */ +import React, { useEffect, useState } from 'react' +import { useForm } from 'react-hook-form' +import Button from '../common/Button' +import Input from '../common/Input' +import Select from '../common/Select' +import axios from 'axios' +import { getBaseUrl } from '../../utils/url' +const ContractorEntryForm = ({ + type, + defaultValues, + onFormSubmit, + handleClose, + contractorId, + ...props +}) => { + const { + register, + handleSubmit, + formState: { errors }, + reset, + setValue, + } = useForm() + + const [loading, setLoading] = useState(false) + + useEffect(() => { + if (defaultValues) { + setValue('contractorId', contractorId) + setValue('name', defaultValues.name) + setValue('dateOfHire', defaultValues.dateOfHire) + setValue('jobTitle', defaultValues.jobTitle) + setValue('paymentRatePerHour', defaultValues.paymentRatePerHour) + setValue('phone', defaultValues.phone) + setValue('assignedCollectionRoute', defaultValues.assignedCollectionRoute) + setValue('volumeOfWaste', defaultValues.volumeOfWaste) + const formattedTimeOfArrival = defaultValues?.dateOfBirth + ? new Date(defaultValues?.dateOfBirth).toISOString().slice(0, 16) + : '' // Converts to "YYYY-MM-DDTHH:MM" format + setValue('dateOfBirth', formattedTimeOfArrival) + } + }, []) + + const onSubmit = handleSubmit(async (data) => { + console.log(data) + setLoading(true) + // convert timeOfArrival to ISO string + data.dateOfBirth = new Date(data.dateOfBirth).toISOString() + await onFormSubmit(data) + setLoading(false) + reset() + }) + + return ( +
+
+ + + + + + + + + + + + + + + +
+ + +
+ ) +} + +export default ContractorEntryForm diff --git a/react-app/components/ContractorEntrys/ContractorEntryItem.js b/react-app/components/ContractorEntrys/ContractorEntryItem.js index ac40881..6427db7 100644 --- a/react-app/components/ContractorEntrys/ContractorEntryItem.js +++ b/react-app/components/ContractorEntrys/ContractorEntryItem.js @@ -1,58 +1,53 @@ /* eslint-disable react/prop-types */ import React from 'react' import UpdateContractorEntry from '../ContractorEntry/UpdateContractorEntry' -import ContractorInfoEntry from '../ContractorEntry/ViewContractorEntry' +import ContractorEntryInfo from '../ContractorEntry/ViewContractorEntry' + +const ContractorEntryItem = ({id, name, dateOfBirth, dateOfHire, jobTitle, paymentRatePerHour, phone, assignedCollectionRoute}) => { -const ContractorEntryItem = ({ - id, - vehicleId, - volumeOfWaste, - timeOfArrival, - timeOfDeparture, - vehicle, - stsId, - sts, - landfill, - bill, -}) => { return ( -
+

- {vehicle.registrationNumber} + {name}

-
-

{volumeOfWaste} Ton

+ {/*
+

{new Date(dateOfBirth).toISOString().slice(0, 10)}

-
-

Landfill: {landfill?.name}

-
+
+

{new Date(dateOfHire).toISOString().slice(0, 10)}

+
*/}

- Arrival: {new Date(timeOfArrival).toLocaleString()} + {phone}

- Departure: {new Date(timeOfDeparture).toLocaleString()} + {jobTitle}

- +

+ {paymentRatePerHour} +

+
+ + diff --git a/react-app/components/ContractorEntrys/ContractorEntryItems.js b/react-app/components/ContractorEntrys/ContractorEntryItems.js index 2aa7359..354a9e1 100644 --- a/react-app/components/ContractorEntrys/ContractorEntryItems.js +++ b/react-app/components/ContractorEntrys/ContractorEntryItems.js @@ -4,15 +4,13 @@ import ContractorEntryItem from './ContractorEntryItem' const ContractorEntryItems = ({ contractorEntries }) => { return (
- {contractorEntries?.length - ? ( - contractorEntries?.map((i) => ) - ) - : ( + {contractorEntries?.length ? ( + contractorEntries?.map((i) => ) + ) : (
Add some employee entries of contractor
- )} + )}
) } diff --git a/react-app/pages/contractor/[contractorId].js b/react-app/pages/contractor/[contractorId].js index 54953e0..624b835 100644 --- a/react-app/pages/contractor/[contractorId].js +++ b/react-app/pages/contractor/[contractorId].js @@ -58,53 +58,53 @@ export default function VehicleEntry () { } }, [contractorId]) - // useEffect(() => { - // if (contractorId === null) return - // setLoading(true) - // const token = localStorage.getItem('token') - // if (token.length > 0) { - // axios - // .get(getBaseUrl() + `/contractor/${contractorId}/entry`, { - // headers: { - // Authorization: `Bearer ${token}` - // } - // }) - // .then((res) => { - // console.log(res.data) - // res.data.sort((a, b) => b.id - a.id) - // setContractorEntries(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() + `/contractor/${contractorId}/employees`, { + headers: { + Authorization: `Bearer ${token}` + } + }) + .then((res) => { + console.log(res.data) + res.data.sort((a, b) => b.id - a.id) + setContractorEntries(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() + `/contractor/${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]) + useEffect(() => { + if (contractorId === null) return + setLoading(true) + const token = localStorage.getItem('token') + if (token.length > 0) { + axios + .get(getBaseUrl() + `/contractor/${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 ( @@ -145,10 +145,10 @@ export default function VehicleEntry () {
-
+

- Contractor Entries{' '} + Employee Entries{' '}

{contractorId && } @@ -161,7 +161,7 @@ export default function VehicleEntry () { )}
-
+ {/*

Waste Entries @@ -175,7 +175,7 @@ export default function VehicleEntry () { ) : ( )} -

+
*/}
diff --git a/react-app/utils/url.js b/react-app/utils/url.js index 526fc15..abc002d 100644 --- a/react-app/utils/url.js +++ b/react-app/utils/url.js @@ -3,6 +3,7 @@ const url = process.env.API; export const getBaseUrl = () => { // console.log(process.env.API); - return process.env.API || 'http://3.208.28.247:5000'; + //return process.env.API || 'http://3.208.28.247:5000'; + return 'http://localhost:5000'; } \ No newline at end of file