diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index badf7ab..1a905db 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -160,12 +160,27 @@ function CustomerForm({ onDone, onCancel, customer }) { name: customer?.name || '', email: customer?.email || '', espocrm_url: customer?.espocrm_url || '', espocrm_api_key: '' }) + const [authUser, setAuthUser] = useState('') + const [authPass, setAuthPass] = useState('') + + const updateAuthFromCredentials = (user, pass) => { + setAuthUser(user) + setAuthPass(pass) + if (user && pass) { + setForm(f => ({ ...f, espocrm_api_key: btoa(user + ':' + pass) })) + } else { + setForm(f => ({ ...f, espocrm_api_key: '' })) + } + } + const submit = async () => { + const payload = { ...form } + if (!payload.espocrm_api_key) delete payload.espocrm_api_key const url = isEdit ? `${API}/customers/${customer.id}` : `${API}/customers` await fetch(url, { method: isEdit ? 'PUT' : 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(form) + body: JSON.stringify(payload) }) onDone() } @@ -178,9 +193,25 @@ function CustomerForm({ onDone, onCancel, customer }) { className={inputClass} dir="ltr" /> setForm({ ...form, espocrm_url: e.target.value })} className={inputClass} dir="ltr" /> - setForm({ ...form, espocrm_api_key: e.target.value })} - className={`${inputClass} font-mono`} dir="ltr" /> +
+

פרטי התחברות ל-EspoCRM

+
+ updateAuthFromCredentials(authUser, e.target.value)} + className="flex-1 bg-white border border-slate-200 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500" dir="ltr" type="password" /> + updateAuthFromCredentials(e.target.value, authPass)} + className="flex-1 bg-white border border-slate-200 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500" dir="ltr" /> +
+ {form.espocrm_api_key && ( +

+ Espo-Authorization: {form.espocrm_api_key} +

+ )} + {isEdit && !form.espocrm_api_key && ( +

השאר ריק כדי לא לשנות

+ )} +