From 1bd9f0d8458ec1e13d74aa9841d460b9d9c70ada Mon Sep 17 00:00:00 2001 From: fms-byte Date: Fri, 10 May 2024 21:54:10 +0600 Subject: [PATCH] contractors --- .../components/Contractor/ContractorLayout.js | 61 ++++++++++--- .../components/Contractor/DeleteContractor.js | 4 +- .../components/Contractor/UpdateContractor.js | 88 +++++++++++++++++++ .../components/Contractor/ViewContractor.js | 2 +- .../components/Contractors/ContractorItem.js | 17 ++-- .../components/Contractors/ContractorItems.js | 19 ++-- react-app/pages/contractor.js | 4 +- 7 files changed, 163 insertions(+), 32 deletions(-) diff --git a/react-app/components/Contractor/ContractorLayout.js b/react-app/components/Contractor/ContractorLayout.js index 041f0f2..9544be3 100644 --- a/react-app/components/Contractor/ContractorLayout.js +++ b/react-app/components/Contractor/ContractorLayout.js @@ -1,7 +1,7 @@ /* eslint-disable multiline-ternary */ import React from 'react' import UpdateContractor from './UpdateContractor' -import DeleteSong from './DeleteContractor' +import DeleteContractor from './DeleteContractor' const Section = ({ title, children, ...props }) => (
@@ -17,34 +17,67 @@ const ContractorLayout = ({ contractor }) => {
-
+
-
-
-
- {contractor.name} -
+
-

- {contractor.name} +

+ Company: {contractor.companyName}

-

{contractor.email}

+

Registration Id: {contractor.registrationId}

+ +
+

STS Assigned: {contractor.stsId}

+
+ +
+

Registration Date: {contractor.registrationDate}

+
+ +
+

TIN Number: {contractor.tin}

+
+ +
+

Phone Number: {contractor.phone}

+
+ +
+

Payment Per Tonnage: {contractor.paymentPerTonnage} Ton

+
+ +
+

Required Waste Per Day: {contractor.requiredWastePerDay} Ton

+
+ +
+

Contract Start Date: {contractor.contractStartDate}

+
+ +
+

Contract End Date: {contractor.contractEndDate}

+
+ +
+

Area of Collection: {contractor.areaOfCollection}

+
-
+ {/*

{contractor?.role?.type}

-
+
*/} - {contractor?.role?.type === 'STSManager' && ( + {/* {contractor?.role?.type === 'STSManager' && (
{ contractor.sts.map((sts) => ( @@ -65,7 +98,7 @@ const ContractorLayout = ({ contractor }) => { )) }
- )} + )} */}
) diff --git a/react-app/components/Contractor/DeleteContractor.js b/react-app/components/Contractor/DeleteContractor.js index 5ed2a61..9fce853 100644 --- a/react-app/components/Contractor/DeleteContractor.js +++ b/react-app/components/Contractor/DeleteContractor.js @@ -10,7 +10,7 @@ const DeleteContractor = ({ contractorId, ...props }) => { const handleDelete = async () => { try { const token = localStorage.getItem('token') - await fetch(getBaseUrl() + `/contractors/${contractorId}`, { + await fetch(getBaseUrl() + `/contractor/${contractorId}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', @@ -28,7 +28,7 @@ const DeleteContractor = ({ contractorId, ...props }) => { return ( <> - diff --git a/react-app/components/Contractor/UpdateContractor.js b/react-app/components/Contractor/UpdateContractor.js index e69de29..8a4be3a 100644 --- a/react-app/components/Contractor/UpdateContractor.js +++ b/react-app/components/Contractor/UpdateContractor.js @@ -0,0 +1,88 @@ +import { Dialog, Transition } from '@headlessui/react' +import React, { Fragment, useState } from 'react' + +import Button from '../common/Button' +import { Close } from '../common/icons/Close' +import ContractorForm from '../ContractorForm' +import { getBaseUrl } from '../../utils/url' +import axios from 'axios' +const UpdateContractor = ({ contractor, ...props }) => { + const [isOpen, setIsOpen] = useState(false) + const handleClose = () => setIsOpen(false) + const handleOpen = () => setIsOpen(true) + + const onFormSubmit = async (data) => { + const token = localStorage.getItem('token') + console.log(contractor) + await axios + .put(getBaseUrl() + `/contractors/${contractor.id}`, data, { + headers: { + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => { + console.log(res) + if (res.status === 200 || res.status === 201) { + alert('Successfully Added.') + } else { + alert(res.status) + console.log(res) + } + }) + } + + return ( + <> + + + + +
+ + +
+
+ + + +

Update Contractor

+ +
+ + +
+
+
+
+
+
+ + ) +} + +export default UpdateContractor diff --git a/react-app/components/Contractor/ViewContractor.js b/react-app/components/Contractor/ViewContractor.js index 48c27eb..071ff7f 100644 --- a/react-app/components/Contractor/ViewContractor.js +++ b/react-app/components/Contractor/ViewContractor.js @@ -19,7 +19,7 @@ const ContractorInfo = ({ contractor, ...props }) => { setLoading(true) const token = localStorage.getItem('token') axios - .get(getBaseUrl() + '/contractors/' + contractor.id, { + .get(getBaseUrl() + '/contractor/' + contractor.id, { headers: { Authorization: `Bearer ${token}`, }, diff --git a/react-app/components/Contractors/ContractorItem.js b/react-app/components/Contractors/ContractorItem.js index 3b22074..5e8df4b 100644 --- a/react-app/components/Contractors/ContractorItem.js +++ b/react-app/components/Contractors/ContractorItem.js @@ -1,22 +1,23 @@ import React from 'react' import ContractorInfo from '../Contractor/ViewContractor' -const ContractorItem = ({ name, email, image, role, id }) => { +const ContractorItem = (data) => { + return ( -
- - -

{name}

+
+

{data.companyName}

-

{email}

+

{data.registrationId}

-

{role.type}

+

{data.paymentPerTonnage}

- +
) } export default ContractorItem + + diff --git a/react-app/components/Contractors/ContractorItems.js b/react-app/components/Contractors/ContractorItems.js index 931a42d..bc39fe7 100644 --- a/react-app/components/Contractors/ContractorItems.js +++ b/react-app/components/Contractors/ContractorItems.js @@ -1,16 +1,25 @@ import React from 'react' import ContractorItem from './ContractorItem' -const ContractorItems = ({ Contractors, reload, setReload }) => { +const ContractorItems = ({ contractors, reload, setReload }) => { return (
- {Contractors?.length ? ( - contractors?.map((i) => ) - ) : ( +
+

Company Name

+ +

Registration Id

+ +

Payment Per Tonnage

+
+ {contractors?.length + ? ( + contractors?.map((i) => ) + ) + : (
Add some contractor to see the data.
- )} + )}
) } diff --git a/react-app/pages/contractor.js b/react-app/pages/contractor.js index 1d6389b..3de795a 100644 --- a/react-app/pages/contractor.js +++ b/react-app/pages/contractor.js @@ -17,7 +17,7 @@ function Contractors() { const token = localStorage.getItem('token') if (token.length > 0) { axios - .get(getBaseUrl() + '/contractors', { + .get(getBaseUrl() + '/contractor', { headers: { Authorization: `Bearer ${token}`, } @@ -50,7 +50,7 @@ function Contractors() { {loading ? ( ) : ( - + )}