Skip to content

Commit

Permalink
Contractor Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
fms-byte committed May 10, 2024
1 parent 5aa02c5 commit 8ac8111
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 153 deletions.
10 changes: 7 additions & 3 deletions react-app/components/ContractorEntry/AddContractorEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
// <div
// className={`${
Expand Down Expand Up @@ -125,7 +129,7 @@ const AddContractorEntry = ({ props, contractorId }) => {
as="div"
className="mb-5 flex items-center justify-between text-lg font-semibold leading-6 text-gray-800"
>
<h3>Add Worker Entry</h3>
<h3>Add Employee Entry</h3>
<Close onClick={handleClose} />
</Dialog.Title>

Expand Down
96 changes: 35 additions & 61 deletions react-app/components/ContractorEntry/ViewContractorEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Section = ({ title, children, ...props }) => (
</section>
)

const STSEntryInfo = ({ vehicleEntry, ...props }) => {
const ContractorEntryInfo = ({ employeeEntry, ...props }) => {
const [isOpen, setIsOpen] = useState(false)
const handleClose = () => setIsOpen(false)
const handleOpen = () => setIsOpen(true)
Expand Down Expand Up @@ -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"
>
<h3>Vehicle Entry Information</h3>
<h3>Employee Entry Information</h3>
<Close onClick={handleClose} />
</Dialog.Title>

<div className="mt-6 flex flex-col md:flex-row">
<div className="w-full">
<Section title={'STS Information'}>
<section className="mb-3 rounded-md border px-3 py-4">
<h3 className="text-xl font-semibold text-gray-500">
Ward No: {vehicleEntry?.sts?.wardNumber}
</h3>
<p className="text-gray-600">
{' '}
{vehicleEntry?.sts?.address}
</p>
</section>
</Section>

<Section title={'Vehicle Information'}>
<section className="mb-3 rounded-md border px-3 py-4">
<h3 className="text-xl font-semibold text-gray-500">
Reg No: {vehicleEntry?.vehicle?.registrationNumber}
</h3>
<p className="text-gray-600">
{' '}
Capacity No: {vehicleEntry?.vehicle?.capacity}
</p>
<p className="text-gray-600">
{' '}
Truck Type: {vehicleEntry?.vehicle?.type}
</p>
</section>
</Section>

<Section title={'Waste Information'}>
<h3 className="font-bond text-xl text-gray-500">
Waste Volume Carried : {vehicleEntry?.volumeOfWaste}{' '}
Ton
<section className="mb-3 rounded-md border px-3 py-4">
<h3 className="text-xl font-semibold text-gray-500">
Name: {employeeEntry.name}
</h3>
</Section>
<p className="text-gray-600">
Date of Birth:{' '}
{new Date(employeeEntry?.dateOfBirth)
.toISOString()
.slice(0, 10)}
</p>
<p className="text-gray-600">
Date of Hire:{' '}
{new Date(employeeEntry?.dateOfHire)
.toISOString()
.slice(0, 10)}
</p>
<p className="text-gray-600">
{' '}
Job Title: {employeeEntry?.jobTitle}
</p>
<p className="text-gray-600">
{' '}
Payment/hour: {employeeEntry?.paymentRatePerHour} BDT
</p>

<Section title={'Time'}>
<h3 className="font-bond text-xl text-gray-500">
Arrival Time :{' '}
{new Date(
vehicleEntry?.timeOfArrival
).toLocaleString()}
</h3>
<h3 className="font-bond text-xl text-gray-500">
Departure Time :{' '}
{new Date(
vehicleEntry?.timeOfDeparture
).toLocaleString()}
</h3>
</Section>
<p className="text-gray-600">
{' '}
Phone Number: {employeeEntry?.phone}
</p>

<Section title={'Trip info'}>
<h3 className="font-bond text-xl text-gray-500">
Destination : {vehicleEntry.landfill?.name}
</h3>
<h3 className="font-bond text-xl text-gray-500">
Distance : {vehicleEntry.bill?.distance} KM
</h3>
<h3 className="font-bond text-xl text-gray-500">
Duration : {vehicleEntry.bill?.duration} Min
</h3>
</Section>
<p className="text-gray-600">
{' '}
Routes: {employeeEntry?.assignedCollectionRoute}
</p>
</section>
</div>
</div>
</Dialog.Panel>
Expand All @@ -134,4 +108,4 @@ const STSEntryInfo = ({ vehicleEntry, ...props }) => {
)
}

export default STSEntryInfo
export default ContractorEntryInfo
187 changes: 187 additions & 0 deletions react-app/components/ContractorEntryForm/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<div {...props} className="flex flex-col space-y-6">
<div>
<Input
name="contractorId"
label="Contractor ID"
placeholder={contractorId}
value={contractorId}
type="text"
error={errors.contractorId ? errors.contractorId.message : false}
disabled
/>

<Input
name="name"
label="Full Name"
placeholder="Full Name of the Employee..."
type="text"
error={errors.name ? errors.name.message : false}
register={register('name', {
required: {
value: true,
message: 'Full name is required...',
},
})}
/>

<Input
name="dateOfBirth"
label="Date of Birth"
placeholder="Date of Birth..."
type="datetime-local"
error={errors.dateOfBirth ? errors.dateOfBirth.message : false}
register={register('dateOfBirth', {
required: {
value: true,
message: 'Date of Birth is required',
},
})}
/>

<Input
name="dateOfHire"
label="Date of Hire"
placeholder="Date of Hire..."
type="datetime-local"
error={errors.dateOfHire ? errors.dateOfHire.message : false}
register={register('dateOfHire', {
required: {
value: true,
message: 'Date of Hire is required',
},
})}
/>

<Input
name="jobTitle"
label="Job Title"
placeholder="Job Title..."
type="text"
error={errors.jobTitle ? errors.jobTitle.message : false}
register={register('jobTitle', {
required: {
value: true,
message: 'Job Title is required',
},
})}
/>

<Input
name="paymentRatePerHour"
label="Payment Rate Per Hour"
placeholder="Payment Rate Per Hour..."
type="text"
error={
errors.paymentRatePerHour
? errors.paymentRatePerHour.message
: false
}
register={register('paymentRatePerHour', {
required: {
value: true,
message: 'Payment Rate Per Hour is required',
},
})}
/>

<Input
name="phone"
label="Phone"
placeholder="Phone..."
type="text"
error={errors.phone ? errors.phone.message : false}
register={register('phone', {
required: {
value: true,
message: 'Phone is required',
},
})}
/>

<Input
name="assignedCollectionRoute"
label="Assigned Collection Route"
placeholder="Assigned Collection Route..."
type="text"
error={
errors.assignedCollectionRoute
? errors.assignedCollectionRoute.message
: false
}
register={register('assignedCollectionRoute', {
required: {
value: true,
message: 'Assigned Collection Route is required',
},
})}
/>
</div>

<Button
type="button"
onClick={onSubmit}
className="w-full"
disable={loading}
>
{/* loading and type condition */}
{loading ? 'Adding' : 'Add Entry'}
</Button>
</div>
)
}

export default ContractorEntryForm
Loading

0 comments on commit 8ac8111

Please sign in to comment.