From 9a6ccc1c44d136ff12e1a2ff910f705dd3b5f266 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 20 May 2024 11:25:32 -0600 Subject: [PATCH] Replace form with modelform Pull in content from related PR and refactor around it --- src/registrar/assets/js/get-gov.js | 29 +-- .../assets/sass/_theme/_fieldsets.scss | 23 +- src/registrar/config/urls.py | 4 +- src/registrar/forms/finish_user_setup.py | 48 ---- src/registrar/forms/user_profile.py | 30 ++- src/registrar/models/contact.py | 7 - ...t_setup.html => finish_profile_setup.html} | 18 +- src/registrar/views/__init__.py | 5 +- src/registrar/views/finish_user_setup.py | 241 ------------------ src/registrar/views/user_profile.py | 188 +++++++++++++- 10 files changed, 230 insertions(+), 363 deletions(-) delete mode 100644 src/registrar/forms/finish_user_setup.py rename src/registrar/templates/{finish_contact_setup.html => finish_profile_setup.html} (82%) delete mode 100644 src/registrar/views/finish_user_setup.py diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 315ff38f4..2fd534f04 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -873,35 +873,16 @@ function hideDeletedForms() { let fieldId = getInputFieldId(fieldName) let inputField = document.querySelector(fieldId); - let nameFieldset = document.querySelector("#contact-full-name-fieldset"); + let nameFieldset = document.querySelector("#profile-name-fieldset"); if (nameFieldset){ nameFieldset.classList.remove("display-none"); } if (inputField) { - let readonlyId = getReadonlyFieldId(fieldName) - let readonlyField = document.querySelector(readonlyId) - if (readonlyField) { - // Update the element's xlink:href attribute - let useElement = readonlyField.querySelector("use"); - if (useElement) { - let currentHref = useElement.getAttribute("xlink:href"); - let parts = currentHref.split("#"); - - // Update the icon reference to the info icon - if (parts.length > 1) { - parts[1] = "info_outline"; - useElement.setAttribute("xlink:href", parts.join("#")); - - // Change the color to => $dhs-dark-gray-60 - useElement.closest('svg').style.fill = '#444547'; - } - } - - let parentDiv = readonlyField.closest("div"); - if (parentDiv) { - parentDiv.classList.toggle("overlapped-full-name-field"); - } + // Remove the "full_name" field + inputFieldParentDiv = inputField.closest("div"); + if (inputFieldParentDiv) { + inputFieldParentDiv.remove(); } } } diff --git a/src/registrar/assets/sass/_theme/_fieldsets.scss b/src/registrar/assets/sass/_theme/_fieldsets.scss index da900f128..7ad0a2a82 100644 --- a/src/registrar/assets/sass/_theme/_fieldsets.scss +++ b/src/registrar/assets/sass/_theme/_fieldsets.scss @@ -10,23 +10,8 @@ fieldset:not(:first-child) { } fieldset.registrar-fieldset__contact { - border-width: 2px; - border-left: none; - border-right: none; - border-bottom: none; - padding-bottom: 0; + // This fieldset is for SR purposes only + border: 0; + margin: 0; + padding: 0; } - -@media (min-width: 800px) { - fieldset.registrar-fieldset__contact { - margin-top: 28px; - } -} - -@media (max-width: 800px){ - fieldset.registrar-fieldset__contact { - padding: 0; - margin: 0; - border: none; - } -} \ No newline at end of file diff --git a/src/registrar/config/urls.py b/src/registrar/config/urls.py index 5ed9adae0..2d4c33569 100644 --- a/src/registrar/config/urls.py +++ b/src/registrar/config/urls.py @@ -103,8 +103,8 @@ urlpatterns = [ path( # We embed the current user ID here, but we have a permission check # that ensures the user is who they say they are. - "finish-user-setup/", - views.FinishUserSetupView.as_view(), + "finish-profile-setup/", + views.FinishProfileSetupView.as_view(), name="finish-user-profile-setup", ), path( diff --git a/src/registrar/forms/finish_user_setup.py b/src/registrar/forms/finish_user_setup.py deleted file mode 100644 index 46b75090f..000000000 --- a/src/registrar/forms/finish_user_setup.py +++ /dev/null @@ -1,48 +0,0 @@ -from django import forms -from phonenumber_field.formfields import PhoneNumberField # type: ignore - - -class FinishUserSetupForm(forms.Form): - """Form for adding or editing user information""" - - def clean(self): - cleaned_data = super().clean() - # Remove the full name property - if "full_name" in cleaned_data: - # Delete the full name element as its purely decorative. - # We include it as a normal Charfield for all the advantages - # and utility that it brings, but we're playing pretend. - del cleaned_data["full_name"] - return cleaned_data - - full_name = forms.CharField( - label="Full name", - error_messages={"required": "Enter your full name"}, - ) - first_name = forms.CharField( - label="First name / given name", - error_messages={"required": "Enter your first name / given name."}, - ) - middle_name = forms.CharField( - required=False, - label="Middle name (optional)", - ) - last_name = forms.CharField( - label="Last name / family name", - error_messages={"required": "Enter your last name / family name."}, - ) - title = forms.CharField( - label="Title or role in your organization", - error_messages={ - "required": ("Enter your title or role in your organization (e.g., Chief Information Officer).") - }, - ) - email = forms.EmailField( - label="Organization email", - required=False, - max_length=None, - ) - phone = PhoneNumberField( - label="Phone", - error_messages={"invalid": "Enter a valid 10-digit phone number.", "required": "Enter your phone number."}, - ) diff --git a/src/registrar/forms/user_profile.py b/src/registrar/forms/user_profile.py index 036b03751..abc90d195 100644 --- a/src/registrar/forms/user_profile.py +++ b/src/registrar/forms/user_profile.py @@ -55,6 +55,34 @@ class UserProfileForm(forms.ModelForm): "required": "Enter your email address in the required format, like name@example.com." } self.fields["phone"].error_messages["required"] = "Enter your phone number." - self.domainInfo = None DomainHelper.disable_field(self.fields["email"], disable_required=True) + + +class FinishSetupProfileForm(UserProfileForm): + """Form for updating user profile.""" + + full_name = forms.CharField(required=True, label="Full name") + + def clean(self): + cleaned_data = super().clean() + # Remove the full name property + if "full_name" in cleaned_data: + # Delete the full name element as its purely decorative. + # We include it as a normal Charfield for all the advantages + # and utility that it brings, but we're playing pretend. + del cleaned_data["full_name"] + return cleaned_data + + def __init__(self, *args, **kwargs): + """Override the inerited __init__ method to update the fields.""" + + super().__init__(*args, **kwargs) + + # Set custom form label for email + self.fields["email"].label = "Organization email" + self.fields["title"].label = "Title or role in your organization" + + # Define the "full_name" value + if self.instance and hasattr(self.instance, 'full_name'): + self.fields["full_name"].initial = self.instance.get_formatted_name() diff --git a/src/registrar/models/contact.py b/src/registrar/models/contact.py index 716849b32..0f55ed863 100644 --- a/src/registrar/models/contact.py +++ b/src/registrar/models/contact.py @@ -102,13 +102,6 @@ class Contact(TimeStampedModel): names = [n for n in [self.first_name, self.middle_name, self.last_name] if n] return " ".join(names) if names else "Unknown" - @property - def full_name(self): - """ - Returns the full name (first_name, middle_name, last_name) of this contact. - """ - return self.get_formatted_name() - def has_contact_info(self): return bool(self.title or self.email or self.phone) diff --git a/src/registrar/templates/finish_contact_setup.html b/src/registrar/templates/finish_profile_setup.html similarity index 82% rename from src/registrar/templates/finish_contact_setup.html rename to src/registrar/templates/finish_profile_setup.html index 301f5837a..a8e16724e 100644 --- a/src/registrar/templates/finish_contact_setup.html +++ b/src/registrar/templates/finish_profile_setup.html @@ -62,25 +62,17 @@ Your contact information - - {# TODO: if an error is thrown here or edit clicked, show first last and middle fields #} - {# Also todo: consolidate all of the scattered classes into this usa form one #} + {% with show_edit_button=True show_readonly=True group_classes="usa-form-readonly padding-top-2" %} {% input_with_errors form.full_name %} {% endwith %} -