From ec7b4c9706d6dc4705dd779216bb3ca3ef009192 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 17 Mar 2026 13:36:35 -0400 Subject: [PATCH] fix: AddOrgToDeal accepts no domain (derives from website); frontend derives domain fallback from website field --- api/handlers.go | 34 +++++++++++++++++++++++++++---- portal/templates/app/project.html | 18 ++++++++++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/api/handlers.go b/api/handlers.go index 4ac6ae0..b3765f1 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -1407,9 +1407,22 @@ func (h *Handlers) CreateOrg(w http.ResponseWriter, r *http.Request) { ErrorResponse(w, http.StatusBadRequest, "missing_fields", "Organization name required") return } + // Derive domain from website if not provided + if len(req.Domains) == 0 && req.Website != "" { + domain := req.Website + domain = strings.TrimPrefix(domain, "https://") + domain = strings.TrimPrefix(domain, "http://") + domain = strings.TrimPrefix(domain, "www.") + if idx := strings.Index(domain, "/"); idx != -1 { + domain = domain[:idx] + } + if domain != "" { + req.Domains = []string{strings.ToLower(strings.TrimSpace(domain))} + } + } + // Name is required; domain is best-effort if len(req.Domains) == 0 { - ErrorResponse(w, http.StatusBadRequest, "missing_fields", "At least one domain required") - return + req.Domains = []string{"unknown.invalid"} } // Validate domains are not empty strings for _, d := range req.Domains { @@ -3170,9 +3183,22 @@ func (h *Handlers) AddOrgToDeal(w http.ResponseWriter, r *http.Request) { ErrorResponse(w, http.StatusBadRequest, "missing_fields", "Organization name required") return } + // Derive domain from website if not provided + if len(req.Domains) == 0 && req.Website != "" { + domain := req.Website + domain = strings.TrimPrefix(domain, "https://") + domain = strings.TrimPrefix(domain, "http://") + domain = strings.TrimPrefix(domain, "www.") + if idx := strings.Index(domain, "/"); idx != -1 { + domain = domain[:idx] + } + if domain != "" { + req.Domains = []string{strings.ToLower(strings.TrimSpace(domain))} + } + } + // Name is required; domain is best-effort if len(req.Domains) == 0 { - ErrorResponse(w, http.StatusBadRequest, "missing_fields", "At least one domain required") - return + req.Domains = []string{"unknown.invalid"} } validRoles := map[string]bool{"seller": true, "buyer": true, "ib": true, "advisor": true} if req.Role == "" || !validRoles[req.Role] { diff --git a/portal/templates/app/project.html b/portal/templates/app/project.html index 84238ee..9be774e 100644 --- a/portal/templates/app/project.html +++ b/portal/templates/app/project.html @@ -1299,7 +1299,14 @@ // 2. Add org + members to project const name = document.getElementById('orgName').value.trim(); const role = document.getElementById('orgRole').value; - const domain = scrapedData?.domain || ''; + // Derive domain: prefer scrapedData.domain, fallback to website field + let domain = scrapedData?.domain || ''; + if (!domain) { + const ws = document.getElementById('orgWebsite').value.trim(); + if (ws) { + domain = ws.replace(/^https?:\/\//, '').replace(/^www\./, '').split('/')[0]; + } + } const people = scrapedData?.people || []; const selectedMembers = []; document.querySelectorAll('.person-cb:checked').forEach(cb => { @@ -1602,7 +1609,14 @@ const name = document.getElementById('orgName').value.trim(); const role = document.getElementById('orgRole').value; - const domain = scrapedData?.domain || ''; + // Derive domain: prefer scrapedData.domain, fallback to website field + let domain = scrapedData?.domain || ''; + if (!domain) { + const ws = document.getElementById('orgWebsite').value.trim(); + if (ws) { + domain = ws.replace(/^https?:\/\//, '').replace(/^www\./, '').split('/')[0]; + } + } const people = scrapedData?.people || []; const selectedMembers = []; document.querySelectorAll('.person-cb:checked').forEach(cb => {