tooot/src/screens/Tabs/Me/Root/Logout.tsx

57 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-12-30 14:33:33 +01:00
import Button from '@components/Button'
import haptics from '@root/components/haptics'
2022-04-30 23:47:52 +02:00
import { useAppDispatch } from '@root/store'
2021-02-20 19:12:44 +01:00
import removeInstance from '@utils/slices/instances/remove'
2021-03-01 01:27:26 +01:00
import { getInstance } from '@utils/slices/instancesSlice'
2020-12-30 14:33:33 +01:00
import { StyleConstants } from '@utils/styles/constants'
import React from 'react'
2020-11-29 18:08:31 +01:00
import { useTranslation } from 'react-i18next'
2020-12-26 23:05:17 +01:00
import { Alert } from 'react-native'
import { useQueryClient } from '@tanstack/react-query'
2022-04-30 23:47:52 +02:00
import { useSelector } from 'react-redux'
2020-11-24 00:18:47 +01:00
const Logout: React.FC = () => {
2022-12-23 15:53:40 +01:00
const { t } = useTranslation(['common', 'screenTabs'])
2022-04-30 23:47:52 +02:00
const dispatch = useAppDispatch()
2020-12-18 23:58:53 +01:00
const queryClient = useQueryClient()
2021-03-01 00:28:14 +01:00
const instance = useSelector(getInstance)
2020-11-24 00:18:47 +01:00
return (
2020-12-26 23:05:17 +01:00
<Button
type='text'
2022-12-23 15:53:40 +01:00
content={t('screenTabs:me.root.logout.button')}
2020-12-26 23:05:17 +01:00
style={{
marginHorizontal: StyleConstants.Spacing.Global.PagePadding * 2,
2022-02-19 17:15:44 +01:00
marginTop: StyleConstants.Spacing.Global.PagePadding,
marginBottom: StyleConstants.Spacing.Global.PagePadding * 2
2020-12-26 23:05:17 +01:00
}}
destructive
onPress={() =>
2022-12-23 15:53:40 +01:00
Alert.alert(
t('screenTabs:me.root.logout.alert.title'),
t('screenTabs:me.root.logout.alert.message'),
[
{
text: t('screenTabs:me.root.logout.alert.buttons.logout'),
style: 'destructive',
onPress: () => {
if (instance) {
haptics('Success')
queryClient.clear()
dispatch(removeInstance(instance))
}
2020-12-26 23:05:17 +01:00
}
2022-12-23 15:53:40 +01:00
},
{
text: t('common:buttons.cancel'),
style: 'default'
2020-12-26 23:05:17 +01:00
}
2022-12-23 15:53:40 +01:00
]
)
2020-12-26 23:05:17 +01:00
}
/>
2020-11-24 00:18:47 +01:00
)
}
export default Logout