tooot/src/screens/Tabs/Me/Profile/Root/AvatarHeader.tsx

67 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-05-17 23:09:50 +02:00
import mediaSelector from '@components/mediaSelector'
import { MenuRow } from '@components/Menu'
2022-07-09 11:29:47 +02:00
import { displayMessage } from '@components/Message'
2021-05-17 23:09:50 +02:00
import { useActionSheet } from '@expo/react-native-action-sheet'
import { useProfileMutation, useProfileQuery } from '@utils/queryHooks/profile'
import { useTheme } from '@utils/styles/ThemeManager'
import React, { RefObject } from 'react'
import { useTranslation } from 'react-i18next'
import FlashMessage from 'react-native-flash-message'
export interface Props {
type: 'avatar' | 'header'
messageRef: RefObject<FlashMessage>
}
const ProfileAvatarHeader: React.FC<Props> = ({ type, messageRef }) => {
2022-02-12 14:51:01 +01:00
const { theme } = useTheme()
2021-05-17 23:09:50 +02:00
const { t } = useTranslation('screenTabs')
const { showActionSheetWithOptions } = useActionSheet()
const query = useProfileQuery({})
const mutation = useProfileMutation()
return (
<MenuRow
title={t(`me.profile.root.${type}.title`)}
description={t(`me.profile.root.${type}.description`)}
loading={query.isLoading || mutation.isLoading}
iconBack='ChevronRight'
onPress={async () => {
const image = await mediaSelector({
2022-06-05 17:58:18 +02:00
mediaType: 'photo',
maximum: 1,
2021-05-17 23:09:50 +02:00
showActionSheetWithOptions,
2022-06-05 17:58:18 +02:00
resize:
type === 'avatar'
? { width: 400, height: 400 }
: { width: 1500, height: 500 }
2021-05-17 23:09:50 +02:00
})
2022-07-09 11:29:47 +02:00
if (!image[0].uri) {
displayMessage({
ref: messageRef,
message: t('screenTabs:me.profile.mediaSelectionFailed'),
theme: theme,
type: 'error'
})
return
}
2021-05-26 23:30:15 +02:00
mutation.mutate({
2022-02-12 14:51:01 +01:00
theme,
2021-05-26 23:30:15 +02:00
messageRef,
message: {
text: `me.profile.root.${type}.title`,
succeed: true,
failed: true
},
type,
2022-06-09 21:33:10 +02:00
data: image[0].uri
2021-05-26 23:30:15 +02:00
})
2021-05-17 23:09:50 +02:00
}}
/>
)
}
export default ProfileAvatarHeader