@oxyhq/services
Version:
328 lines (325 loc) • 13.2 kB
JavaScript
"use strict";
import { View, Text, StyleSheet, ActivityIndicator, ScrollView, Platform } from 'react-native';
import { useCallback, useMemo } from 'react';
import { packageInfo } from '@oxyhq/core';
import { toast } from '../../lib/sonner';
import { confirmAction } from "../utils/confirmAction.js";
import { fontFamilies } from "../styles/fonts.js";
import ProfileCard from "../components/ProfileCard.js";
import Section from "../components/Section.js";
import QuickActions from "../components/QuickActions.js";
import GroupedSection from "../components/GroupedSection.js";
import GroupedItem from "../components/GroupedItem.js";
import { useI18n } from "../hooks/useI18n.js";
import { useThemeStyles } from "../hooks/useThemeStyles.js";
import { useColorScheme } from "../hooks/useColorScheme.js";
import { Colors } from "../constants/theme.js";
import { normalizeColorScheme, normalizeTheme } from "../utils/themeUtils.js";
import { useOxy } from "../context/OxyContext.js";
import { screenContentStyle } from "../constants/spacing.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const AccountCenterScreen = ({
onClose,
theme,
navigate
}) => {
// Use useOxy() hook for OxyContext values
const {
user,
logout,
isLoading,
sessions,
isAuthenticated
} = useOxy();
const {
t
} = useI18n();
const colorScheme = useColorScheme();
const normalizedTheme = normalizeTheme(theme);
const themeStyles = useThemeStyles(normalizedTheme, colorScheme);
// AccountCenterScreen uses a slightly different light background
const backgroundColor = themeStyles.isDarkTheme ? themeStyles.backgroundColor : '#f2f2f2';
// Extract commonly used colors for readability - ensure colors is always defined
const {
textColor,
secondaryBackgroundColor,
borderColor,
primaryColor,
dangerColor,
colors: themeColors
} = themeStyles;
const colors = themeColors || Colors[normalizeColorScheme(colorScheme, normalizedTheme)];
// Memoized logout handler - prevents unnecessary re-renders
const handleLogout = useCallback(async () => {
try {
await logout();
if (onClose) {
onClose();
}
} catch (error) {
if (__DEV__) {
console.error('Logout failed:', error);
}
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 = useCallback(() => {
confirmAction(t('common.confirms.signOut') || 'Are you sure you want to sign out?', handleLogout);
}, [handleLogout, t]);
if (!isAuthenticated) {
return /*#__PURE__*/_jsx(View, {
style: [styles.container, {
backgroundColor
}],
children: /*#__PURE__*/_jsx(Text, {
style: [styles.message, {
color: textColor
}],
children: t('common.status.notSignedIn') || '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: [user && /*#__PURE__*/_jsx(ProfileCard, {
user: user,
theme: normalizedTheme,
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: t('accountCenter.sections.quickActions') || 'Quick Actions',
isFirst: true,
children: /*#__PURE__*/_jsx(QuickActions, {
theme: normalizedTheme,
actions: useMemo(() => [{
id: 'overview',
icon: 'account-circle',
iconColor: colors.iconSecurity,
title: t('accountCenter.quickActions.overview') || 'Overview',
onPress: () => navigate?.('AccountOverview')
}, {
id: 'settings',
icon: 'cog',
iconColor: colors.iconData,
title: t('accountCenter.quickActions.editProfile') || 'Edit Profile',
onPress: () => navigate?.('AccountSettings')
}, {
id: 'sessions',
icon: 'shield-check',
iconColor: colors.iconSecurity,
title: t('accountCenter.quickActions.sessions') || 'Sessions',
onPress: () => navigate?.('SessionManagement')
}, {
id: 'premium',
icon: 'star',
iconColor: colors.iconPayments,
title: t('accountCenter.quickActions.premium') || 'Premium',
onPress: () => navigate?.('PremiumSubscription')
}, ...(user?.isPremium ? [{
id: 'billing',
icon: 'card',
iconColor: colors.iconPersonalInfo,
title: t('accountCenter.quickActions.billing') || 'Billing',
onPress: () => navigate?.('PaymentGateway')
}] : []), ...(sessions && sessions.length > 1 ? [{
id: 'switch',
icon: 'swap-horizontal',
iconColor: colors.iconStorage,
title: t('accountCenter.quickActions.switch') || 'Switch',
onPress: () => navigate?.('AccountSwitcher')
}] : [])], [user?.isPremium, sessions, navigate, t, colors])
})
}), /*#__PURE__*/_jsx(Section, {
title: t('accountCenter.sections.accountManagement') || 'Account Management',
children: /*#__PURE__*/_jsx(GroupedSection, {
items: useMemo(() => [{
id: 'overview',
icon: 'account-circle',
iconColor: colors.iconSecurity,
title: t('accountCenter.items.accountOverview.title') || 'Account Overview',
subtitle: t('accountCenter.items.accountOverview.subtitle') || 'Complete account information',
onPress: () => navigate?.('AccountOverview')
}, {
id: 'settings',
icon: 'cog',
iconColor: colors.iconData,
title: t('accountCenter.items.editProfile.title') || 'Edit Profile',
subtitle: t('accountCenter.items.editProfile.subtitle') || 'Manage your profile and preferences',
onPress: () => navigate?.('AccountSettings')
}, {
id: 'sessions',
icon: 'shield-check',
iconColor: colors.iconSecurity,
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: colors.iconStorage,
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: colors.iconPayments,
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: colors.iconPersonalInfo,
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, colors])
})
}), sessions && sessions.length > 1 && /*#__PURE__*/_jsx(Section, {
title: t('accountCenter.sections.multiAccount') || 'Multi-Account',
children: /*#__PURE__*/_jsx(GroupedSection, {
items: useMemo(() => [{
id: 'switch',
icon: 'account-group',
iconColor: colors.iconStorage,
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: 'account-plus',
iconColor: colors.iconPersonalInfo,
title: t('accountCenter.items.addAccount.title') || 'Add Another Account',
subtitle: t('accountCenter.items.addAccount.subtitle') || 'Sign in with a different account',
onPress: () => navigate?.('OxyAuth')
}], [sessions.length, navigate, t, colors])
})
}), (!sessions || sessions.length <= 1) && /*#__PURE__*/_jsx(Section, {
title: t('accountCenter.sections.addAccount') || 'Add Account',
children: /*#__PURE__*/_jsx(GroupedSection, {
items: useMemo(() => [{
id: 'add',
icon: 'account-plus',
iconColor: colors.iconPersonalInfo,
title: t('accountCenter.items.addAccount.title') || 'Add Another Account',
subtitle: t('accountCenter.items.addAccount.subtitle') || 'Sign in with a different account',
onPress: () => navigate?.('OxyAuth')
}], [navigate, t, colors])
})
}), /*#__PURE__*/_jsx(Section, {
title: t('accountCenter.sections.moreOptions') || 'More Options',
children: /*#__PURE__*/_jsx(GroupedSection, {
items: useMemo(() => [...(Platform.OS !== 'web' ? [{
id: 'notifications',
icon: 'bell',
iconColor: colors.iconStorage,
title: t('accountCenter.items.notifications.title') || 'Notifications',
subtitle: t('accountCenter.items.notifications.subtitle') || 'Manage notification settings',
onPress: () => navigate?.('AccountSettings', {
activeTab: 'notifications'
})
}] : []), {
id: 'language',
icon: 'translate',
iconColor: colors.iconPersonalInfo,
title: t('language.title') || 'Language',
subtitle: t('language.subtitle') || 'Choose your preferred language',
onPress: () => navigate?.('LanguageSelector')
}, {
id: 'help',
icon: 'help-circle',
iconColor: colors.iconSecurity,
title: t('accountOverview.items.help.title') || 'Help & Support',
subtitle: t('accountOverview.items.help.subtitle') || 'Get help and contact support',
onPress: () => navigate?.('HelpSupport')
}, {
id: 'appinfo',
icon: 'information',
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, colors, Platform.OS])
})
}), /*#__PURE__*/_jsx(Section, {
children: /*#__PURE__*/_jsx(GroupedItem, {
icon: "logout",
iconColor: dangerColor,
title: isLoading ? t('accountCenter.signingOut') || 'Signing out...' : t('common.actions.signOut') || 'Sign Out',
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__*/_jsx(Text, {
style: [styles.versionText, {
color: themeStyles.isDarkTheme ? '#666666' : '#999999'
}],
children: t('accountCenter.version', {
version: packageInfo.version
}) || `Version ${packageInfo.version}`
})
})]
})]
});
};
const styles = StyleSheet.create({
container: {
flex: 1
},
scrollView: {
flex: 1
},
scrollContainer: screenContentStyle,
versionContainer: {
alignItems: 'center',
marginTop: 20,
marginBottom: 20
},
versionText: {
fontSize: 12,
fontFamily: fontFamilies.inter
},
message: {
fontSize: 16,
textAlign: 'center',
marginTop: 24
}
});
export default AccountCenterScreen;
//# sourceMappingURL=AccountCenterScreen.js.map