import React from 'react'; import { Avatar, BottomSheetItem, Box, PressBox, TextInput, createStyleSheet, useBottomSheet, useToast, useUIKitTheme, } from '@sendbird/uikit-react-native-foundation'; import { Icon } from '@sendbird/uikit-react-native-foundation'; import { ifThenOr, useSafeAreaPadding } from '@sendbird/uikit-utils'; import { useLocalization, usePlatformService } from '../../../hooks/useContext'; import SBUError from '../../../libs/SBUError'; import SBUUtils from '../../../libs/SBUUtils'; import type { OpenChannelCreateProps } from '../types'; const OpenChannelCreateProfileInput = ({ channelName, channelCoverFile, onChangeChannelName, onChangeChannelCoverFile, }: OpenChannelCreateProps['ProfileInput']) => { const toast = useToast(); const { openSheet } = useBottomSheet(); const { palette, colors, typography } = useUIKitTheme(); const safeArea = useSafeAreaPadding(['left', 'right']); const { STRINGS } = useLocalization(); const { fileService } = usePlatformService(); const onPressPhotoButton = () => { const sheetItems: BottomSheetItem['sheetItems'] = [ { title: STRINGS.OPEN_CHANNEL_CREATE.DIALOG_IMAGE_MENU_CAMERA, onPress: async () => { const mediaFile = await fileService.openCamera({ mediaType: 'photo', onOpenFailure: (error) => { if (error.code === SBUError.CODE.ERR_PERMISSIONS_DENIED) { alert({ title: STRINGS.DIALOG.ALERT_PERMISSIONS_TITLE, message: STRINGS.DIALOG.ALERT_PERMISSIONS_MESSAGE( STRINGS.LABELS.PERMISSION_CAMERA, STRINGS.LABELS.PERMISSION_APP_NAME, ), buttons: [{ text: STRINGS.DIALOG.ALERT_PERMISSIONS_OK, onPress: () => SBUUtils.openSettings() }], }); } else { toast.show(STRINGS.TOAST.OPEN_CAMERA_ERROR, 'error'); } }, }); if (mediaFile) onChangeChannelCoverFile(mediaFile); }, }, { title: STRINGS.OPEN_CHANNEL_CREATE.DIALOG_IMAGE_MENU_PHOTO_LIBRARY, onPress: async () => { const mediaFiles = await fileService.openMediaLibrary({ selectionLimit: 1, mediaType: 'photo', onOpenFailure: (error) => { if (error.code === SBUError.CODE.ERR_PERMISSIONS_DENIED) { alert({ title: STRINGS.DIALOG.ALERT_PERMISSIONS_TITLE, message: STRINGS.DIALOG.ALERT_PERMISSIONS_MESSAGE( STRINGS.LABELS.PERMISSION_DEVICE_STORAGE, STRINGS.LABELS.PERMISSION_APP_NAME, ), buttons: [{ text: STRINGS.DIALOG.ALERT_PERMISSIONS_OK, onPress: () => SBUUtils.openSettings() }], }); } else { toast.show(STRINGS.TOAST.OPEN_PHOTO_LIBRARY_ERROR, 'error'); } }, }); if (mediaFiles?.[0]) onChangeChannelCoverFile(mediaFiles[0]); }, }, ]; if (channelCoverFile) { sheetItems.unshift({ title: STRINGS.OPEN_CHANNEL_CREATE.DIALOG_IMAGE_MENU_REMOVE, titleColor: colors.error, onPress: () => { onChangeChannelCoverFile(undefined); }, }); } openSheet({ sheetItems }); }; return ( {ifThenOr( Boolean(channelCoverFile), , , )} {channelName.length > 0 && ( onChangeChannelName('')} style={styles.removeButtonContainer}> )} ); }; const styles = createStyleSheet({ coverButton: { marginEnd: 20, }, inputContainer: { flex: 1, flexDirection: 'row', alignItems: 'center', borderBottomWidth: 1, }, input: { flex: 1, paddingStart: 0, paddingEnd: 0, paddingTop: 0, paddingBottom: 0, }, removeButtonContainer: { alignItems: 'flex-end', justifyContent: 'center', marginStart: 8, }, }); export default OpenChannelCreateProfileInput;