UNPKG

@oxyhq/services

Version:

Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀

329 lines (326 loc) • 13.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _reactNative = require("react-native"); var _react = require("react"); var _OxyContext = require("../context/OxyContext"); var _version = require("../../constants/version"); var _sonner = require("../../lib/sonner"); var _confirmAction = require("../utils/confirmAction"); var _fonts = require("../styles/fonts"); var _ProfileCard = _interopRequireDefault(require("../components/ProfileCard")); var _Section = _interopRequireDefault(require("../components/Section")); var _QuickActions = _interopRequireDefault(require("../components/QuickActions")); var _GroupedSection = _interopRequireDefault(require("../components/GroupedSection")); var _GroupedItem = _interopRequireDefault(require("../components/GroupedItem")); var _useI18n = require("../hooks/useI18n"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const AccountCenterScreen = ({ onClose, theme, navigate }) => { const { user, logout, isLoading, sessions, isAuthenticated } = (0, _OxyContext.useOxy)(); const { t } = (0, _useI18n.useI18n)(); 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'; // Memoized logout handler - prevents unnecessary re-renders const handleLogout = (0, _react.useCallback)(async () => { try { await logout(); if (onClose) { onClose(); } } catch (error) { console.error('Logout failed:', error); _sonner.toast.error(t('common.errors.signOutFailed') || 'There was a problem signing you out. Please try again.'); } }, [logout, onClose, t]); // Memoized confirm logout handler - prevents unnecessary re-renders const confirmLogout = (0, _react.useCallback)(() => { (0, _confirmAction.confirmAction)(t('common.confirms.signOut') || 'Are you sure you want to sign out?', handleLogout); }, [handleLogout, t]); if (!isAuthenticated) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.container, { backgroundColor }], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.message, { color: textColor }], children: t('common.status.notSignedIn') || 'Not signed in' }) }); } if (isLoading) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.container, { backgroundColor, justifyContent: 'center' }], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, { size: "large", color: primaryColor }) }); } return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.container, { backgroundColor }], children: [user && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ProfileCard.default, { user: user, theme: theme, onEditPress: () => navigate('EditProfile', { activeTab: 'profile' }), onClosePress: onClose, showCloseButton: !!onClose }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.ScrollView, { style: styles.scrollView, contentContainerStyle: styles.scrollContainer, showsVerticalScrollIndicator: false, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Section.default, { title: t('accountCenter.sections.quickActions') || 'Quick Actions', theme: theme, isFirst: true, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_QuickActions.default, { actions: (0, _react.useMemo)(() => [{ id: 'overview', icon: 'person-circle', iconColor: '#007AFF', title: t('accountCenter.quickActions.overview') || 'Overview', onPress: () => navigate('AccountOverview') }, { id: 'settings', icon: 'settings', iconColor: '#5856D6', title: t('accountCenter.quickActions.editProfile') || 'Edit Profile', onPress: () => navigate('EditProfile') }, { id: 'sessions', icon: 'shield-checkmark', iconColor: '#30D158', title: t('accountCenter.quickActions.sessions') || 'Sessions', onPress: () => navigate('SessionManagement') }, { id: 'premium', icon: 'star', iconColor: '#FFD700', title: t('accountCenter.quickActions.premium') || 'Premium', onPress: () => navigate('PremiumSubscription') }, ...(user?.isPremium ? [{ id: 'billing', icon: 'card', iconColor: '#34C759', title: t('accountCenter.quickActions.billing') || 'Billing', onPress: () => navigate('PaymentGateway') }] : []), ...(sessions && sessions.length > 1 ? [{ id: 'switch', icon: 'swap-horizontal', iconColor: '#FF9500', title: t('accountCenter.quickActions.switch') || 'Switch', onPress: () => navigate('AccountSwitcher') }] : [])], [user?.isPremium, sessions, navigate, t]), theme: theme }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Section.default, { title: t('accountCenter.sections.accountManagement') || 'Account Management', theme: theme, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_GroupedSection.default, { items: (0, _react.useMemo)(() => [{ id: 'overview', icon: 'person-circle', iconColor: '#007AFF', title: t('accountCenter.items.accountOverview.title') || 'Account Overview', subtitle: t('accountCenter.items.accountOverview.subtitle') || 'Complete account information', onPress: () => navigate('AccountOverview') }, { id: 'settings', icon: 'settings', iconColor: '#5856D6', title: t('accountCenter.items.editProfile.title') || 'Edit Profile', subtitle: t('accountCenter.items.editProfile.subtitle') || 'Manage your profile and preferences', onPress: () => navigate('EditProfile') }, { id: 'sessions', icon: 'shield-checkmark', iconColor: '#30D158', title: t('accountCenter.items.manageSessions.title') || 'Manage Sessions', subtitle: t('accountCenter.items.manageSessions.subtitle') || 'Security and active devices', onPress: () => navigate('SessionManagement') }, { id: 'files', icon: 'folder', iconColor: '#FF9500', title: t('accountCenter.items.fileManagement.title') || 'File Management', subtitle: t('accountCenter.items.fileManagement.subtitle') || 'Upload, download, and manage your files', onPress: () => navigate('FileManagement') }, { id: 'premium', icon: 'star', iconColor: '#FFD700', title: t('accountCenter.items.premium.title') || 'Oxy+ Subscriptions', subtitle: user?.isPremium ? t('accountCenter.items.premium.manage') || 'Manage your premium plan' : t('accountCenter.items.premium.upgrade') || 'Upgrade to premium features', onPress: () => navigate('PremiumSubscription') }, ...(user?.isPremium ? [{ id: 'billing', icon: 'card', iconColor: '#34C759', title: t('accountCenter.items.billing.title') || 'Billing Management', subtitle: t('accountCenter.items.billing.subtitle') || 'Payment methods and invoices', onPress: () => navigate('PaymentGateway') }] : [])], [user?.isPremium, navigate, t]), theme: theme }) }), sessions && sessions.length > 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Section.default, { title: t('accountCenter.sections.multiAccount') || 'Multi-Account', theme: theme, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_GroupedSection.default, { items: (0, _react.useMemo)(() => [{ id: 'switch', icon: 'people', iconColor: '#FF9500', title: t('accountCenter.items.switchAccount.title') || 'Switch Account', subtitle: t('accountCenter.items.switchAccount.subtitle', { count: sessions.length }) || `${sessions.length} accounts available`, onPress: () => navigate('AccountSwitcher') }, { id: 'add', icon: 'person-add', iconColor: '#30D158', title: t('accountCenter.items.addAccount.title') || 'Add Another Account', subtitle: t('accountCenter.items.addAccount.subtitle') || 'Sign in with a different account', onPress: () => navigate('SignIn') }], [sessions.length, navigate, t]), theme: theme }) }), (!sessions || sessions.length <= 1) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Section.default, { title: t('accountCenter.sections.addAccount') || 'Add Account', theme: theme, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_GroupedSection.default, { items: (0, _react.useMemo)(() => [{ id: 'add', icon: 'person-add', iconColor: '#30D158', title: t('accountCenter.items.addAccount.title') || 'Add Another Account', subtitle: t('accountCenter.items.addAccount.subtitle') || 'Sign in with a different account', onPress: () => navigate('SignIn') }], [navigate, t]), theme: theme }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Section.default, { title: t('accountCenter.sections.moreOptions') || 'More Options', theme: theme, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_GroupedSection.default, { items: (0, _react.useMemo)(() => [...(_reactNative.Platform.OS !== 'web' ? [{ id: 'notifications', icon: 'notifications', iconColor: '#FF9500', title: t('accountCenter.items.notifications.title') || 'Notifications', subtitle: t('accountCenter.items.notifications.subtitle') || 'Manage notification settings', onPress: () => _sonner.toast.info(t('accountCenter.items.notifications.coming') || 'Notifications feature coming soon!') }] : []), { id: 'language', icon: 'language', iconColor: '#32D74B', title: t('language.title') || 'Language', subtitle: t('language.subtitle') || 'Choose your preferred language', onPress: () => navigate('LanguageSelector') }, { id: 'help', icon: 'help-circle', iconColor: '#007AFF', title: t('accountOverview.items.help.title') || 'Help & Support', subtitle: t('accountOverview.items.help.subtitle') || 'Get help and contact support', onPress: () => _sonner.toast.info(t('accountOverview.items.help.coming') || 'Help & Support feature coming soon!') }, { id: 'appinfo', icon: 'information-circle', iconColor: '#8E8E93', title: t('accountCenter.items.appInfo.title') || 'App Information', subtitle: t('accountCenter.items.appInfo.subtitle') || 'Version and system details', onPress: () => navigate('AppInfo') }], [navigate, t]), theme: theme }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Section.default, { theme: theme, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_GroupedItem.default, { icon: "log-out", iconColor: dangerColor, title: isLoading ? t('accountCenter.signingOut') || 'Signing out...' : t('common.actions.signOut') || 'Sign Out', theme: theme, onPress: confirmLogout, isFirst: true, isLast: true, showChevron: false, disabled: isLoading, customContent: isLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, { color: dangerColor, size: "small", style: { marginRight: 16 } }) : null }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: styles.versionContainer, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.versionText, { color: isDarkTheme ? '#666666' : '#999999' }], children: t('accountCenter.version', { version: _version.packageInfo.version }) || `Version ${_version.packageInfo.version}` }) })] })] }); }; const styles = _reactNative.StyleSheet.create({ container: { flex: 1 }, scrollView: { flex: 1 }, scrollContainer: { padding: 16, paddingBottom: 20 }, versionContainer: { alignItems: 'center', marginTop: 20, marginBottom: 20 }, versionText: { fontSize: 12, fontFamily: _fonts.fontFamilies.phudu }, message: { fontSize: 16, textAlign: 'center', marginTop: 24 } }); var _default = exports.default = AccountCenterScreen; //# sourceMappingURL=AccountCenterScreen.js.map