2023-07-05 18:28:01 +00:00
|
|
|
import React, { useLayoutEffect } from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { Text, View } from 'react-native';
|
2023-07-05 18:28:01 +00:00
|
|
|
import { useNavigation } from '@react-navigation/native';
|
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
2021-12-03 19:27:57 +00:00
|
|
|
import { CompositeNavigationProp } from '@react-navigation/core';
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2021-12-03 19:27:57 +00:00
|
|
|
import { OutsideModalParamList, OutsideParamList } from '../../stacks/types';
|
2020-03-30 19:20:50 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import Button from '../../containers/Button';
|
2023-07-05 18:28:01 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2020-03-30 19:20:50 +00:00
|
|
|
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
|
2022-05-03 01:27:33 +00:00
|
|
|
import { IAssetsFavicon512 } from '../../definitions/IAssetsFavicon512';
|
2020-04-01 15:56:08 +00:00
|
|
|
import { getShowLoginButton } from '../../selectors/login';
|
2021-09-13 20:41:05 +00:00
|
|
|
import ServerAvatar from './ServerAvatar';
|
|
|
|
import styles from './styles';
|
2023-07-05 18:28:01 +00:00
|
|
|
import { useAppSelector } from '../../lib/hooks';
|
|
|
|
import RegisterDisabledComponent from './RegisterDisabledComponent';
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2023-07-05 18:28:01 +00:00
|
|
|
type TNavigation = CompositeNavigationProp<
|
|
|
|
StackNavigationProp<OutsideParamList, 'WorkspaceView'>,
|
|
|
|
StackNavigationProp<OutsideModalParamList>
|
|
|
|
>;
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2023-07-05 18:28:01 +00:00
|
|
|
const useWorkspaceViewSelector = () =>
|
|
|
|
useAppSelector(state => ({
|
|
|
|
server: state.server.server,
|
|
|
|
Site_Name: state.settings.Site_Name as string,
|
|
|
|
Site_Url: state.settings.Site_Url as string,
|
|
|
|
Assets_favicon_512: state.settings.Assets_favicon_512 as IAssetsFavicon512,
|
|
|
|
registrationForm: state.settings.Accounts_RegistrationForm as string,
|
|
|
|
Accounts_iframe_enabled: state.settings.Accounts_iframe_enabled as boolean,
|
|
|
|
showLoginButton: getShowLoginButton(state),
|
|
|
|
inviteLinkToken: state.inviteLinks.token
|
|
|
|
}));
|
2020-06-12 19:12:08 +00:00
|
|
|
|
2023-07-05 18:28:01 +00:00
|
|
|
const WorkspaceView = () => {
|
|
|
|
const navigation = useNavigation<TNavigation>();
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2023-07-05 18:28:01 +00:00
|
|
|
const { colors } = useTheme();
|
|
|
|
|
|
|
|
const {
|
|
|
|
Accounts_iframe_enabled,
|
|
|
|
Assets_favicon_512,
|
|
|
|
Site_Name,
|
|
|
|
Site_Url,
|
|
|
|
inviteLinkToken,
|
|
|
|
registrationForm,
|
|
|
|
server,
|
|
|
|
showLoginButton
|
|
|
|
} = useWorkspaceViewSelector();
|
|
|
|
|
|
|
|
useLayoutEffect(() => {
|
|
|
|
navigation.setOptions({
|
|
|
|
title: I18n.t('Your_workspace')
|
|
|
|
});
|
|
|
|
}, [navigation]);
|
|
|
|
|
|
|
|
const showRegistrationButton = !!(
|
|
|
|
!Accounts_iframe_enabled &&
|
|
|
|
(registrationForm === 'Public' || (registrationForm === 'Secret URL' && inviteLinkToken?.length))
|
|
|
|
);
|
|
|
|
|
|
|
|
const login = () => {
|
2020-06-17 20:12:21 +00:00
|
|
|
if (Accounts_iframe_enabled) {
|
|
|
|
navigation.navigate('AuthenticationWebView', { url: server, authType: 'iframe' });
|
|
|
|
return;
|
|
|
|
}
|
2020-03-30 19:20:50 +00:00
|
|
|
navigation.navigate('LoginView', { title: Site_Name });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2023-07-05 18:28:01 +00:00
|
|
|
const register = () => {
|
2020-03-30 19:20:50 +00:00
|
|
|
navigation.navigate('RegisterView', { title: Site_Name });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2023-07-05 18:28:01 +00:00
|
|
|
return (
|
|
|
|
<FormContainer testID='workspace-view'>
|
|
|
|
<FormContainerInner>
|
|
|
|
<View style={styles.alignItemsCenter}>
|
|
|
|
<ServerAvatar url={server} image={Assets_favicon_512?.url ?? Assets_favicon_512?.defaultUrl} />
|
|
|
|
<Text style={[styles.serverName, { color: colors.titleText }]}>{Site_Name}</Text>
|
|
|
|
<Text style={[styles.serverUrl, { color: colors.auxiliaryText }]}>{Site_Url}</Text>
|
|
|
|
</View>
|
|
|
|
{showLoginButton ? <Button title={I18n.t('Login')} type='primary' onPress={login} testID='workspace-view-login' /> : null}
|
|
|
|
{showRegistrationButton ? (
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Create_account')}
|
|
|
|
type='secondary'
|
|
|
|
backgroundColor={colors.chatComponentBackground}
|
|
|
|
onPress={register}
|
|
|
|
testID='workspace-view-register'
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<RegisterDisabledComponent />
|
|
|
|
)}
|
|
|
|
</FormContainerInner>
|
|
|
|
</FormContainer>
|
|
|
|
);
|
|
|
|
};
|
2020-03-30 19:20:50 +00:00
|
|
|
|
2023-07-05 18:28:01 +00:00
|
|
|
export default WorkspaceView;
|