-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcomponent.tsx
More file actions
96 lines (85 loc) · 3 KB
/
Copy pathcomponent.tsx
File metadata and controls
96 lines (85 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { BottomSheetModal } from '@gorhom/bottom-sheet';
import { useTranslation } from '@ronas-it/react-native-common-modules/i18n';
import { ReactElement, useRef } from 'react';
import { Alert } from 'react-native';
import { useLogout } from '@open-webui-react-native/mobile/shared/features/use-logout';
import {
Avatar,
AppBottomSheetProps,
ActionsBottomSheet,
ActionSheetItemProps,
AppPressable,
} from '@open-webui-react-native/mobile/shared/ui/ui-kit';
import { authApi } from '@open-webui-react-native/shared/data-access/api';
import { FeatureID, isFeatureEnabled } from '@open-webui-react-native/shared/utils/feature-flag';
import { ToastService } from '@open-webui-react-native/shared/utils/toast-service';
interface ProfileMenuSheetProps extends Pick<AppBottomSheetProps, 'renderTrigger'> {
onArchivedChatsPress: () => void;
}
export function ProfileMenuSheet({ onArchivedChatsPress, ...restProps }: ProfileMenuSheetProps): ReactElement {
const translate = useTranslation('PROFILE.PROFILE_MENU_SHEET');
const { logout, isLoading } = useLogout();
const { data: profile } = authApi.useGetProfile();
const actionsBottomSheetRef = useRef<BottomSheetModal>(null);
const closeActionsSheet = (): Promise<void> =>
new Promise((resolve) => {
actionsBottomSheetRef.current?.close();
setTimeout(() => resolve(), 250);
});
const handleArchivedChatsPress = async (): Promise<void> => {
await closeActionsSheet();
onArchivedChatsPress();
};
const handleDeleteAccountPress = (): void => {
ToastService.show(translate('TEXT_ACCOUNT_DELETION_REQUEST'));
};
const handleRequestDeleteAccountPress = async (): Promise<void> => {
await closeActionsSheet();
Alert.alert(
translate('TEXT_DELETE_ACCOUNT_TITLE'),
translate('TEXT_DELETE_ACCOUNT_MESSAGE'),
[
{ text: translate('BUTTON_DELETE_ACCOUNT'), style: 'destructive', onPress: handleDeleteAccountPress },
{ text: translate('BUTTON_DONT_DELETE'), style: 'cancel' },
],
{
userInterfaceStyle: 'dark',
},
);
};
const actions: Array<ActionSheetItemProps> = [
{
title: translate('TEXT_ARCHIVED_CHATS'),
iconName: 'archive',
onPress: isFeatureEnabled(FeatureID.ARCHIVE_CHAT)
? handleArchivedChatsPress
: ToastService.showFeatureNotImplemented,
},
{
title: translate('TEXT_DELETE_ACCOUNT'),
iconName: 'trashCan',
onPress: handleRequestDeleteAccountPress,
isDanger: true,
},
{
title: translate('TEXT_LOGOUT'),
iconName: 'logout',
onPress: logout,
isLoading,
disabled: isLoading,
isDanger: true,
},
];
const renderTrigger = ({ onPress }: { onPress: () => void }): ReactElement => (
<AppPressable onPress={onPress}>
<Avatar source={{ uri: profile?.profileImageUrl }} />
</AppPressable>
);
return (
<ActionsBottomSheet
ref={actionsBottomSheetRef}
renderTrigger={renderTrigger}
actions={actions}
{...restProps} />
);
}