Skip to content

Commit 1a82b7a

Browse files
authored
Update register-company.html
1 parent 11574df commit 1a82b7a

1 file changed

Lines changed: 124 additions & 30 deletions

File tree

auth/register-company.html

Lines changed: 124 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -204,43 +204,137 @@ <h3 style="font-size: 1rem; margin-bottom: 1rem;">Setup Preferences</h3>
204204

205205
<div class="toast-container" id="toastContainer"></div>
206206

207-
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
208-
<script src="../js/supabase-client.js"></script>
209-
<script src="../js/auth.js"></script>
210-
<script>
211-
let currentStep = 1;
212-
function goToStep(step) {
213-
// Validation for step 1
214-
if (step === 2 && currentStep === 1) {
215-
const name = document.getElementById('regName').value;
216-
const email = document.getElementById('regEmail').value;
217-
const pass = document.getElementById('regPassword').value;
218-
const passConfirm = document.getElementById('regPasswordConfirm').value;
219-
if (!name || !email || !pass) { showToast('Please fill all required fields', 'error'); return; }
220-
if (pass !== passConfirm) { showToast('Passwords do not match', 'error'); return; }
221-
if (pass.length < 8) { showToast('Password must be at least 8 characters', 'error'); return; }
222-
}
223-
if (step === 3 && currentStep === 2) {
224-
const compName = document.getElementById('companyName').value;
225-
if (!compName) { showToast('Please enter company name', 'error'); return; }
226-
}
207+
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
208+
<script src="../js/supabase-client.js"></script>
209+
<script>
210+
const API = 'https://evalis-ai.simpaticohrconsultancy.workers.dev';
227211

228-
document.querySelectorAll('.form-step').forEach(s => s.classList.add('hidden'));
229-
document.getElementById(`step${step}`).classList.remove('hidden');
212+
let currentStep = 1;
230213

231-
for (let i = 1; i <= 3; i++) {
214+
function goToStep(step) {
215+
if (step === 2 && currentStep === 1) {
216+
const name = document.getElementById('regName').value;
217+
const email = document.getElementById('regEmail').value;
218+
const pass = document.getElementById('regPassword').value;
219+
const confirm = document.getElementById('regPasswordConfirm').value;
220+
if (!name || !email || !pass) { toast('Please fill all required fields', 'error'); return; }
221+
if (pass !== confirm) { toast('Passwords do not match', 'error'); return; }
222+
if (pass.length < 8) { toast('Password must be at least 8 characters', 'error'); return; }
223+
}
224+
if (step === 3 && currentStep === 2) {
225+
const compName = document.getElementById('companyName').value;
226+
if (!compName) { toast('Please enter company name', 'error'); return; }
227+
}
228+
document.querySelectorAll('.form-step').forEach(s => s.classList.add('hidden'));
229+
document.getElementById(`step${step}`).classList.remove('hidden');
230+
for (let i = 1; i <= 3; i++) {
232231
const dot = document.getElementById(`step${i}Dot`);
233232
dot.classList.remove('active', 'done');
234233
if (i < step) dot.classList.add('done');
235234
if (i === step) dot.classList.add('active');
236-
}
237-
if (step > 1) document.getElementById('line1').classList.add('done');
238-
else document.getElementById('line1').classList.remove('done');
239-
if (step > 2) document.getElementById('line2').classList.add('done');
240-
else document.getElementById('line2').classList.remove('done');
235+
}
236+
if (step > 1) document.getElementById('line1').classList.add('done');
237+
else document.getElementById('line1').classList.remove('done');
238+
if (step > 2) document.getElementById('line2').classList.add('done');
239+
else document.getElementById('line2').classList.remove('done');
240+
currentStep = step;
241+
}
242+
243+
async function submitCompanyRegistration() {
244+
const btn = document.getElementById('submitBtn');
245+
const spinner = document.getElementById('submitSpinner');
246+
const btnText = document.getElementById('submitText');
247+
248+
// Gather all form values
249+
const payload = {
250+
// Step 1 — account
251+
full_name: document.getElementById('regName').value.trim(),
252+
email: document.getElementById('regEmail').value.trim(),
253+
password: document.getElementById('regPassword').value,
254+
phone: document.getElementById('regPhone')?.value.trim() || '',
255+
role: 'company_admin',
256+
257+
// Step 2 — company
258+
company_name: document.getElementById('companyName').value.trim(),
259+
industry: document.getElementById('companyIndustry')?.value || '',
260+
company_size: document.getElementById('companySize')?.value || '',
261+
website: document.getElementById('companyWebsite')?.value.trim() || '',
262+
contact_email: document.getElementById('regEmail').value.trim(),
263+
264+
// Step 3 — plan
265+
subscription_plan: document.getElementById('planSelect')?.value || 'trial',
266+
whatsapp: document.getElementById('regPhone')?.value.trim() || '',
267+
};
268+
269+
if (!payload.full_name || !payload.email || !payload.company_name) {
270+
toast('Please complete all required fields', 'error'); return;
271+
}
272+
273+
// Loading state
274+
if (btn) btn.disabled = true;
275+
if (spinner) spinner.style.display = 'inline-block';
276+
if (btnText) btnText.textContent = 'Creating account...';
277+
278+
try {
279+
const res = await fetch(`${API}/api/auth/register-company`, {
280+
method: 'POST',
281+
headers: { 'Content-Type': 'application/json' },
282+
body: JSON.stringify(payload)
283+
});
284+
285+
const data = await res.json();
286+
287+
if (!res.ok || data.error) {
288+
throw new Error(data.error || data.message || 'Registration failed');
289+
}
241290

242-
currentStep = step;
291+
// Save session
292+
if (data.token) {
293+
localStorage.setItem('simpatico_token', data.token);
294+
localStorage.setItem('simpatico_user', JSON.stringify(data.user || {
295+
email: payload.email,
296+
full_name: payload.full_name,
297+
role: 'company_admin'
298+
}));
299+
if (data.company) {
300+
localStorage.setItem('simpatico_company', JSON.stringify(data.company));
301+
}
302+
}
303+
304+
toast('✅ Company registered! Redirecting to dashboard...', 'success');
305+
setTimeout(() => {
306+
window.location.href = data.token
307+
? '../dashboard/hr.html'
308+
: 'login.html';
309+
}, 1500);
310+
311+
} catch (err) {
312+
console.error('Registration error:', err);
313+
toast(err.message || 'Registration failed. Please try again.', 'error');
314+
} finally {
315+
if (btn) btn.disabled = false;
316+
if (spinner) spinner.style.display = 'none';
317+
if (btnText) btnText.textContent = 'Complete Registration';
243318
}
244-
</script>
319+
}
320+
321+
function toast(msg, type = 'info') {
322+
document.querySelector('.toast')?.remove();
323+
const t = document.createElement('div');
324+
t.className = `toast toast-${type}`;
325+
t.textContent = msg;
326+
// Basic inline styles in case app.css not loaded
327+
Object.assign(t.style, {
328+
position:'fixed', top:'20px', right:'20px', padding:'14px 20px',
329+
borderRadius:'10px', fontSize:'14px', fontWeight:'600', color:'#fff',
330+
zIndex:'10000', maxWidth:'400px', boxShadow:'0 10px 30px rgba(0,0,0,0.2)',
331+
background: type==='success' ? '#059669' : type==='error' ? '#DC2626' : '#2563EB'
332+
});
333+
document.body.appendChild(t);
334+
setTimeout(() => t.remove(), 4000);
335+
}
336+
</script>
337+
</body>
338+
</html>
245339
</body>
246340
</html>

0 commit comments

Comments
 (0)