-
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 branch 'develop' into feat/CONNECTA-297-playwright-setup
- Loading branch information
Showing
20 changed files
with
521 additions
and
517 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { endpoints } from '../resources/scripts/endpoints'; | ||
import { FETCH_ERRORS, FETCH_METHODS, fetchData } from './fetchData'; | ||
|
||
export const apiGetAgenciesByTenant = async ( | ||
postcode: string, | ||
topicId: number | ||
): Promise<any[]> => { | ||
const url = `${endpoints.agenciesByTenant}?postcode=${postcode}&topicId=${topicId}`; | ||
|
||
return fetchData({ | ||
url, | ||
method: FETCH_METHODS.GET, | ||
responseHandling: [FETCH_ERRORS.EMPTY] | ||
}); | ||
}; |
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,17 @@ | ||
import { fetchData, FETCH_METHODS, FETCH_ERRORS } from './fetchData'; | ||
import { endpoints } from '../resources/scripts/endpoints'; | ||
|
||
export interface TenantAgenciesTopicsInterface { | ||
id: number; | ||
name: string; | ||
} | ||
|
||
export const apiGetTenantAgenciesTopics = async (): Promise< | ||
TenantAgenciesTopicsInterface[] | ||
> => { | ||
return fetchData({ | ||
url: `${endpoints.agencyTopics}`, | ||
method: FETCH_METHODS.GET, | ||
responseHandling: [FETCH_ERRORS.CATCH_ALL] | ||
}); | ||
}; |
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
172 changes: 172 additions & 0 deletions
172
src/components/profile/AdditionalEnquiry/AdditionalAgencySelection.tsx
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,172 @@ | ||
import * as React from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
import { AgencyDataInterface } from '../../../globalState/interfaces'; | ||
import { apiGetAgenciesByTenant, FETCH_ERRORS } from '../../../api'; | ||
import { InputField, InputFieldItem } from '../../inputField/InputField'; | ||
import '../../agencySelection/agencySelection.styles'; | ||
import '../profile.styles'; | ||
import { Text } from '../../text/Text'; | ||
import { Headline } from '../../headline/Headline'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { AgencyRadioSelect } from '../../agencyRadioSelect/AgencyRadioSelect'; | ||
import { VALID_POSTCODE_LENGTH } from '../../agencySelection/agencySelectionHelpers'; | ||
|
||
export interface AdditionalAgencySelectionProps { | ||
onAgencyChange: Function; | ||
onPostcodeChange: Function; | ||
selectedTopicId: number; | ||
} | ||
|
||
export const AdditionalAgencySelection = ( | ||
props: AdditionalAgencySelectionProps | ||
) => { | ||
const { t: translate } = useTranslation(['common', 'agencies']); | ||
const [proposedAgencies, setProposedAgencies] = useState< | ||
AgencyDataInterface[] | null | ||
>(null); | ||
const [selectedPostcode, setSelectedPostcode] = useState(''); | ||
const [selectedAgency, setSelectedAgency] = | ||
useState<AgencyDataInterface | null>(null); | ||
const validPostcode = () => | ||
selectedPostcode?.length === VALID_POSTCODE_LENGTH; | ||
|
||
const isSelectedAgencyValidated = () => | ||
validPostcode() && typeof selectedAgency?.id === 'number'; | ||
|
||
useEffect(() => { | ||
if (isSelectedAgencyValidated()) { | ||
const agency = { | ||
...selectedAgency, | ||
postcode: selectedPostcode | ||
}; | ||
props.onAgencyChange(agency); | ||
props.onPostcodeChange(selectedPostcode); | ||
} else { | ||
props.onAgencyChange(null); | ||
props.onPostcodeChange(null); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [selectedAgency, selectedPostcode]); | ||
|
||
useEffect(() => { | ||
if (validPostcode()) { | ||
apiGetAgenciesByTenant(selectedPostcode, props.selectedTopicId) | ||
.then((agencies) => { | ||
setProposedAgencies(agencies); | ||
setSelectedAgency(agencies[0]); | ||
}) | ||
.catch((err: any) => { | ||
if (err.message === FETCH_ERRORS.EMPTY) { | ||
setProposedAgencies(null); | ||
setSelectedAgency(null); | ||
} | ||
}); | ||
} else if (proposedAgencies) { | ||
setProposedAgencies(null); | ||
setSelectedAgency(null); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [selectedPostcode, props.selectedTopicId]); | ||
|
||
const postcodeInputItem: InputFieldItem = { | ||
name: 'postcode', | ||
class: 'asker__registration__postcodeInput', | ||
id: 'postcode', | ||
type: 'number', | ||
label: translate('registration.agencySelection.postcode.label'), | ||
content: selectedPostcode, | ||
maxLength: VALID_POSTCODE_LENGTH, | ||
pattern: '^[0-9]+$' | ||
}; | ||
|
||
const handlePostcodeInput = (e) => { | ||
setSelectedPostcode(e.target.value); | ||
}; | ||
|
||
const introItemsTranslations = [ | ||
'registration.agencySelection.intro.point1', | ||
'registration.agencySelection.intro.point2', | ||
'registration.agencySelection.intro.point3' | ||
]; | ||
|
||
return ( | ||
<div className="agencySelection"> | ||
<> | ||
<Headline | ||
semanticLevel="5" | ||
text={translate('registration.agencySelection.headline')} | ||
/> | ||
<div className="agencySelection__intro"> | ||
<Text | ||
text={translate( | ||
'registration.agencySelection.intro.overline' | ||
)} | ||
type="standard" | ||
/> | ||
<div className="agencySelection__intro__content"> | ||
<Text | ||
text={translate( | ||
'registration.agencySelection.intro.subline' | ||
)} | ||
type="standard" | ||
/> | ||
<ul> | ||
{introItemsTranslations.map( | ||
(introItemTranslation, i) => ( | ||
<li key={i}> | ||
<Text | ||
text={translate( | ||
introItemTranslation | ||
)} | ||
type="standard" | ||
/> | ||
</li> | ||
) | ||
)} | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<InputField | ||
item={postcodeInputItem} | ||
inputHandle={(e) => handlePostcodeInput(e)} | ||
/> | ||
{validPostcode() && ( | ||
<div className="agencySelection__proposedAgencies"> | ||
<h3> | ||
{translate( | ||
'registration.agencySelection.title.start' | ||
)}{' '} | ||
{selectedPostcode} | ||
{translate( | ||
'registration.agencySelection.title.end' | ||
)} | ||
</h3> | ||
{proposedAgencies ? ( | ||
proposedAgencies.map( | ||
(proposedAgency: AgencyDataInterface) => ( | ||
<AgencyRadioSelect | ||
key={`agency-${proposedAgency.id}`} | ||
agency={proposedAgency} | ||
checkedValue={proposedAgencies[0].id.toString()} | ||
showTooltipAbove={true} | ||
onChange={() => | ||
setSelectedAgency(proposedAgency) | ||
} | ||
/> | ||
) | ||
) | ||
) : ( | ||
<Text | ||
text={translate( | ||
'registration.agencySelection.noAgencies' | ||
)} | ||
type="infoLargeAlternative" | ||
/> | ||
)} | ||
</div> | ||
)} | ||
</> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.