diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index ab94bec7a..06927ed51 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -1975,33 +1975,34 @@ class MembersTable extends LoadTableBase { const options = { year: 'numeric', month: 'short', day: 'numeric' }; // Handle last_active values - let last_active = NaN - last_active = member.last_active; + let last_active = member.last_active; // Changed to let to allow for potential modification let last_active_formatted = ''; - let last_active_sort_value = ''; + let last_active_sort_value = NaN; - // Handle 'Invited' or null/empty values differently from valid dates - if (last_active !== invited) { - try { - // Try to parse the last_active as a valid date - // Try to parse the last_active as a valid date + // Check if last_active is valid before proceeding + if (last_active) { + if (last_active === invited) { + last_active_formatted = invited; + last_active_sort_value = invited; // Keep 'Invited' as a sortable value + } else { const parsedDate = new Date(last_active); - if (!isNaN(last_active)) { - last_active_formatted = parsedDate.toLocaleDateString('en-US', options); - last_active_sort_value = parsedDate.getTime(); // For sorting purposes - } else { - last_active_formatted='Invalid date'; - last_active_sort_value = 'Invalid date'; + + try { + if (!isNaN(parsedDate.getTime())) { // Check if the date is valid + last_active_formatted = parsedDate.toLocaleDateString('en-US', options); + last_active_sort_value = parsedDate.getTime(); // For sorting purposes + } else { + throw new Error('Invalid date'); // Throw an error to catch in catch block + } + } catch (e) { + console.error(`Error parsing date: ${last_active}. Error: ${e}`); + last_active_formatted = 'Invalid date'; + last_active_sort_value = 'Invalid date'; } - } catch (e) { - console.error(`Error parsing date: ${last_active}. Error: ${e}`); - last_active_formatted='Invalid date' } - } else { - // Handle 'Invited' or null - last_active = invited; - last_active_formatted = invited; - last_active_sort_value = invited; // Keep 'Invited' as a sortable string + } else { // last_active is null or undefined + last_active_formatted = 'Invalid date'; + last_active_sort_value = 'Invalid date'; // Default value for invalid or missing last_active } const action_url = member.action_url; diff --git a/src/registrar/views/portfolio_members_json.py b/src/registrar/views/portfolio_members_json.py index e888feda5..dc5d2d57c 100644 --- a/src/registrar/views/portfolio_members_json.py +++ b/src/registrar/views/portfolio_members_json.py @@ -113,8 +113,6 @@ def initial_permissions_search(portfolio): def initial_invitations_search(portfolio): """Perform initial invitations search and get related DomainInvitation data based on the email.""" - - # Get DomainInvitation query for matching email domain_invitations = DomainInvitation.objects.filter( email=OuterRef('email'), @@ -127,7 +125,6 @@ def initial_invitations_search(portfolio): output_field=CharField() ) ) - invitations = PortfolioInvitation.objects.filter(portfolio=portfolio) invitations = invitations.annotate( first_name=Value(None, output_field=CharField()),