-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from ertush/hotfix
Hotfix
- Loading branch information
Showing
12 changed files
with
829 additions
and
376 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
|
||
import { useRef, useContext, useEffect } from "react" // useContext | ||
import { useRef, useContext, useEffect, useState } from "react" // useContext | ||
import { XCircleIcon } from '@heroicons/react/outline' | ||
import { FacilityContactsContext } from "../../../components/Forms/FacilityContactsForm" | ||
// import { EditFacilityContactsContext } from "../../../pages/facilities/edit/[id]" | ||
import { useAlert } from "react-alert" | ||
import Select from './FormikSelect' | ||
import { Field } from 'formik' | ||
// import {Select as CustomSelect} from '../formComponents/Select' | ||
import { Field, useFormikContext } from 'formik' | ||
|
||
|
||
const FacilityContact = ({contactTypeOptions, setFacilityContacts, index, fieldNames, contacts}) => { | ||
function FacilityContact({contactTypeOptions, setFacilityContacts, index, fieldNames, contacts}) { | ||
|
||
|
||
|
||
|
@@ -22,8 +23,17 @@ const FacilityContact = ({contactTypeOptions, setFacilityContacts, index, fieldN | |
const contactDetailsRef = useRef(null) | ||
|
||
const [contact, contact_type_name, id] = contacts | ||
const [_contactType, setContactType] = useState(null) | ||
|
||
const {values, _} = useFormikContext() | ||
|
||
useEffect(() => { | ||
if(values) { | ||
setContactType(contactTypeOptions?.find(type => type?.value == values[`contact_type_${index}`])?.label) | ||
} | ||
}, [values[`contact_type_${index}`]]) | ||
|
||
|
||
|
||
|
||
useEffect(() => { | ||
|
||
|
@@ -33,8 +43,7 @@ const FacilityContact = ({contactTypeOptions, setFacilityContacts, index, fieldN | |
|
||
contactTypeRef.current.state.value = contactTypeOptions.filter(({label}) => label === contact_type_name).map(obj => {obj['id'] = id; return obj}) | ||
} | ||
|
||
// console.log({val: contactTypeRef.current?.state?.value}) | ||
|
||
} | ||
|
||
if(contactDetailsRef.current ){ | ||
|
@@ -46,10 +55,9 @@ const FacilityContact = ({contactTypeOptions, setFacilityContacts, index, fieldN | |
}, []) | ||
|
||
return ( | ||
<div className="w-full grid grid-cols-2 grid-rows-1 gap-3 mt-3" id={`facility-dept-wrapper-${index}`}> | ||
<div className="w-full grid grid-cols-2 grid-rows-auto gap-3 mt-3" id={`facility-dept-wrapper-${index}`}> | ||
|
||
{/* Name */} | ||
|
||
<Select options={contactTypeOptions || []} | ||
required | ||
id={`facility-contact-type-${index}`} | ||
|
@@ -59,17 +67,95 @@ const FacilityContact = ({contactTypeOptions, setFacilityContacts, index, fieldN | |
/> | ||
|
||
<div className="w-full col-start-2 flex items-center gap-x-3 justify-between"> | ||
{/*facility contact */} | ||
<Field | ||
id={`facility-contact-detail-${index}`} | ||
type="text" | ||
name={`${fieldNames[1]}_${index}`} | ||
className="w-full flex-grow rounded flex-1 bg-transparent p-2 border placeholder-gray-500 border-gray-600 focus:shadow-none focus:border-black outline-none" | ||
/> | ||
{/* Facility Contact */} | ||
|
||
|
||
{ | ||
(_contactType == null || _contactType == "FAX" ) && | ||
|
||
|
||
|
||
<Field | ||
as="input" | ||
required | ||
id={`facility-contact-detail-${index}`} | ||
type="text" | ||
name={`${fieldNames[1]}_${index}`} | ||
className="w-full flex-grow rounded flex-1 bg-transparent p-2 border placeholder-gray-500 border-gray-600 focus:shadow-none focus:border-black outline-none" | ||
/> | ||
|
||
|
||
|
||
} | ||
|
||
{ | ||
( _contactType == 'LANDLINE' || _contactType == 'MOBILE') && | ||
|
||
<div className=" flex flex-col w-full gap-1 relative max-h-min"> | ||
<Field | ||
as="input" | ||
required | ||
id={`facility-contact-detail-${index}`} | ||
type="tel" | ||
placeholder={'+254 #########'} | ||
pattern={'[+]{1}[254]{3}[ ]{1}[0-9]{9}'} | ||
name={`${fieldNames[1]}_${index}`} | ||
className="w-full flex-grow rounded flex-1 bg-transparent p-2 border placeholder-gray-500 border-gray-600 focus:shadow-none focus:border-black outline-none" | ||
/> | ||
|
||
<span class="tooltiptext">Invalid Input! Correct Format is +254 #########</span> | ||
|
||
|
||
</div> | ||
|
||
} | ||
|
||
{ | ||
_contactType == 'EMAIL' && | ||
<div className=" flex flex-col w-full gap-1 relative max-h-min"> | ||
|
||
<Field | ||
as="input" | ||
reuired | ||
id={`facility-contact-detail-${index}`} | ||
type="email" | ||
placeholder="user@email-domain" | ||
pattern="[a-z0-9]+[.]*[\-]*[a-z0-9]+@[a-z0-9]+[\-]*[.]*[a-z0-9]+[.][a-z]{2,}" | ||
name={`${fieldNames[1]}_${index}`} | ||
className="w-full flex-grow rounded flex-1 bg-transparent p-2 border placeholder-gray-500 border-gray-600 focus:shadow-none focus:border-black outline-none" | ||
/> | ||
<span class="tooltiptext">Invalid Input! Correct Format is [email protected] </span> | ||
|
||
</div> | ||
|
||
} | ||
|
||
{ | ||
_contactType == 'POSTAL' && | ||
<div className=" flex flex-col w-full gap-1 relative max-h-min"> | ||
|
||
<Field | ||
as="input" | ||
required | ||
id={`facility-contact-detail-${index}`} | ||
type="text" | ||
placeholder="P.O BOX #####" | ||
pattern={'[P.O BOX]{7}[ ]{1}[0-9]{5,6}'} | ||
name={`${fieldNames[1]}_${index}`} | ||
className="w-full flex-grow rounded flex-1 bg-transparent p-2 border placeholder-gray-500 border-gray-600 focus:shadow-none focus:border-black outline-none" | ||
/> | ||
|
||
<span class="tooltiptext">Invalid Input! Correct Format is P.O BOX ##### </span> | ||
|
||
|
||
</div> | ||
} | ||
|
||
|
||
|
||
|
||
{/* Delete Btn */} | ||
|
||
|
||
{/* Delete Btn */} | ||
<button | ||
id={`delete-btn-${index}`} | ||
onClick={async ev => { | ||
|
@@ -103,18 +189,37 @@ const FacilityContact = ({contactTypeOptions, setFacilityContacts, index, fieldN | |
}} | ||
><XCircleIcon className='w-7 h-7 text-red-400'/></button> | ||
|
||
</div> | ||
</div> | ||
|
||
|
||
|
||
|
||
</div> | ||
) | ||
} | ||
|
||
const OfficerContactDetails = ({contactTypeOptions, setFacilityContacts, contacts, index, fieldNames}) => { | ||
function OfficerContactDetails ({contactTypeOptions, setFacilityContacts, contacts, index, fieldNames}) { | ||
|
||
|
||
const contactTypes = useContext(FacilityContactsContext) | ||
const [_contactType, setContactType] = useState(null) | ||
|
||
const {values, _} = useFormikContext() | ||
|
||
|
||
useEffect(() => { | ||
if(values) { | ||
setContactType(contactTypeOptions?.find(type => type?.value == values[`officer_details_contact_type_${index}`])?.label) | ||
console.log({values}) | ||
} | ||
}, [values[`officer_details_contact_type_${index}`]]) | ||
|
||
|
||
|
||
return ( | ||
|
||
/** */ | ||
|
||
<div className="w-full grid grid-cols-2 grid-rows-1 gap-3 mt-3" id={`facility-dept-wrapper-${index}`}> | ||
|
||
|
||
|
@@ -123,17 +228,96 @@ const OfficerContactDetails = ({contactTypeOptions, setFacilityContacts, contact | |
required | ||
id={`officer-contact-type-${index}`} | ||
placeholder="Select Contact Type" | ||
|
||
name={`${fieldNames[0]}_${index}`} | ||
/> | ||
|
||
|
||
|
||
<div className="w-full col-start-2 flex items-center gap-x-3 justify-between"> | ||
{/* Officer contacts */} | ||
<Field | ||
id={`officer-contact-detail-${index}`} | ||
type="text" | ||
|
||
name={`${fieldNames[1]}_${index}`} | ||
className="w-full flex-grow rounded flex-1 bg-transparent p-2 border placeholder-gray-500 border-gray-600 focus:shadow-none focus:border-black outline-none" /> | ||
<div className="w-full col-start-2 flex items-center gap-x-3 justify-between"> | ||
{/* Facility Contact */} | ||
|
||
|
||
{ | ||
(_contactType == null || _contactType == "FAX") && | ||
|
||
|
||
|
||
<Field | ||
as="input" | ||
required | ||
id={`officer-contact-detail-${index}`} | ||
type="text" | ||
name={`${fieldNames[1]}_${index}`} | ||
className="w-full flex-grow rounded flex-1 bg-transparent p-2 border placeholder-gray-500 border-gray-600 focus:shadow-none focus:border-black outline-none" | ||
/> | ||
|
||
|
||
|
||
} | ||
|
||
{ | ||
( _contactType == 'LANDLINE' || _contactType == 'MOBILE') && | ||
|
||
<div className=" flex flex-col w-full gap-1 relative max-h-min"> | ||
<Field | ||
as="input" | ||
required | ||
id={`officer-contact-detail-${index}`} | ||
type="tel" | ||
placeholder={'+254 #########'} | ||
pattern={'[+]{1}[254]{3}[ ]{1}[0-9]{9}'} | ||
name={`${fieldNames[1]}_${index}`} | ||
className="w-full flex-grow rounded flex-1 bg-transparent p-2 border placeholder-gray-500 border-gray-600 focus:shadow-none focus:border-black outline-none" | ||
/> | ||
|
||
<span class="tooltiptext">Invalid Input! Correct Format is +254 #########</span> | ||
|
||
|
||
</div> | ||
|
||
} | ||
|
||
{ | ||
_contactType == 'EMAIL' && | ||
<div className=" flex flex-col w-full gap-1 relative max-h-min"> | ||
|
||
<Field | ||
as="input" | ||
reuired | ||
id={`officer-contact-detail-${index}`} | ||
type="email" | ||
placeholder="user@email-domain" | ||
pattern="[a-z0-9]+[.]*[\-]*[a-z0-9]+@[a-z0-9]+[\-]*[.]*[a-z0-9]+[.][a-z]{2,}" | ||
name={`${fieldNames[1]}_${index}`} | ||
className="w-full flex-grow rounded flex-1 bg-transparent p-2 border placeholder-gray-500 border-gray-600 focus:shadow-none focus:border-black outline-none" | ||
/> | ||
<span class="tooltiptext">Invalid Input! Correct Format is [email protected] </span> | ||
|
||
</div> | ||
|
||
} | ||
|
||
{ | ||
_contactType == 'POSTAL' && | ||
<div className=" flex flex-col w-full gap-1 relative max-h-min"> | ||
|
||
<Field | ||
as="input" | ||
required | ||
id={`officer-contact-detail-${index}`} | ||
type="text" | ||
placeholder="P.O BOX #####" | ||
pattern={'[P.O BOX]{7}[ ]{1}[0-9]{5,6}'} | ||
name={`${fieldNames[1]}_${index}`} | ||
className="w-full flex-grow rounded flex-1 bg-transparent p-2 border placeholder-gray-500 border-gray-600 focus:shadow-none focus:border-black outline-none" | ||
/> | ||
|
||
<span class="tooltiptext">Invalid Input! Correct Format is P.O BOX ##### </span> | ||
|
||
|
||
</div> | ||
} | ||
|
||
|
||
{/* Delete Btn */} | ||
|
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
Oops, something went wrong.