Skip to content

Commit

Permalink
contractor add functionality fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
fms-byte committed May 11, 2024
1 parent cee0166 commit a2b2404
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions react-app/components/ContractorForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Input from '../common/Input'
import Select from '../common/Select'
import axios from 'axios'
import { getBaseUrl } from '../../utils/url'
import toast from 'react-hot-toast'

const ContractorForm = ({ type, defaultValues, onFormSubmit, reload, setReload, ...props }) => {
const {
Expand All @@ -19,10 +20,9 @@ const ContractorForm = ({ type, defaultValues, onFormSubmit, reload, setReload,
useEffect(() => {
if (defaultValues) {
setValue('companyName', defaultValues.companyName)
// if (sts) {
// setValue('stsId', defaultValues?.sts?.map((item) => item.id.toString()))
// }
setValue('stsId', defaultValues.stsId)
if (sts) {
setValue('stsId', defaultValues?.sts?.map((item) => item.id.toString()) || [])
}
setValue('registrationId', defaultValues.registrationId)
// Format date strings to yyyy-MM-dd
setValue('registrationDate', formatDate(defaultValues.registrationDate))
Expand Down Expand Up @@ -54,7 +54,7 @@ const ContractorForm = ({ type, defaultValues, onFormSubmit, reload, setReload,

useEffect(() => {
const token = localStorage.getItem('token')
if (token && ! type) {
if (token) {
axios
.get(getBaseUrl() + '/sts', {
headers: {
Expand All @@ -64,8 +64,11 @@ const ContractorForm = ({ type, defaultValues, onFormSubmit, reload, setReload,
.then((res) => {
setSts(res.data)
})
.catch((err) => {
console.log(err)
})
}
}, [reload])
}, [defaultValues, sts, setValue])

const onSubmit = handleSubmit(async (data) => {
await onFormSubmit(data)
Expand Down

0 comments on commit a2b2404

Please sign in to comment.