File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ module Api
55 class OrgsByDomainController < ApplicationController
66 # GET /api/get-orgs-by-domain?domain=berkeley.edu
77 def index
8- domain_param = search_params [ :domain ]
8+ email_param = search_params [ :email ]
9+ email_domain = email_param . split ( '@' ) . last if email_param . present? && email_param . include? ( '@' )
910
1011 dummy_orgs = [
1112 {
@@ -26,8 +27,8 @@ def index
2627 ]
2728
2829 # Filter orgs by domain if domain parameter is provided
29- if domain_param . present?
30- filtered_orgs = dummy_orgs . select { |org | org [ :domain ] == domain_param }
30+ if email_param . present?
31+ filtered_orgs = dummy_orgs . select { |org | org [ :domain ] == email_domain }
3132
3233 # If no matches found, return the "OTHER" org
3334 if filtered_orgs . empty?
@@ -52,7 +53,7 @@ def index
5253
5354 # Using Strong Parameters ensure only domain is permitted
5455 def search_params
55- params . permit ( :domain , :format )
56+ params . permit ( :email , :format )
5657 end
5758 end
5859end
Original file line number Diff line number Diff line change @@ -12,39 +12,36 @@ $(() => {
1212 return ;
1313 }
1414
15- let currentDomain = '' ;
15+ let currentEmail = '' ;
1616 let debounceTimer = null ;
1717
1818 // Handle email input changes
1919 emailField . addEventListener ( 'input' , function ( ) {
2020 const email = this . value ;
2121
2222 if ( email && email . includes ( '@' ) ) {
23- const domain = email . split ( '@' ) [ 1 ] ;
24-
25- // Only fetch if domain has changed
26- if ( domain && domain !== currentDomain ) {
27- currentDomain = domain ;
28-
23+ if ( email !== currentEmail ) {
24+ currentEmail = email ;
25+
2926 // Clear previous timer
3027 if ( debounceTimer ) {
3128 clearTimeout ( debounceTimer ) ;
3229 }
3330
3431 // Debounce API calls to avoid too many requests
3532 debounceTimer = setTimeout ( ( ) => {
36- fetchOrganizations ( domain ) ;
33+ fetchOrganizations ( email ) ;
3734 } , 500 ) ;
3835 }
3936 } else {
4037 // Clear organizations if email is invalid
41- currentDomain = '' ;
38+ currentEmail = '' ;
4239 resetOrgSelect ( ) ;
4340 }
4441 } ) ;
4542
46- function fetchOrganizations ( domain ) {
47- fetch ( `/api/get-orgs-by-domain?domain =${ encodeURIComponent ( domain ) } ` )
43+ function fetchOrganizations ( email ) {
44+ fetch ( `/api/get-orgs-by-domain?email =${ encodeURIComponent ( email ) } ` )
4845 . then ( response => response . json ( ) )
4946 . then ( data => {
5047 populateOrgSelect ( data ) ;
You can’t perform that action at this time.
0 commit comments