-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
163 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<> | ||
<Button onClick={handleOpen} type="button" {...props}> | ||
Update | ||
</Button> | ||
<Transition appear show={isOpen} as={Fragment}> | ||
<Dialog as="div" className="relative z-10" onClose={handleClose}> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0" | ||
enterTo="opacity-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
<div className="z-100 fixed inset-0 bg-black bg-opacity-25" /> | ||
</Transition.Child> | ||
|
||
<div className="fixed inset-0 overflow-y-auto"> | ||
<div className="flex min-h-full items-center justify-center p-4 text-center"> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0 scale-95" | ||
enterTo="opacity-100 scale-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100 scale-100" | ||
leaveTo="opacity-0 scale-95" | ||
> | ||
<Dialog.Panel className="w-full max-w-2xl transform overflow-y-auto rounded-xl bg-white p-6 text-left align-middle shadow-xl transition-all"> | ||
<Dialog.Title | ||
as="div" | ||
className="mb-5 flex items-center justify-between text-lg font-semibold leading-6 text-gray-800" | ||
> | ||
<h3>Update Contractor</h3> | ||
<Close onClick={handleClose} /> | ||
</Dialog.Title> | ||
|
||
<ContractorForm | ||
defaultValues={contractor} | ||
type={'Update'} | ||
onFormSubmit={onFormSubmit} | ||
/> | ||
</Dialog.Panel> | ||
</Transition.Child> | ||
</div> | ||
</div> | ||
</Dialog> | ||
</Transition> | ||
</> | ||
) | ||
} | ||
|
||
export default UpdateContractor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import React from 'react' | ||
import ContractorInfo from '../Contractor/ViewContractor' | ||
|
||
const ContractorItem = ({ name, email, image, role, id }) => { | ||
const ContractorItem = (data) => { | ||
|
||
return ( | ||
|
||
<div className="smooth-effect my-2 flex cursor-pointer items-center rounded-md border px-3 py-4 shadow-sm hover:bg-green-100 hover:shadow lg:px-6"> | ||
<img className="mx-3 h-8 w-8 flex-shrink-0 rounded-md" src={image} /> | ||
|
||
<p className="flex-1 truncate font-bold">{name}</p> | ||
<div className="smooth-effect my-2 flex cursor-pointer items-center text-center rounded-md border px-3 py-4 shadow-sm hover:bg-green-100 hover:shadow lg:px-6"> | ||
<p className="flex-1 truncate font-bold">{data.companyName}</p> | ||
|
||
<p className="flex-1 truncate px-2 font-medium">{email}</p> | ||
<p className="flex-1 truncate px-2 font-medium">{data.registrationId}</p> | ||
|
||
<p className="flex-1 truncate px-2 font-medium">{role.type}</p> | ||
<p className="flex-1 truncate px-2 font-medium">{data.paymentPerTonnage}</p> | ||
|
||
<ContractorInfo contractor={{ name, email, image, role, id }} /> | ||
<ContractorInfo contractor={data}/> | ||
</div> | ||
|
||
) | ||
} | ||
|
||
export default ContractorItem | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters