ReportBug.js 15.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
/*
FileName:UserSupport.js
Version:1.0.0
Purpose: User Support Screen
Devloper:Mahesh Reddy
*/
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, StatusBar, Dimensions, Picker, TouchableOpacity, Linking, TextInput, Alert } from 'react-native';
import { Title, Button, Container, Content, Header, Right, Left, Body, Tab, Tabs, TabHeading, Footer, Item, Input, FooterTab } from 'native-base';
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import SearchableDropdown from 'react-native-searchable-dropdown';
import AsyncStorage from '@react-native-community/async-storage';
// import { tsMethodSignature } from '@babel/types';
import { API, CHATAPI } from "../WebServices/RestClient";
import NetInfo from '@react-native-community/netinfo';
import Snackbar from 'react-native-snackbar';
import ModalSelector from 'react-native-modal-selector';
// import { Dropdown } from 'react-native-material-dropdown';
import log from '../LogFile/Log';
import Toast from 'react-native-whc-toast';
import { MAINTASKINFO, MAINTASKTITLE, DESCRIPTION, } from '../CommonComponents/Header';
import { ScrollView } from 'react-native-gesture-handler';
import { EMPLOYEEID1, FULLNAME, USERNAME1, EMAIL1, MOBILE1, ADDEMPLOYEE, EMPLOYEEDETAILS } from '../CommonComponents/Header';
import RadioButtonRN from 'radio-buttons-react-native';
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';

const options = {
    title: 'Select Image',
    type: 'library',
    options: {
        maxHeight: 200,
        maxWidth: 200,
        selectionLimit: 1,
        mediaType: 'photo',
        includeBase64: false
    },
}

export default class ReportBug extends Component {

    constructor(props) {
        super(props);

        this.state = {
            email_to_contact: '',
            bug_one_sen: '',
            steps_for_bug: '',
            docFile: '',

        };
    }
    //upload Report
    reportBugimage = async () => {
        log("Info", " onSignIn( usertype, user_status, password) is used to Adding the new Employee");
        const images = await launchImageLibrary(options);

        if (this.isValid()) {



            AsyncStorage.multiGet(["cropcode", "userName", "fullName"], (err, response) => {
                const cropcode = response[0][1];
                const userName = response[1][1];
                const { empId, bug_one_sen, steps_for_bug, docFile } = this.state;
                const data = new FormData();
                data.append('file', {
                    uri: images.assets[0].uri,
                    type: images.assets[0].type,
                    name: images.assets[0].fileName,
                })
                data.append('action', 'releaseBug');
                data.append('api', CHATAPI);
                data.append('bug_one_sen', bug_one_sen);
                data.append('email_to_contact', userName);
                data.append('steps_for_bug', steps_for_bug);

                NetInfo.fetch().then(state => {
                    if (state.type == "none") {
                        console.log(state.type);
                        log("Warn", "No internet connection");
                        Snackbar.show({
                            title: 'No Internet Connection',
                            backgroundColor: 'red',
                            duration: Snackbar.LENGTH_LONG,
                        });
                    } else {
                        fetch(API + 'report_bug.php', {
                            method: 'post',
                            body: data,
                            headers: {
                                'Content-Type': 'multipart/form-data; ',
                            },
                        }).then((response) => response.json())
                            .then((responseJson) => {
                                //alert(responseJson);
                                console.log(JSON.stringify(responseJson));
                                console.log(responseJson);
                                alert("Your report was sent successfully")

                                if (responseJson.status === 'True') {

                                    this.props.navigation.navigate('MyTask');

                                }
                                else {
                                    console.log(JSON.stringify(responseJson));
                                    log("Warn", "Error  found");
                                    // alert("error");
                                    // alert(responseJson.message)
                                }

                            }).catch((error) => {
                                console.error(error);
                                log("Error", "Adding the new Employee error");
                            });
                    }
                });

            });

        }
    }
    //upload Report
    reportBug() {

        if (this.isValid()) {


            AsyncStorage.multiGet(["cropcode", "userName", "fullName"], (err, response) => {
                const cropcode = response[0][1];
                const userName = response[1][1];
                const { empId, bug_one_sen, steps_for_bug, email_to_contact, docFile } = this.state;

                const data = new FormData();
                data.append('file', '')
                data.append('action', 'releaseBug');
                data.append('api', CHATAPI);
                data.append('bug_one_sen', bug_one_sen);
                data.append('email_to_contact', email_to_contact);
                data.append('steps_for_bug', steps_for_bug);

                NetInfo.fetch().then(state => {
                    if (state.type == "none") {
                        console.log(state.type);
                        log("Warn", "No internet connection");
                        Snackbar.show({
                            title: 'No Internet Connection',
                            backgroundColor: 'red',
                            duration: Snackbar.LENGTH_LONG,
                        });
                    } else {
                        fetch(API + 'report_bug.php', {
                            method: 'post',
                            body: data,
                            headers: {
                                'Content-Type': 'multipart/form-data; ',
                            },
                        }).then((response) => response.json())
                            .then((responseJson) => {
                                //alert(responseJson);
                                console.log(JSON.stringify(responseJson));
                                console.log(responseJson);
                                alert("Your report was sent successfully")

                                if (responseJson.status === 'True') {

                                    this.props.navigation.navigate('Login');

                                }
                                else {
                                    console.log(JSON.stringify(responseJson));
                                    log("Warn", "Error  found");
                                    // alert("error");
                                    // alert(responseJson.message)
                                }

                            }).catch((error) => {
                                console.error(error);
                                log("Error", "Adding the new Employee error");
                            });
                    }
                });
            });


        }
    }
    //Checking the Validations start
    isValid() {
        var { email_to_contact, bug_one_sen, steps_for_bug } = this.state;
        let valid = false;

        // if (empId.length === 0) {
        //     log("Warn", "empId should not be empty");
        //     alert("Enter Employee Id");
        // }

        if (!this.verifyEmail(email_to_contact)) {
            log("Warn", "Email should not be empty");
            alert("Enter Email ");
        }
        else if (bug_one_sen.length === 0) {
            log("Warn", "Bug should not be empty");
            alert("Enter Bug Report");
        }

        else if (steps_for_bug.length === 0) {
            log("Warn", "Steps should not be empty");
            alert("Enter Steps of Bugs");
        }

        // else if (mobile.length === 0) {
        //     log("Warn", "mobile should not be empty");
        //     alert("Enter phonenumber");
        // }
        // else if (mobile.length > 10) {
        //     log("Warn", "mobile should not be greater than 10");
        //     alert("Invalid phonenumber");
        // }
        // else if (mobile.length < 10) {
        //     log("Warn", "mobile should not be less than 10");
        //     alert("Invalid phonenumber");
        // }

        else {
            valid = true;
        }
        return valid;
    }
    verifyEmail(email_to_contact) {
        var reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return reg.test(email_to_contact);
    }
    //Checking the Validations end






    //Add or Mpdify the Maintask close
    componentDidMount() {
        //Getting Employees List
        log("Debug", "Add Task screen is loaded");
        // alert("")

    }

    render() {

        return (
            <Container>
                <Header
                    androidStatusBarColor="#00A2C1"
                    style={{
                        backgroundColor: '#00A2C1',
                        height: 60,
                        width: Dimensions.get('window').width,
                        borderBottomColor: '#ffffff',
                        justifyContent: 'space-between',
                    }}>
                    <Left>
                    <Icon size={25} name="arrow-left" style={{ color: '#fff' }} onPress={() =>
              this.props.navigation.goBack(null)} />
                    </Left>
                    <Body>
                        <Title style={{ color: '#fff', fontWeight: '600' }}>Report Support</Title>
                    </Body>

                </Header>


                <Content>
                    <Toast ref="toast" />

                    <View style={{ paddingTop: 20, }}>
                        <Text style={{ paddingTop: 10, paddingLeft: 20 }}>
                            Tell us about the bug you found!
                        </Text>
                    </View>

                    <View style={{ paddingTop: 20, }}>

                        <View style={{ paddingLeft: 10, }}>
                            <View style={{ width: wp('95%'), }}>
                                <Text>
                                    When The Bug Is Resolved, Which Email Should We Contact You At?*
                            </Text>

                            </View>
                            <View>



                                <TextInput style={{ width: wp('95%'), height: 45, borderBottomWidth: 1, }}
                                    placeholder="Enter Emai"
                                    underlineColorAndroid='transparent'
                                    // value={this.state.email_to_contact}
                                    onChangeText={(email_to_contact) => this.setState({ email_to_contact })}

                                />
                            </View>
                        </View>

                        <View style={{ paddingLeft: 10, }}>
                            <View style={{ width: wp('95%'), }}>
                                <Text>
                                    Could You Please Describe This Bug In One Sentence?*                            </Text>
                            </View>
                            <View>

                                <TextInput style={{ width: wp('95%'), height: 45, borderBottomWidth: 1, }}
                                    placeholder="Scrum board or Active Sprint: Sprint Name not displaying "
                                    underlineColorAndroid='transparent'
                                    // value={this.state.bug_one_sen}
                                    onChangeText={(bug_one_sen) => this.setState({ bug_one_sen })}

                                />
                            </View>
                        </View>
                        <View style={{ paddingLeft: 10, }}>
                            <View style={{ width: wp('95%'), }}>
                                <Text>
                                    Let Us Know How To Reproduce The Bug For Us To Work On?*
                                                           </Text>
                            </View>
                            <View>

                                <TextInput style={{ width: wp('95%'), height: 45, borderBottomWidth: 1, }}
                                    placeholder="1. Go to Dashboards | 2. Add a new Project "
                                    // maxLength={10}
                                    // keyboardType={"number-pad"}
                                    underlineColorAndroid='transparent'
                                    // value={this.state.steps_for_bug}
                                    onChangeText={(steps_for_bug) => this.setState({ steps_for_bug })}

                                />
                            </View>

                        </View>
                        <TouchableOpacity style={styles.upload}
                            onPress={this.reportBugimage} >
                            <Text style={{ color: 'white' }}>Uplaod</Text>
                        </TouchableOpacity>

                        <View style={{ flexDirection: 'row', marginTop: 10, justifyContent: "space-between" }}>



                            <TouchableOpacity style={styles.opensave}
                                onPress={this.reportBug.bind(this)} >
                                <Text style={{ color: 'white' }}>Submit</Text>
                            </TouchableOpacity>
                        </View>

                    </View>
                </Content>
            </Container>
        );
    }
}
//Styles for UI
const styles = StyleSheet.create({
    opencancel: {
        flex: 1,
        ...Platform.select({
            ios: {
                backgroundColor: 'red', margin: 20, height: 30, alignItems:
                    "center", justifyContent: 'center'
            },
            android: {
                backgroundColor: 'red', margin: 20, height: 30, alignItems:
                    "center", justifyContent: 'center'
            },
        }),
    },
    opensave: {
        flex: 1,
        ...Platform.select({
            ios: {
                backgroundColor: 'green', margin: 20, height: 30, alignItems:
                    "center", justifyContent: 'center'
            },
            android: {
                backgroundColor: 'green', margin: 20, height: 30, alignItems:
                    "center", justifyContent: 'center'
            },
        }),
    },
    upload: {
        flex: 1,
        ...Platform.select({
            ios: {
                backgroundColor: 'orange', margin: 20, height: 30, alignItems:
                    "center", justifyContent: 'center'
            },
            android: {
                backgroundColor: 'orange', margin: 20, height: 30, alignItems:
                    "center", justifyContent: 'center'
            },
        }),
    },
});