improve(wizard): add website discovery button + fix company name from KRS
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
- Add 'Wyszukaj stronę' button in Step 2 next to WWW field (uses WebsiteDiscoveryService/Brave) - Fix company name: update from legal_name when KRS enrichment provides it - Add discover-website endpoint Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
275195c332
commit
9235377db0
@ -205,6 +205,12 @@ def wizard_step1():
|
||||
elif registry_source == 'CEIDG' and ceidg_data:
|
||||
_apply_ceidg_data(company, ceidg_data, db)
|
||||
|
||||
# Update name from legal_name if still placeholder
|
||||
if company.legal_name and company.name.startswith('Firma NIP'):
|
||||
company.name = company.legal_name
|
||||
company.slug = _generate_slug(company.name)
|
||||
company.slug = _ensure_unique_slug(db, company.slug, exclude_id=company.id)
|
||||
|
||||
company.wizard_step = 2
|
||||
db.commit()
|
||||
|
||||
@ -429,6 +435,50 @@ def wizard_step2():
|
||||
# STEP 3: WEBSITE & LOGO
|
||||
# ============================================================
|
||||
|
||||
@bp.route('/companies/wizard/discover-website', methods=['POST'])
|
||||
@login_required
|
||||
@role_required(SystemRole.OFFICE_MANAGER)
|
||||
def wizard_discover_website():
|
||||
"""Search for company website using Brave Search."""
|
||||
data = request.get_json()
|
||||
company_id = data.get('company_id')
|
||||
|
||||
if not company_id:
|
||||
return jsonify({'success': False, 'error': 'Brak company_id'}), 400
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
company = db.query(Company).filter_by(
|
||||
id=company_id, status='wizard_draft'
|
||||
).first()
|
||||
if not company:
|
||||
return jsonify({'success': False, 'error': 'Firma nie znaleziona'}), 404
|
||||
|
||||
from services.website_discovery_service import WebsiteDiscoveryService
|
||||
service = WebsiteDiscoveryService(db=db)
|
||||
result = service.discover_for_company(company)
|
||||
|
||||
if result and result.get('error'):
|
||||
return jsonify({'success': False, 'error': result['error']})
|
||||
|
||||
# Refresh company — discover_for_company may have updated website
|
||||
db.refresh(company)
|
||||
website = company.website
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'website': website,
|
||||
'details': result
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
logger.error(f"Website discovery error: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@bp.route('/companies/wizard/step3/fetch-logos', methods=['POST'])
|
||||
@login_required
|
||||
@role_required(SystemRole.OFFICE_MANAGER)
|
||||
|
||||
@ -397,7 +397,13 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Strona WWW</label>
|
||||
<input type="text" id="editWebsite" class="form-control" placeholder="https://">
|
||||
<div class="nip-input-row">
|
||||
<input type="text" id="editWebsite" class="form-control" placeholder="https://">
|
||||
<button class="btn-wizard btn-secondary" id="btnDiscoverWebsite" onclick="discoverWebsite()">
|
||||
Wyszukaj stronę
|
||||
</button>
|
||||
</div>
|
||||
<div id="discoverStatus" style="display:none"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@ -733,6 +739,42 @@
|
||||
}
|
||||
}
|
||||
|
||||
function discoverWebsite() {
|
||||
var btn = document.getElementById('btnDiscoverWebsite');
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<span class="spinner"></span> Szukam...';
|
||||
var statusEl = document.getElementById('discoverStatus');
|
||||
statusEl.style.display = 'block';
|
||||
statusEl.className = 'lookup-status loading';
|
||||
statusEl.innerHTML = '<span class="spinner"></span> Szukam strony w internecie...';
|
||||
|
||||
fetch('/admin/companies/wizard/discover-website', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json', 'X-CSRFToken': getCSRF()},
|
||||
body: JSON.stringify({company_id: wizardState.companyId})
|
||||
})
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(data) {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = 'Wyszukaj stronę';
|
||||
if (data.success && data.website) {
|
||||
document.getElementById('editWebsite').value = data.website;
|
||||
wizardState.companyData.website = data.website;
|
||||
statusEl.className = 'lookup-status success';
|
||||
statusEl.innerHTML = 'Znaleziono: ' + esc(data.website);
|
||||
} else {
|
||||
statusEl.className = 'lookup-status error';
|
||||
statusEl.innerHTML = data.error || 'Nie znaleziono strony internetowej';
|
||||
}
|
||||
})
|
||||
.catch(function(err) {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = 'Wyszukaj stronę';
|
||||
statusEl.className = 'lookup-status error';
|
||||
statusEl.innerHTML = 'Błąd: ' + err.message;
|
||||
});
|
||||
}
|
||||
|
||||
function saveStep2() {
|
||||
var btn = document.getElementById('btnStep2Next');
|
||||
btn.disabled = true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user