import { useState, useEffect } from 'react'; import axios from 'axios'; export default function PrivacySettingsModal({ isOpen, onClose }) { const [organizations, setOrganizations] = useState([]); const [currentOrgIndex, setCurrentOrgIndex] = useState(0); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [settings, setSettings] = useState({ share_career_exploration: false, share_interest_inventory: false, share_career_profiles: false, share_college_profiles: false, share_financial_profile: false, share_roadmap: false }); useEffect(() => { if (isOpen) { fetchOrganizations(); } }, [isOpen]); const fetchOrganizations = async () => { try { setLoading(true); const { data } = await axios.get('/api/privacy-settings', { withCredentials: true }); if (data.organizations && data.organizations.length > 0) { setOrganizations(data.organizations); // Load settings for first org setSettings(data.organizations[0].settings || { share_career_exploration: false, share_interest_inventory: false, share_career_profiles: false, share_college_profiles: false, share_financial_profile: false, share_roadmap: false }); } } catch (err) { console.error('[PrivacySettingsModal] Error loading organizations:', err); } finally { setLoading(false); } }; const handleSave = async () => { if (organizations.length === 0) return; try { setSaving(true); const currentOrg = organizations[currentOrgIndex]; await axios.post('/api/privacy-settings', { organization_id: currentOrg.organization_id, ...settings }, { withCredentials: true }); // If there are more organizations, move to next if (currentOrgIndex < organizations.length - 1) { const nextIndex = currentOrgIndex + 1; setCurrentOrgIndex(nextIndex); setSettings(organizations[nextIndex].settings || { share_career_exploration: false, share_interest_inventory: false, share_career_profiles: false, share_college_profiles: false, share_financial_profile: false, share_roadmap: false }); } else { // All done, close modal onClose(); } } catch (err) { console.error('[PrivacySettingsModal] Error saving settings:', err); alert('Failed to save privacy settings. Please try again.'); } finally { setSaving(false); } }; const toggleSetting = (key) => { setSettings(prev => ({ ...prev, [key]: !prev[key] })); }; if (!isOpen) return null; if (loading) { return (
You've enrolled in {currentOrg.organization_name}. Please choose what information you'd like to share with them. {organizations.length > 1 && ` (${currentOrgIndex + 1} of ${organizations.length})`}
Your privacy is important to us. All settings default to private. When you enable sharing, your organization's counselors can view your activity data (tied to your name and email) to provide personalized guidance. You can change these settings anytime from Profile → Privacy Settings.
{description}
{description}