Handled case of no common team

This commit is contained in:
harshil Sharma 2023-10-27 16:32:20 +05:30
parent d3ba8439f2
commit 6752d84b21
5 changed files with 16 additions and 85 deletions

View file

@ -10,7 +10,11 @@ import {useTheme} from '@app/context/theme';
import {t} from '@app/i18n';
import {getKeyboardAppearanceFromTheme} from '@app/utils/theme';
export const ChannelNameInput = () => {
type Props = {
error?: string;
}
export const ChannelNameInput = ({error}: Props) => {
const {formatMessage} = useIntl();
const theme = useTheme();
@ -29,10 +33,11 @@ export const ChannelNameInput = () => {
maxLength={Channel.MAX_CHANNEL_NAME_LENGTH}
keyboardAppearance={getKeyboardAppearanceFromTheme(theme)}
returnKeyType='next'
showErrorIcon={false}
showErrorIcon={true}
spellCheck={false}
testID='gonvert_gm_to_channel.channel_display_name.input'
theme={theme}
error={error}
/>
);
};

View file

@ -7,8 +7,9 @@ import {fetchChannelMemberships, getGroupMessageMembersCommonTeams} from '@actio
import {PER_PAGE_DEFAULT} from '@app/client/rest/constants';
import {useServerUrl} from '@app/context/server';
import {ConvertGMToChannelForm} from './convert_gm_to_channel_form';
import {ConvertGMToChannelForm} from './convert_gm_to_channel_form/convert_gm_to_channel_form';
import {Loader} from './loader';
import { logDebug } from '@app/utils/log';
type Props = {
channelId: string;

View file

@ -1,79 +0,0 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, { useCallback, useEffect, useRef, useState } from 'react';
import {useIntl} from 'react-intl';
import {View} from 'react-native';
import {useTheme} from '@app/context/theme';
import {makeStyleSheetFromTheme} from '@app/utils/theme';
import Button from '@components/button';
import {ChannelNameInput} from './channel_name_input';
import MessageBox from './message_box';
import {TeamSelector} from './team_selector';
import { logDebug } from '@app/utils/log';
const getStyleFromTheme = makeStyleSheetFromTheme((theme: Theme) => {
return {
container: {
paddingVertical: 24,
paddingHorizontal: 20,
display: 'flex',
flexDirection: 'column',
gap: 24,
},
};
});
type Props = {
commonTeams: Team[];
profiles: UserProfile[];
}
export const ConvertGMToChannelForm = ({commonTeams, profiles}: Props) => {
const theme = useTheme();
const styles = getStyleFromTheme(theme);
const team = useRef<Team>();
const {formatMessage} = useIntl();
const confirmButtonText = formatMessage({
id: 'channel_info.convert_gm_to_channel.button_text',
defaultMessage: 'Convert to Private Channel',
});
useEffect(() => {
if (commonTeams.length === 1) {
team.current = commonTeams[0];
}
}, [commonTeams]);
const handleOnSelectTeam = useCallback((selectedTeam: Team) => {
team.current = selectedTeam;
}, []);
return (
<View style={styles.container}>
<MessageBox
profiles={profiles}
/>
{
commonTeams.length > 1 &&
<TeamSelector
commonTeams={commonTeams}
onSelectTeam={handleOnSelectTeam}
/>
}
<ChannelNameInput/>
<Button
onPress={() => logDebug(`Selected team: ${team.current?.display_name}`)}
text={confirmButtonText}
theme={theme}
buttonType='destructive'
emphasis='primary'
size='lg'
/>
</View>
);
};

View file

@ -25,9 +25,10 @@ const getStyleFromTheme = makeStyleSheetFromTheme((theme: Theme) => {
type Props = {
commonTeams: Team[];
onSelectTeam: (team: Team) => void;
selectedTeamId?: string;
}
export const TeamSelector = ({commonTeams, onSelectTeam}: Props) => {
export const TeamSelector = ({commonTeams, onSelectTeam, selectedTeamId}: Props) => {
const {formatMessage} = useIntl();
const theme = useTheme();
const styles = getStyleFromTheme(theme);
@ -49,7 +50,7 @@ export const TeamSelector = ({commonTeams, onSelectTeam}: Props) => {
await dismissBottomSheet();
const title = formatMessage({id: 'channel_info.convert_gm_to_channel.team_selector_list.title', defaultMessage: 'Select Team'});
goToScreen(Screens.TEAM_SELECTOR_LIST, title, {teams: commonTeams, selectTeam});
goToScreen(Screens.TEAM_SELECTOR_LIST, title, {teams: commonTeams, selectTeam, selectedTeamId});
});
return (

View file

@ -1090,9 +1090,12 @@
"channel_info.convert_gm_to_channel": "Convert to a Private Channel",
"channel_info.convert_gm_to_channel.warning.header": "Conversation history will be visible to any channel members",
"channel_info.convert_gm_to_channel.warning.body": "You are about to convert the Group Message with {memberNames} to a Channel. This cannot be undone.",
"channel_info.convert_gm_to_channel.warning.no_teams.header": "Unable to convert to a channel because group members are part of different teams",
"channel_info.convert_gm_to_channel.warning.no_teams.body": "Group Message cannot be converted to a channel because members are not a part of the same team. Add all members to a single team to convert this group message to a channel.",
"channel_info.convert_gm_to_channel.warning.body.yourself": "yourself",
"channel_into.convert_gm_to_channel.team_selector.label": "Team",
"channel_into.convert_gm_to_channel.team_selector.placeholder": "Select a Team",
"channel_info.convert_gm_to_channel.button_text": "Convert to Private Channel",
"channel_info.convert_gm_to_channel.team_selector_list.title": "Select Team"
"channel_info.convert_gm_to_channel.team_selector_list.title": "Select Team",
"generic.back": "Back"
}