Rocket.Chat.ReactNative/app/views/WorkspaceView/index.tsx

95 lines
3.2 KiB
TypeScript
Raw Normal View History

import React, { useLayoutEffect } from 'react';
import { Text, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
import { CompositeNavigationProp } from '@react-navigation/core';
import { OutsideModalParamList, OutsideParamList } from '../../stacks/types';
import I18n from '../../i18n';
import Button from '../../containers/Button';
import { useTheme } from '../../theme';
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
import { IAssetsFavicon512 } from '../../definitions/IAssetsFavicon512';
import { getShowLoginButton } from '../../selectors/login';
import ServerAvatar from './ServerAvatar';
import styles from './styles';
import { useAppSelector } from '../../lib/hooks';
import RegisterDisabledComponent from './RegisterDisabledComponent';
type TNavigation = CompositeNavigationProp<
StackNavigationProp<OutsideParamList, 'WorkspaceView'>,
StackNavigationProp<OutsideModalParamList>
>;
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
}));
const WorkspaceView = () => {
const navigation = useNavigation<TNavigation>();
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 = () => {
if (Accounts_iframe_enabled) {
navigation.navigate('AuthenticationWebView', { url: server, authType: 'iframe' });
return;
}
navigation.navigate('LoginView', { title: Site_Name });
};
const register = () => {
navigation.navigate('RegisterView', { title: Site_Name });
};
return (
<FormContainer testID='workspace-view'>
<FormContainerInner>
<View style={styles.alignItemsCenter}>
<ServerAvatar url={server} image={Assets_favicon_512?.url ?? Assets_favicon_512?.defaultUrl} />
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
<Text style={[styles.serverName, { color: colors.fontTitlesLabels }]}>{Site_Name}</Text>
<Text style={[styles.serverUrl, { color: colors.fontSecondaryInfo }]}>{Site_Url}</Text>
</View>
{showLoginButton ? <Button title={I18n.t('Login')} type='primary' onPress={login} testID='workspace-view-login' /> : null}
{showRegistrationButton ? (
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
<Button title={I18n.t('Create_account')} type='secondary' onPress={register} testID='workspace-view-register' />
) : (
<RegisterDisabledComponent />
)}
</FormContainerInner>
</FormContainer>
);
};
export default WorkspaceView;