fix: AddOrgToDeal accepts no domain (derives from website); frontend derives domain fallback from website field

This commit is contained in:
James 2026-03-17 13:36:35 -04:00
parent ec0b60d44c
commit ec7b4c9706
2 changed files with 46 additions and 6 deletions

View File

@ -1407,9 +1407,22 @@ func (h *Handlers) CreateOrg(w http.ResponseWriter, r *http.Request) {
ErrorResponse(w, http.StatusBadRequest, "missing_fields", "Organization name required") ErrorResponse(w, http.StatusBadRequest, "missing_fields", "Organization name required")
return 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 { if len(req.Domains) == 0 {
ErrorResponse(w, http.StatusBadRequest, "missing_fields", "At least one domain required") req.Domains = []string{"unknown.invalid"}
return
} }
// Validate domains are not empty strings // Validate domains are not empty strings
for _, d := range req.Domains { 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") ErrorResponse(w, http.StatusBadRequest, "missing_fields", "Organization name required")
return 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 { if len(req.Domains) == 0 {
ErrorResponse(w, http.StatusBadRequest, "missing_fields", "At least one domain required") req.Domains = []string{"unknown.invalid"}
return
} }
validRoles := map[string]bool{"seller": true, "buyer": true, "ib": true, "advisor": true} validRoles := map[string]bool{"seller": true, "buyer": true, "ib": true, "advisor": true}
if req.Role == "" || !validRoles[req.Role] { if req.Role == "" || !validRoles[req.Role] {

View File

@ -1299,7 +1299,14 @@
// 2. Add org + members to project // 2. Add org + members to project
const name = document.getElementById('orgName').value.trim(); const name = document.getElementById('orgName').value.trim();
const role = document.getElementById('orgRole').value; 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 people = scrapedData?.people || [];
const selectedMembers = []; const selectedMembers = [];
document.querySelectorAll('.person-cb:checked').forEach(cb => { document.querySelectorAll('.person-cb:checked').forEach(cb => {
@ -1602,7 +1609,14 @@
const name = document.getElementById('orgName').value.trim(); const name = document.getElementById('orgName').value.trim();
const role = document.getElementById('orgRole').value; 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 people = scrapedData?.people || [];
const selectedMembers = []; const selectedMembers = [];
document.querySelectorAll('.person-cb:checked').forEach(cb => { document.querySelectorAll('.person-cb:checked').forEach(cb => {