Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGUK-394 Dunn and Bradstreet integration - Front-end (Phase 1) #3415

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
logger = getLogger(__name__)


def check_url_host_is_safelisted(request):
if request.GET.get('next'):
if url_has_allowed_host_and_scheme(request.GET.get('next'), settings.SAFELIST_HOSTS):
return iri_to_uri(request.GET.get('next'))
def check_url_host_is_safelisted(request, query_param='next'):
if request.GET.get(query_param):
if url_has_allowed_host_and_scheme(request.GET.get(query_param), settings.SAFELIST_HOSTS):
return iri_to_uri(request.GET.get(query_param))
else:
logger.error('Host is not on the safe list - %s', request.GET.get('next'))
logger.error('Host is not on the safe list - %s', request.GET.get(query_param))
return '/'


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
{% endcomment %}
<div class="{% if show_vertical_error_line and field.errors %} govuk-form-group--error{% endif %}">
{% if field.label %}
<label class="govuk-label govuk-label--s"
<label class="{% if label_class %} {{ label_class }} {% else %} govuk-label govuk-label--s {% endif %}"
for="{% if labelForId %}{{ labelForId }}{% else %}{{ field.id_for_label }}{% endif %}">
{{ field.label }}
{% if optional %}<span>(Optional)</span>{% endif %}
{% if dynamicText %}{{ dynamicText }}{% endif %}
</label>
{% endif %}
{% if field.help_text %}
<div class="govuk-hint govuk-!-margin-bottom-2"
<div class="{% if help_class %} {{ help_class }} {% else %} govuk-hint govuk-!-margin-bottom-2 {% endif %}"
id="help_for_{{ field.auto_id }}">{{ field.help_text|safe }}</div>
{% endif %}
{% for error in field.errors %}
Expand All @@ -23,10 +23,10 @@
</p>
{% endfor %}
{% if inputWrapperClass %}
<div class="{{ inputWrapperClass }}">
<span class="{{ inputWrapperClass }}">
{% if inputPrefixClass %}<div class="{{ inputPrefixClass }}" aria-hidden="true">{{ inputPrefixText }}</div>{% endif %}
{% endif %}
{{ field }}
{% if inputWrapperClass %}</div>{% endif %}
{% if inputWrapperClass %}</span>{% endif %}
</div>
{% endif %}
3 changes: 1 addition & 2 deletions international_online_offer/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def feedback_next_url(request):

def is_using_triage(request):
current_url = request.build_absolute_uri(request.path)
business_details = str(reverse_lazy('international_online_offer:business-details'))
business_details = str(reverse_lazy('international_online_offer:company-details'))
contact_details = str(reverse_lazy('international_online_offer:contact-details'))
when_want_setup = str(reverse_lazy('international_online_offer:when-want-setup'))
about_your_business = str(reverse_lazy('international_online_offer:about-your-business'))
Expand All @@ -47,7 +47,6 @@ def is_using_triage(request):
for url in triage_urls:
if url in current_url:
return True
return False


def is_using_login(request):
Expand Down
167 changes: 133 additions & 34 deletions international_online_offer/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
CheckboxInput,
CheckboxSelectMultiple,
ChoiceField,
HiddenInput,
MultipleChoiceField,
PasswordInput,
RadioSelect,
Expand All @@ -25,62 +26,160 @@
COUNTRIES = BLANK_COUNTRY_CHOICE + COUNTRY_CHOICES


class BusinessDetailsForm(forms.Form):
class BusinessHeadquartersForm(forms.Form):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
sector_data_json = get_dbt_sectors()
self.sub_sectors_choices = region_sector_helpers.get_sectors_as_choices(sector_data_json)
self.fields['sector_sub'].choices = (('', ''),) + self.sub_sectors_choices
company_location = ChoiceField(
label=False,
help_text='Enter your country, region or territory and select from results',
required=False,
widget=Select(attrs={'id': 'js-company-location-select', 'class': 'govuk-input'}),
choices=(('', ''),) + choices.COMPANY_LOCATION_CHOICES,
)

# if js is off we use a different success url
js_enabled = BooleanField(required=False, widget=HiddenInput(attrs={'value': 'False'}))

def clean(self):
cleaned_data = super().clean()
company_location = cleaned_data.get('company_location')
if not company_location:
self.add_error('company_location', 'Enter your country, region or territory and select from results')
else:
return cleaned_data


class FindYourCompanyForm(forms.Form):
# the accessible autocomplete that we use to query and search company data enhances a div element rather
# than a TextInput hence in this form we use HiddenInputs to store chosen company details via hidden
# inputs with values set in JS

company_name = CharField(
label='Company name',
required=True,
widget=HiddenInput(attrs={'id': 'company-name'}),
error_messages={
'required': 'Search again for company name or enter manually',
},
)

# below fields set to required=False as there is no way for the user to recover from any errors
duns_number = CharField(
required=False,
widget=HiddenInput(attrs={'id': 'company-duns-number'}),
)

address_line_1 = CharField(
required=False,
widget=HiddenInput(attrs={'id': 'address-line-1'}),
)

address_line_2 = CharField(
required=False,
widget=HiddenInput(attrs={'id': 'address-line-2'}),
)

town = CharField(
required=False,
widget=HiddenInput(attrs={'id': 'address-town'}),
)

county = CharField(
required=False,
widget=HiddenInput(attrs={'id': 'address-county'}),
)

postcode = CharField(
required=False,
widget=HiddenInput(attrs={'id': 'address-postcode'}),
)

company_website = CharField(
required=False,
widget=HiddenInput(attrs={'id': 'company-website'}),
)


class CompanyDetailsForm(forms.Form):

company_name = CharField(
label='Company name',
max_length=255,
widget=TextInput(attrs={'class': 'govuk-input', 'autocomplete': 'organization'}),
error_messages={
'required': 'Enter your company name',
},
)

# sector sub choices are set in form constructor to avoid set effects when importing module
sector_sub = ChoiceField(
label='What is your sector or industry?',
help_text='Search a list of sectors and select the closest one',
required=True,
widget=Select(
attrs={'id': 'js-sector-select', 'class': 'govuk-input', 'aria-describedby': 'help_for_id_sector_sub'}
),
choices=(('', ''),),
company_website = CharField(
label='Website',
max_length=255,
widget=TextInput(attrs={'class': 'govuk-input', 'autocomplete': 'url'}),
error_messages={
'required': 'Search and select a sector',
'required': "Enter your company's website address",
},
)

company_location = ChoiceField(
label='Where is your company headquarters located?',
help_text='Search and select a country, region or territory',
address_line_1 = CharField(
label='Address line 1',
max_length=255,
widget=TextInput(attrs={'class': 'govuk-input', 'autocomplete': 'address-line1'}),
error_messages={
'required': 'Enter address line 1, typically the building and street',
},
)

address_line_2 = CharField(
label='Address line 2 (optional)',
max_length=255,
required=False,
widget=Select(attrs={'id': 'js-company-location-select', 'class': 'govuk-input'}),
choices=(('', ''),) + choices.COMPANY_LOCATION_CHOICES,
widget=TextInput(attrs={'class': 'govuk-input', 'autocomplete': 'address-line2'}),
)

company_website = CharField(
label='Company website address',
required=True,
# no autocomplete on town_or_city due to variations in international addresses, e.g. address-level1 refers
# to post town in the UK and state in the USA
town = CharField(
label='Town or city',
max_length=255,
widget=TextInput(attrs={'class': 'govuk-input', 'autocomplete': 'url'}),
widget=TextInput(attrs={'class': 'govuk-input'}),
error_messages={
'required': """Enter your company's website address""",
'required': 'Enter town or city',
},
)

def clean(self):
cleaned_data = super().clean()
company_location = cleaned_data.get('company_location')
if not company_location:
self.add_error('company_location', 'Search and select a country, region or territory')
else:
return cleaned_data
county = CharField(
label='State, province or county (optional)',
max_length=255,
required=False,
widget=TextInput(attrs={'class': 'govuk-input'}),
)

postcode = CharField(
label='Postal code or zip code (optional)',
max_length=255,
required=False,
widget=TextInput(attrs={'class': 'govuk-input'}),
)


class BusinessSectorForm(forms.Form):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
sector_data_json = get_dbt_sectors()
self.sub_sectors_choices = region_sector_helpers.get_sectors_as_choices(sector_data_json)
self.fields['sector_sub'].choices = (('', ''),) + self.sub_sectors_choices

# sector sub choices are set in form constructor to avoid side effects when importing module
sector_sub = ChoiceField(
label=False,
help_text='Enter your sector or industry and select the closest result',
required=True,
widget=Select(
attrs={'id': 'js-sector-select', 'class': 'govuk-input', 'aria-describedby': 'help_for_id_sector_sub'}
),
choices=(('', ''),),
error_messages={
'required': 'Enter your sector or industry and select the closest result',
},
)


class ContactDetailsForm(forms.Form):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.15 on 2024-09-25 19:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('international_online_offer', '0054_triagedata_sector_id_triagedata_sector_sub_sub_and_more'),
]

operations = [
migrations.AddField(
model_name='userdata',
name='address_line_1',
field=models.CharField(blank=True, default='', max_length=255),
),
migrations.AddField(
model_name='userdata',
name='address_line_2',
field=models.CharField(blank=True, default='', max_length=255),
),
migrations.AddField(
model_name='userdata',
name='duns_number',
field=models.CharField(blank=True, default='', max_length=255),
),
migrations.AddField(
model_name='userdata',
name='postcode',
field=models.CharField(blank=True, default='', max_length=255),
),
migrations.AddField(
model_name='userdata',
name='town',
field=models.CharField(blank=True, default='', max_length=255),
),
]
18 changes: 18 additions & 0 deletions international_online_offer/migrations/0056_userdata_county.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.15 on 2024-09-26 14:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('international_online_offer', '0055_userdata_address_line_1_userdata_address_line_2_and_more'),
]

operations = [
migrations.AddField(
model_name='userdata',
name='county',
field=models.CharField(blank=True, default='', max_length=255),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.2.15 on 2024-10-01 11:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('international_online_offer', '0056_userdata_county'),
]

operations = [
migrations.AlterField(
model_name='userdata',
name='address_line_1',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='userdata',
name='address_line_2',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='userdata',
name='county',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='userdata',
name='duns_number',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='userdata',
name='postcode',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='userdata',
name='town',
field=models.CharField(blank=True, max_length=255, null=True),
),
]
6 changes: 6 additions & 0 deletions international_online_offer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ class UserData(TimeStampedModel):
hashed_uuid = models.CharField(max_length=200)
company_name = models.CharField(max_length=255)
company_location = models.CharField(max_length=255, choices=choices.COMPANY_LOCATION_CHOICES)
duns_number = models.CharField(max_length=255, null=True, blank=True)
address_line_1 = models.CharField(max_length=255, null=True, blank=True)
address_line_2 = models.CharField(max_length=255, null=True, blank=True)
town = models.CharField(max_length=255, null=True, blank=True)
county = models.CharField(max_length=255, null=True, blank=True)
postcode = models.CharField(max_length=255, null=True, blank=True)
full_name = models.CharField(max_length=255)
role = models.CharField(max_length=255)
email = models.CharField(max_length=255)
Expand Down
Loading