Review company scan suggestions before saving profile
This commit is contained in:
+14
-50
@@ -2,7 +2,7 @@ import {mergeServerNotifications,acknowledgeNotifications} from '../services/not
|
||||
import { searchTender } from '../services/searchTender';
|
||||
import { normalizeTenderSearch, matchingItemResults } from '../services/tenderSearch';
|
||||
import React, {createContext, useContext, useState, useEffect, useMemo, useRef } from 'react';
|
||||
import { parseWebsiteCapabilitiesDynamically } from '../services/webScraperService';
|
||||
import { scanCompanyProposal } from '../services/companyProfile';
|
||||
import { havuzuPuanla, profilMetni, profilTerimleri } from '../services/uyum';
|
||||
import { getToken } from '../services/auth';
|
||||
import { fetchLiveTenders, fetchTenderDetail, mergeUserState } from '../services/tenderApi';
|
||||
@@ -479,14 +479,6 @@ export const AppProvider = ({ children }) => {
|
||||
};
|
||||
|
||||
const [userProfile, setUserProfile] = useState(() => defaultProfile(getStoredUser()));
|
||||
useEffect(() => {
|
||||
const veri = {
|
||||
company: userProfile.company, website: userProfile.website,
|
||||
scrapedCapabilities: userProfile.scrapedCapabilities, uyumEsigi: userProfile.uyumEsigi,
|
||||
};
|
||||
if (veriSenkron) ilkYazmaDegil('firma_profil', veri);
|
||||
}, [userProfile.company, userProfile.website, userProfile.scrapedCapabilities, userProfile.uyumEsigi, veriSenkron]);
|
||||
const setUyumEsigi = (v) => setUserProfile((p) => ({ ...p, uyumEsigi: Math.max(0, Math.min(100, Number(v) || 0)) }));
|
||||
|
||||
// Anlamsal bonus: profil metni sunucuda gömülür, havuzla kosinüs alınır,
|
||||
// z-skor → 0..20. Profil terimi yoksa ya da oturum yoksa istenmez. Havuz
|
||||
@@ -522,47 +514,20 @@ export const AppProvider = ({ children }) => {
|
||||
[tenders, userProfile.scrapedCapabilities, gommeBonus],
|
||||
);
|
||||
|
||||
// Önce gerçek tarama (/api/company/scan: site metni + model), başarısızsa
|
||||
// alan adından tahmin eden eski yol. Sonuç uyum skorunun girdisi olur.
|
||||
const scanCompanyWebsite = async (url) => {
|
||||
const session = getToken();
|
||||
let yeni = null;
|
||||
const scanCompanyWebsite = scanCompanyProposal;
|
||||
const profileSaveLock=useRef(false);
|
||||
const updateCompanyCapabilities = async (capabilities,{website=userProfile.website,threshold=userProfile.uyumEsigi}={}) => {
|
||||
if(!authUser||!veriSenkron)throw new Error('Hesap verileri yüklenmeden profil kaydedilemez.');
|
||||
if(profileSaveLock.current)throw new Error('Önceki profil kaydı sürüyor.');
|
||||
const session=getToken();
|
||||
profileSaveLock.current=true;
|
||||
try {
|
||||
const r = await fetch('/api/company/scan', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` },
|
||||
body: JSON.stringify({ url }),
|
||||
});
|
||||
const d = await r.json();
|
||||
if (d.success && d.sonuc) {
|
||||
const so = d.sonuc;
|
||||
yeni = {
|
||||
scrapedAt: new Date().toLocaleString('tr-TR'),
|
||||
extractedSectors: so.sektorler || [],
|
||||
extractedProducts: so.urunler || [],
|
||||
extractedCertifications: so.sertifikalar || [],
|
||||
ihaleKonulari: so.ihaleKonulari || [],
|
||||
ozet: so.ozet || null,
|
||||
tarananSayfa: d.tarananSayfa,
|
||||
matchScoreBoost: 0,
|
||||
gercekTarama: true,
|
||||
};
|
||||
}
|
||||
} catch { /* aşağıda yedek yol */ }
|
||||
if (!yeni) yeni = { ...parseWebsiteCapabilitiesDynamically(url), ihaleKonulari: [], gercekTarama: false };
|
||||
if(getToken() !== session) throw new Error('Oturum değişti; firma taraması bu hesaba aktarılmadı.');
|
||||
setUserProfile((prev) => ({ ...prev, website: url, scrapedCapabilities: yeni }));
|
||||
return yeni;
|
||||
};
|
||||
|
||||
const updateCompanyCapabilities = (updatedCapabilities) => {
|
||||
setUserProfile(prev => ({
|
||||
...prev,
|
||||
scrapedCapabilities: {
|
||||
...prev.scrapedCapabilities,
|
||||
...updatedCapabilities
|
||||
}
|
||||
}));
|
||||
const profile={company:userProfile.company,website,scrapedCapabilities:capabilities,uyumEsigi:Math.max(0,Math.min(100,Number(threshold)||0))};
|
||||
await setUserData('firma_profil',profile);
|
||||
if(getToken()!==session)throw new Error('Oturum değişti; profil bu hesaba aktarılmadı.');
|
||||
setUserProfile(previous=>({...previous,...profile}));
|
||||
return profile;
|
||||
}finally{profileSaveLock.current=false;}
|
||||
};
|
||||
|
||||
const [notifications, setNotifications] = useState([]);
|
||||
@@ -741,7 +706,6 @@ export const AppProvider = ({ children }) => {
|
||||
setActiveTab,
|
||||
tenders: tendersSkorlu,
|
||||
uyumEsigi: userProfile.uyumEsigi,
|
||||
setUyumEsigi,
|
||||
gommeDurum,
|
||||
setTenders,
|
||||
isLiveMode,
|
||||
|
||||
Reference in New Issue
Block a user