@oxyhq/services
Version:
Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀
308 lines (307 loc) • 9.67 kB
JavaScript
"use strict";
import React from 'react';
import { View, Text, StyleSheet, ActivityIndicator, ScrollView, Alert, Platform } from 'react-native';
import { useOxy } from '../context/OxyContext';
import { packageInfo } from '../../constants/version';
import { toast } from '../../lib/sonner';
import { fontFamilies } from '../styles/fonts';
import { ProfileCard, Section, QuickActions, GroupedSection, GroupedItem } from '../components';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const AccountCenterScreen = ({
onClose,
theme,
navigate
}) => {
const {
user,
logout,
isLoading,
sessions
} = useOxy();
const isDarkTheme = theme === 'dark';
const textColor = isDarkTheme ? '#FFFFFF' : '#000000';
const backgroundColor = isDarkTheme ? '#121212' : '#f2f2f2';
const secondaryBackgroundColor = isDarkTheme ? '#222222' : '#FFFFFF';
const borderColor = isDarkTheme ? '#444444' : '#E0E0E0';
const primaryColor = '#0066CC';
const dangerColor = '#D32F2F';
const handleLogout = async () => {
try {
await logout();
if (onClose) {
onClose();
}
} catch (error) {
console.error('Logout failed:', error);
toast.error('There was a problem signing you out. Please try again.');
}
};
const confirmLogout = () => {
Alert.alert('Sign Out', 'Are you sure you want to sign out?', [{
text: 'Cancel',
style: 'cancel'
}, {
text: 'Sign Out',
onPress: handleLogout,
style: 'destructive'
}], {
cancelable: true
});
};
if (!user) {
return /*#__PURE__*/_jsx(View, {
style: [styles.container, {
backgroundColor
}],
children: /*#__PURE__*/_jsx(Text, {
style: [styles.message, {
color: textColor
}],
children: "Not signed in"
})
});
}
if (isLoading) {
return /*#__PURE__*/_jsx(View, {
style: [styles.container, {
backgroundColor,
justifyContent: 'center'
}],
children: /*#__PURE__*/_jsx(ActivityIndicator, {
size: "large",
color: primaryColor
})
});
}
return /*#__PURE__*/_jsxs(View, {
style: [styles.container, {
backgroundColor
}],
children: [/*#__PURE__*/_jsx(ProfileCard, {
user: user,
theme: theme,
onEditPress: () => navigate('AccountSettings', {
activeTab: 'profile'
}),
onClosePress: onClose,
showCloseButton: !!onClose
}), /*#__PURE__*/_jsxs(ScrollView, {
style: styles.scrollView,
contentContainerStyle: styles.scrollContainer,
showsVerticalScrollIndicator: false,
children: [/*#__PURE__*/_jsx(Section, {
title: "Quick Actions",
theme: theme,
isFirst: true,
children: /*#__PURE__*/_jsx(QuickActions, {
actions: [{
id: 'overview',
icon: 'person-circle',
iconColor: '#007AFF',
title: 'Overview',
onPress: () => navigate('AccountOverview')
}, {
id: 'settings',
icon: 'settings',
iconColor: '#5856D6',
title: 'Settings',
onPress: () => navigate('AccountSettings')
}, {
id: 'sessions',
icon: 'shield-checkmark',
iconColor: '#30D158',
title: 'Sessions',
onPress: () => navigate('SessionManagement')
}, {
id: 'premium',
icon: 'star',
iconColor: '#FFD700',
title: 'Premium',
onPress: () => navigate('PremiumSubscription')
}, ...(user?.isPremium ? [{
id: 'billing',
icon: 'card',
iconColor: '#34C759',
title: 'Billing',
onPress: () => navigate('BillingManagement')
}] : []), ...(sessions && sessions.length > 1 ? [{
id: 'switch',
icon: 'swap-horizontal',
iconColor: '#FF9500',
title: 'Switch',
onPress: () => navigate('AccountSwitcher')
}] : [])],
theme: theme
})
}), /*#__PURE__*/_jsx(Section, {
title: "Account Management",
theme: theme,
children: /*#__PURE__*/_jsx(GroupedSection, {
items: [{
id: 'overview',
icon: 'person-circle',
iconColor: '#007AFF',
title: 'Account Overview',
subtitle: 'Complete account information',
onPress: () => navigate('AccountOverview')
}, {
id: 'settings',
icon: 'settings',
iconColor: '#5856D6',
title: 'Account Settings',
subtitle: 'Manage your preferences',
onPress: () => navigate('AccountSettings')
}, {
id: 'sessions',
icon: 'shield-checkmark',
iconColor: '#30D158',
title: 'Manage Sessions',
subtitle: 'Security and active devices',
onPress: () => navigate('SessionManagement')
}, {
id: 'files',
icon: 'folder',
iconColor: '#FF9500',
title: 'File Management',
subtitle: 'Upload, download, and manage your files',
onPress: () => navigate('FileManagement')
}, {
id: 'premium',
icon: 'star',
iconColor: '#FFD700',
title: 'Oxy+ Subscriptions',
subtitle: user?.isPremium ? 'Manage your premium plan' : 'Upgrade to premium features',
onPress: () => navigate('PremiumSubscription')
}, ...(user?.isPremium ? [{
id: 'billing',
icon: 'card',
iconColor: '#34C759',
title: 'Billing Management',
subtitle: 'Payment methods and invoices',
onPress: () => navigate('BillingManagement')
}] : [])],
theme: theme
})
}), sessions && sessions.length > 1 && /*#__PURE__*/_jsx(Section, {
title: "Multi-Account",
theme: theme,
children: /*#__PURE__*/_jsx(GroupedSection, {
items: [{
id: 'switch',
icon: 'people',
iconColor: '#FF9500',
title: 'Switch Account',
subtitle: `${sessions.length} accounts available`,
onPress: () => navigate('AccountSwitcher')
}, {
id: 'add',
icon: 'person-add',
iconColor: '#30D158',
title: 'Add Another Account',
subtitle: 'Sign in with a different account',
onPress: () => navigate('SignIn')
}],
theme: theme
})
}), (!sessions || sessions.length <= 1) && /*#__PURE__*/_jsx(Section, {
title: "Add Account",
theme: theme,
children: /*#__PURE__*/_jsx(GroupedSection, {
items: [{
id: 'add',
icon: 'person-add',
iconColor: '#30D158',
title: 'Add Another Account',
subtitle: 'Sign in with a different account',
onPress: () => navigate('SignIn')
}],
theme: theme
})
}), /*#__PURE__*/_jsx(Section, {
title: "More Options",
theme: theme,
children: /*#__PURE__*/_jsx(GroupedSection, {
items: [...(Platform.OS !== 'web' ? [{
id: 'notifications',
icon: 'notifications',
iconColor: '#FF9500',
title: 'Notifications',
subtitle: 'Manage notification settings',
onPress: () => toast.info('Notifications feature coming soon!')
}] : []), {
id: 'help',
icon: 'help-circle',
iconColor: '#007AFF',
title: 'Help & Support',
subtitle: 'Get help and contact support',
onPress: () => toast.info('Help & Support feature coming soon!')
}, {
id: 'appinfo',
icon: 'information-circle',
iconColor: '#8E8E93',
title: 'App Information',
subtitle: 'Version and system details',
onPress: () => navigate('AppInfo')
}],
theme: theme
})
}), /*#__PURE__*/_jsx(Section, {
theme: theme,
children: /*#__PURE__*/_jsx(GroupedItem, {
icon: "log-out",
iconColor: dangerColor,
title: isLoading ? "Signing out..." : "Sign Out",
theme: theme,
onPress: confirmLogout,
isFirst: true,
isLast: true,
showChevron: false,
disabled: isLoading,
customContent: isLoading ? /*#__PURE__*/_jsx(ActivityIndicator, {
color: dangerColor,
size: "small",
style: {
marginRight: 16
}
}) : null
})
}), /*#__PURE__*/_jsx(View, {
style: styles.versionContainer,
children: /*#__PURE__*/_jsxs(Text, {
style: [styles.versionText, {
color: isDarkTheme ? '#666666' : '#999999'
}],
children: ["Version ", packageInfo.version]
})
})]
})]
});
};
const styles = StyleSheet.create({
container: {
flex: 1
},
scrollView: {
flex: 1
},
scrollContainer: {
padding: 16,
paddingBottom: 20
},
versionContainer: {
alignItems: 'center',
marginTop: 20,
marginBottom: 20
},
versionText: {
fontSize: 12,
fontFamily: fontFamilies.phudu
},
message: {
fontSize: 16,
textAlign: 'center',
marginTop: 24
}
});
export default AccountCenterScreen;
//# sourceMappingURL=AccountCenterScreen.js.map