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

114 lines
3.6 KiB
TypeScript
Raw Normal View History

import React, { useLayoutEffect, useState } from 'react';
import { ScrollView, StatusBar } from 'react-native';
import { CompositeNavigationProp, RouteProp, useNavigation, useRoute } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
import { useForm } from 'react-hook-form';
import * as yup from 'yup';
import { yupResolver } from '@hookform/resolvers/yup';
import log from '../../lib/methods/helpers/log';
import SafeAreaView from '../../containers/SafeAreaView';
import { useTheme } from '../../theme';
import { ChatsStackParamList } from '../../stacks/types';
import { MasterDetailInsideStackParamList } from '../../stacks/MasterDetailStack/types';
import I18n from '../../i18n';
import UserInfo from './UserInfo';
import styles from './styles';
import { ControlledFormTextInput } from '../../containers/TextInput';
import Button from '../../containers/Button';
import { useAppSelector } from '../../lib/hooks';
import EventEmitter from '../../lib/methods/helpers/events';
import { LISTENER } from '../../containers/Toast';
import { Services } from '../../lib/services';
import KeyboardView from '../../containers/KeyboardView';
type TReportUserViewNavigationProp = CompositeNavigationProp<
StackNavigationProp<ChatsStackParamList, 'ReportUserView'>,
StackNavigationProp<MasterDetailInsideStackParamList>
>;
type TReportUserViewRouteProp = RouteProp<ChatsStackParamList, 'ReportUserView'>;
interface ISubmit {
description: string;
}
const schema = yup.object().shape({
description: yup.string().trim().required()
});
const ReportUserView = () => {
const [loading, setLoading] = useState(false);
const { colors } = useTheme();
const navigation = useNavigation<TReportUserViewNavigationProp>();
const { isMasterDetail } = useAppSelector(state => ({ isMasterDetail: state.app.isMasterDetail }));
const {
params: { username, userId, name }
} = useRoute<TReportUserViewRouteProp>();
const {
control,
handleSubmit,
formState: { isValid }
} = useForm<ISubmit>({ mode: 'onChange', resolver: yupResolver(schema), defaultValues: { description: '' } });
useLayoutEffect(() => {
navigation?.setOptions({
title: I18n.t('Report_user')
});
}, [navigation]);
const submit = async ({ description }: ISubmit) => {
try {
setLoading(true);
await Services.reportUser(userId, description);
EventEmitter.emit(LISTENER, { message: I18n.t('Report_sent_successfully') });
setLoading(false);
if (isMasterDetail) {
navigation.navigate('DrawerNavigator');
return;
}
navigation.navigate('RoomView');
} catch (e) {
log(e);
setLoading(false);
}
};
return (
<KeyboardView
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
style={{ backgroundColor: colors.surfaceHover }}
contentContainerStyle={styles.container}
keyboardVerticalOffset={128}
>
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
<SafeAreaView style={[styles.containerView, { backgroundColor: colors.strokeExtraDark }]} testID='report-user-view'>
<ScrollView contentContainerStyle={[styles.scroll, { backgroundColor: colors.surfaceHover }]}>
<StatusBar />
<UserInfo username={username} name={name} />
<ControlledFormTextInput
name='description'
control={control}
label={I18n.t('Why_do_you_want_to_report')}
multiline
inputStyle={styles.textInput}
testID='report-user-view-input'
containerStyle={styles.containerTextInput}
/>
<Button
title={I18n.t('Report')}
type='primary'
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
backgroundColor={colors.buttonBackgroundDangerDefault}
disabled={!isValid}
onPress={handleSubmit(submit)}
testID='report-user-view-submit'
loading={loading}
/>
</ScrollView>
</SafeAreaView>
</KeyboardView>
);
};
export default ReportUserView;