refactor: simplify privacy tab by removing data settings and restricting profile visibility to agents only
This commit is contained in:
@@ -14,22 +14,14 @@ class PrivacyTab extends ConsumerStatefulWidget {
|
|||||||
|
|
||||||
class _PrivacyTabState extends ConsumerState<PrivacyTab> {
|
class _PrivacyTabState extends ConsumerState<PrivacyTab> {
|
||||||
String _profileVisibility = 'public';
|
String _profileVisibility = 'public';
|
||||||
String _contactInfo = 'connections';
|
|
||||||
String _activityStatus = 'public';
|
String _activityStatus = 'public';
|
||||||
bool _shareAnalytics = false;
|
|
||||||
bool _personalizedAds = false;
|
|
||||||
bool _thirdPartySharing = false;
|
|
||||||
bool _isLoadingPrivacy = false;
|
bool _isLoadingPrivacy = false;
|
||||||
bool _isSavingPrivacy = false;
|
bool _isSavingPrivacy = false;
|
||||||
bool _privacyLoaded = false;
|
bool _privacyLoaded = false;
|
||||||
|
|
||||||
// Snapshot for cancel/reset
|
// Snapshot for cancel/reset
|
||||||
String _origProfileVisibility = 'public';
|
String _origProfileVisibility = 'public';
|
||||||
String _origContactInfo = 'connections';
|
|
||||||
String _origActivityStatus = 'public';
|
String _origActivityStatus = 'public';
|
||||||
bool _origShareAnalytics = false;
|
|
||||||
bool _origPersonalizedAds = false;
|
|
||||||
bool _origThirdPartySharing = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -45,26 +37,14 @@ class _PrivacyTabState extends ConsumerState<PrivacyTab> {
|
|||||||
final repo = ref.read(profileRepositoryProvider);
|
final repo = ref.read(profileRepositoryProvider);
|
||||||
final data = await repo.getPrivacyPreferences(role);
|
final data = await repo.getPrivacyPreferences(role);
|
||||||
final privacy = data['privacySettings'] as Map<String, dynamic>? ?? {};
|
final privacy = data['privacySettings'] as Map<String, dynamic>? ?? {};
|
||||||
final dataSettings =
|
|
||||||
data['dataSettings'] as Map<String, dynamic>? ?? {};
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_profileVisibility =
|
_profileVisibility =
|
||||||
privacy['profile_visibility'] as String? ?? 'public';
|
privacy['profile_visibility'] as String? ?? 'public';
|
||||||
_contactInfo = privacy['contact_info'] as String? ?? 'connections';
|
|
||||||
_activityStatus = privacy['activity_status'] as String? ?? 'public';
|
_activityStatus = privacy['activity_status'] as String? ?? 'public';
|
||||||
_shareAnalytics = dataSettings['shareAnalytics'] as bool? ?? false;
|
|
||||||
_personalizedAds = dataSettings['personalizedAds'] as bool? ?? false;
|
|
||||||
_thirdPartySharing =
|
|
||||||
dataSettings['thirdPartySharing'] as bool? ?? false;
|
|
||||||
_isLoadingPrivacy = false;
|
_isLoadingPrivacy = false;
|
||||||
_privacyLoaded = true;
|
_privacyLoaded = true;
|
||||||
// Save snapshot for cancel/reset
|
|
||||||
_origProfileVisibility = _profileVisibility;
|
_origProfileVisibility = _profileVisibility;
|
||||||
_origContactInfo = _contactInfo;
|
|
||||||
_origActivityStatus = _activityStatus;
|
_origActivityStatus = _activityStatus;
|
||||||
_origShareAnalytics = _shareAnalytics;
|
|
||||||
_origPersonalizedAds = _personalizedAds;
|
|
||||||
_origThirdPartySharing = _thirdPartySharing;
|
|
||||||
});
|
});
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
setState(() => _isLoadingPrivacy = false);
|
setState(() => _isLoadingPrivacy = false);
|
||||||
@@ -79,6 +59,8 @@ class _PrivacyTabState extends ConsumerState<PrivacyTab> {
|
|||||||
child: CircularProgressIndicator(color: AppColors.accentOrange));
|
child: CircularProgressIndicator(color: AppColors.accentOrange));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final isAgent = ref.read(profileProvider).role == 'AGENT';
|
||||||
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -89,32 +71,23 @@ class _PrivacyTabState extends ConsumerState<PrivacyTab> {
|
|||||||
subtitle: 'Control your privacy and visibility preferences',
|
subtitle: 'Control your privacy and visibility preferences',
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
ProfileDropdownRow(
|
// Profile Visibility — agent only
|
||||||
label: 'Profile Visibility',
|
if (isAgent) ...[
|
||||||
description: 'Control who can see your profile',
|
ProfileDropdownRow(
|
||||||
value: _profileVisibility,
|
label: 'Profile Visibility',
|
||||||
options: const {
|
description: 'Control who can see your profile',
|
||||||
'public': 'Public',
|
value: _profileVisibility,
|
||||||
'connections': 'Connections Only',
|
options: const {
|
||||||
'private': 'Private',
|
'public': 'Public',
|
||||||
},
|
'connections': 'Connections Only',
|
||||||
onChanged: (v) =>
|
'private': 'Private',
|
||||||
setState(() => _profileVisibility = v ?? _profileVisibility),
|
},
|
||||||
),
|
onChanged: (v) =>
|
||||||
const Divider(height: 24, color: Color(0xFFE8E8E8)),
|
setState(() => _profileVisibility = v ?? _profileVisibility),
|
||||||
ProfileDropdownRow(
|
),
|
||||||
label: 'Contact Information',
|
const Divider(height: 24, color: Color(0xFFE8E8E8)),
|
||||||
description: 'Control who can see your contact details',
|
],
|
||||||
value: _contactInfo,
|
// Activity Status — both agent and user
|
||||||
options: const {
|
|
||||||
'public': 'Public',
|
|
||||||
'connections': 'Connections Only',
|
|
||||||
'private': 'Hidden',
|
|
||||||
},
|
|
||||||
onChanged: (v) =>
|
|
||||||
setState(() => _contactInfo = v ?? _contactInfo),
|
|
||||||
),
|
|
||||||
const Divider(height: 24, color: Color(0xFFE8E8E8)),
|
|
||||||
ProfileDropdownRow(
|
ProfileDropdownRow(
|
||||||
label: 'Activity Status',
|
label: 'Activity Status',
|
||||||
description: 'Show when you are active on the platform',
|
description: 'Show when you are active on the platform',
|
||||||
@@ -131,86 +104,37 @@ class _PrivacyTabState extends ConsumerState<PrivacyTab> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
ProfileSectionCard(
|
|
||||||
title: 'Data & Personalization',
|
|
||||||
subtitle: 'Manage how your data is used',
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
ProfileToggleRow(
|
|
||||||
label: 'Share Analytics',
|
|
||||||
description:
|
|
||||||
'Help improve our service by sharing usage data',
|
|
||||||
value: _shareAnalytics,
|
|
||||||
onChanged: (v) => setState(() => _shareAnalytics = v),
|
|
||||||
),
|
|
||||||
const Divider(height: 24, color: Color(0xFFE8E8E8)),
|
|
||||||
ProfileToggleRow(
|
|
||||||
label: 'Personalized Ads',
|
|
||||||
description: 'See ads tailored to your interests',
|
|
||||||
value: _personalizedAds,
|
|
||||||
onChanged: (v) => setState(() => _personalizedAds = v),
|
|
||||||
),
|
|
||||||
const Divider(height: 24, color: Color(0xFFE8E8E8)),
|
|
||||||
ProfileToggleRow(
|
|
||||||
label: 'Third-Party Data Sharing',
|
|
||||||
description:
|
|
||||||
'Allow sharing data with third-party partners',
|
|
||||||
value: _thirdPartySharing,
|
|
||||||
onChanged: (v) => setState(() => _thirdPartySharing = v),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
ProfileActionButtons(
|
ProfileActionButtons(
|
||||||
onSave: _savePrivacyPreferences,
|
onSave: _savePrivacyPreferences,
|
||||||
onCancel: () {
|
onCancel: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_profileVisibility = _origProfileVisibility;
|
_profileVisibility = _origProfileVisibility;
|
||||||
_contactInfo = _origContactInfo;
|
|
||||||
_activityStatus = _origActivityStatus;
|
_activityStatus = _origActivityStatus;
|
||||||
_shareAnalytics = _origShareAnalytics;
|
|
||||||
_personalizedAds = _origPersonalizedAds;
|
|
||||||
_thirdPartySharing = _origThirdPartySharing;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
isSaving: _isSavingPrivacy),
|
isSaving: _isSavingPrivacy),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
|
// Delete Account
|
||||||
ProfileSectionCard(
|
ProfileSectionCard(
|
||||||
title: 'Danger Zone',
|
title: 'Delete Account',
|
||||||
subtitle: 'Irreversible and destructive actions',
|
subtitle: 'Permanently delete your account and all data',
|
||||||
borderColor: Colors.red.withValues(alpha: 0.3),
|
child: SizedBox(
|
||||||
titleColor: Colors.red,
|
width: double.infinity,
|
||||||
child: Column(
|
child: OutlinedButton(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
onPressed: _deleteAccount,
|
||||||
children: [
|
style: OutlinedButton.styleFrom(
|
||||||
const Text(
|
foregroundColor: Colors.red,
|
||||||
'Once you delete your account, there is no going back. All your data will be permanently removed.',
|
side: const BorderSide(color: Colors.red, width: 1.5),
|
||||||
style: TextStyle(
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||||
fontFamily: 'SourceSerif4',
|
shape: RoundedRectangleBorder(
|
||||||
fontSize: 13,
|
borderRadius: BorderRadius.circular(15)),
|
||||||
color: AppColors.hintText),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
child: const Text('Delete Account',
|
||||||
SizedBox(
|
style: TextStyle(
|
||||||
width: double.infinity,
|
fontFamily: 'Fractul',
|
||||||
child: OutlinedButton(
|
fontSize: 14,
|
||||||
onPressed: _deleteAccount,
|
fontWeight: FontWeight.w700)),
|
||||||
style: OutlinedButton.styleFrom(
|
),
|
||||||
foregroundColor: Colors.red,
|
|
||||||
side: const BorderSide(color: Colors.red, width: 1.5),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(15)),
|
|
||||||
),
|
|
||||||
child: const Text('Delete Account',
|
|
||||||
style: TextStyle(
|
|
||||||
fontFamily: 'Fractul',
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w700)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
@@ -227,14 +151,8 @@ class _PrivacyTabState extends ConsumerState<PrivacyTab> {
|
|||||||
await repo.updatePrivacyPreferences(role, {
|
await repo.updatePrivacyPreferences(role, {
|
||||||
'privacySettings': {
|
'privacySettings': {
|
||||||
'profile_visibility': _profileVisibility,
|
'profile_visibility': _profileVisibility,
|
||||||
'contact_info': _contactInfo,
|
|
||||||
'activity_status': _activityStatus,
|
'activity_status': _activityStatus,
|
||||||
},
|
},
|
||||||
'dataSettings': {
|
|
||||||
'shareAnalytics': _shareAnalytics,
|
|
||||||
'personalizedAds': _personalizedAds,
|
|
||||||
'thirdPartySharing': _thirdPartySharing,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
_showSnackBar('Privacy settings saved');
|
_showSnackBar('Privacy settings saved');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user