From 3b4afdcef2e82df8eea64cd4fcda4b709f78dd24 Mon Sep 17 00:00:00 2001 From: Menaka Date: Wed, 21 Aug 2024 18:45:40 +0530 Subject: [PATCH] Add DOB field, Offlinepage and fix bug --- src/components/Sidebar.tsx | 44 +++++++++++++++++--------- src/containers/ExpoBare/ExpoBare.tsx | 28 ++++++++++++++-- src/screens/ForgotPassword.tsx | 2 +- src/screens/OTPVerification.tsx | 8 ++--- src/screens/OfflinePage.tsx | 39 +++++++++++++++++++++++ src/screens/Quizzes/TakeQuizzes.tsx | 9 ++++-- src/screens/Student/StudentCreate.tsx | 31 ++++++++++++++++-- src/screens/Student/StudentProfile.tsx | 2 +- src/screens/Student/StudentReport.tsx | 4 +-- src/screens/Student/StudentUpdate.tsx | 31 ++++++++++++++++-- src/screens/Teacher/TeacherCreate.tsx | 33 +++++++++++++++++-- src/screens/Teacher/TeacherUpdate.tsx | 36 ++++++++++++++++++--- src/screens/class/classCreate.tsx | 2 +- src/theme/BaseStyles.tsx | 2 +- 14 files changed, 230 insertions(+), 41 deletions(-) create mode 100644 src/screens/OfflinePage.tsx diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 2c90a99..427d096 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -83,24 +83,25 @@ class Sidebar extends React.Component { const token = await AsyncStorage.getItem('token') this.imageBaseUrl = await fetchBaseUrl() this.props.getMenuList({ token: token, app_type: 'mobile' }) - if (userInfo) { - const userDetails: any = JSON.parse(userInfo) - const profileDetails: any = JSON.parse(profileInfo) - this.isLoggedinAs = userDetails.usertype - this.filterRoleBaseSideBar(userDetails, profileDetails) - } else { - if (this.props.userinfo.hasOwnProperty('status')) { - if (this.props.userinfo.status) { - this.isLoggedinAs = this.props.userinfo.data.usertype - this.filterRoleBaseSideBar(this.props.userinfo.data, this.props.profileInfo.data) - } - } - } + // if (userInfo) { + // const userDetails: any = JSON.parse(userInfo) + // const profileDetails: any = JSON.parse(profileInfo) + // this.isLoggedinAs = userDetails.usertype + // this.filterRoleBaseSideBar(userDetails, profileDetails) + // } else { + // if (this.props.userinfo.hasOwnProperty('status')) { + // if (this.props.userinfo.status) { + // this.isLoggedinAs = this.props.userinfo.data.usertype + // this.filterRoleBaseSideBar(this.props.userinfo.data, this.props.profileInfo.data) + // } + // } + // } } async componentDidUpdate(prevProps: any) { if (prevProps.menuList !== this.props.menuList) { const userInfo: any = await AsyncStorage.getItem('userInfo') + const profileInfo: any = await AsyncStorage.getItem('profileInfo') if (userInfo) { const { menuList } = this.props const { routes } = this.state @@ -123,7 +124,20 @@ class Sidebar extends React.Component { this.setState({ routes: concatenatedMenu }) } } - } + } + if (userInfo && profileInfo) { + const userDetails: any = JSON.parse(userInfo) + const profileDetails: any = JSON.parse(profileInfo) + this.isLoggedinAs = userDetails.usertype + this.filterRoleBaseSideBar(userDetails, profileDetails) + } else { + if (this.props.userinfo.hasOwnProperty('status')) { + if (this.props.userinfo.status) { + this.isLoggedinAs = this.props.userinfo.data.usertype + this.filterRoleBaseSideBar(this.props.userinfo.data, this.props.profileInfo.data) + } + } + } } } @@ -143,7 +157,7 @@ class Sidebar extends React.Component { render() { - + return ( {this.state.image && this.state.image !== '' ? diff --git a/src/containers/ExpoBare/ExpoBare.tsx b/src/containers/ExpoBare/ExpoBare.tsx index 8f4e55e..c307203 100644 --- a/src/containers/ExpoBare/ExpoBare.tsx +++ b/src/containers/ExpoBare/ExpoBare.tsx @@ -7,7 +7,7 @@ import AuthNavigator from '../../navigation/AuthNavigator' import * as Analytics from 'expo-firebase-analytics' import * as Location from 'expo-location' import * as SplashScreen from 'expo-splash-screen' -import NetInfo from '@react-native-community/netinfo' +import NetInfo, { NetInfoState } from '@react-native-community/netinfo' import { ActivityIndicator, SafeAreaView, StyleSheet, View, StatusBar, KeyboardAvoidingView } from 'react-native' import FlashMessage from 'react-native-flash-message' import * as Font from 'expo-font' @@ -19,6 +19,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage' import { common } from '@constants/Constants' //NOSONAR import * as ImagePicker from 'expo-image-picker' import messaging from '@react-native-firebase/messaging' +import OfflinePage from '@screens/OfflinePage'; const Stack = createStackNavigator(); class ExpoBare extends React.Component { @@ -31,7 +32,8 @@ class ExpoBare extends React.Component { state = { appIsReady: false, location: '', - assetsLoaded: false + assetsLoaded: false, + isConnected: true, } constructor(Props: any) { @@ -42,6 +44,8 @@ class ExpoBare extends React.Component { } async componentDidMount() { + this.unsubscribe = NetInfo.addEventListener(this.handleNetworkChange); + // Prevent native splash screen from autohiding this.token = await AsyncStorage.getItem('token') try { @@ -60,6 +64,20 @@ class ExpoBare extends React.Component { } + componentWillUnmount() { + if (this.unsubscribe) { + this.unsubscribe(); + } + } + + private handleNetworkChange = (state: NetInfoState) => { + this.setState({ + isConnected: state.isConnected, + }); + }; + + private unsubscribe: (() => void) | undefined; + async componentDidUpdate() { if (this.props.profileInfo.hasOwnProperty('status')) { if (!this.props.profileInfo.status) { @@ -240,7 +258,7 @@ class ExpoBare extends React.Component { render() { - const { assetsLoaded } = this.state + const { assetsLoaded, isConnected } = this.state const initial = this.token ? "app" : "auth" const onNavigationStateChange = (prevState:any, currentState:any) => { this.getActiveUserCheck(currentState) @@ -259,6 +277,9 @@ class ExpoBare extends React.Component { + {!isConnected ? + + : { @@ -278,6 +299,7 @@ class ExpoBare extends React.Component { + } ) diff --git a/src/screens/ForgotPassword.tsx b/src/screens/ForgotPassword.tsx index 60130cb..6f8c006 100644 --- a/src/screens/ForgotPassword.tsx +++ b/src/screens/ForgotPassword.tsx @@ -38,7 +38,7 @@ class ForgotPassword extends React.Component{ if (this.props.checkuser_data.hasOwnProperty('status')) { if (this.props.checkuser_data.status) { if(!this.props.isRedirected) { - this.props.navigation.navigate("otp", { action: 'forgot', username: this.state.username.value }) + this.props.navigation.navigate("otp", { action: 'forgot', username: this.state.username.value, isEmailAuth: this.state.isEmailAuth }) } } } diff --git a/src/screens/OTPVerification.tsx b/src/screens/OTPVerification.tsx index 2c173ae..ff50f75 100644 --- a/src/screens/OTPVerification.tsx +++ b/src/screens/OTPVerification.tsx @@ -21,6 +21,7 @@ class OTPVerification extends React.Component{ inputs:any; state = { username: this.props.route.params.username, + isEmailAuth: this.props.route.params.isEmailAuth, otp: { value: '', error: '', verified: null }, action: this.props.route.params.action, otp1: false, @@ -192,15 +193,14 @@ class OTPVerification extends React.Component{ } render() { - const { otp1, otp2, otp3, otp4, otp5, otp6, inputotp } = this.state - + const { otp1, otp2, otp3, otp4, otp5, otp6, inputotp, isEmailAuth } = this.state return ( STEP 2/3 - Verify your number - Wel'll text you on {this.state.username} + {isEmailAuth ? "Verify your Email" : "Verify your number"} + We'll text you on {this.state.username} {Array.from({ length: 6 }).map((_, index) => ( diff --git a/src/screens/OfflinePage.tsx b/src/screens/OfflinePage.tsx new file mode 100644 index 0000000..d4ec68e --- /dev/null +++ b/src/screens/OfflinePage.tsx @@ -0,0 +1,39 @@ +import React, { Component } from 'react'; +import { View, Text, StyleSheet } from 'react-native'; + + +interface OfflinePageProps { + +} + +class OfflinePage extends Component { + render() { + + return ( + + You're offline + Please check your internet connection and try again. + + ); + } +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: '#f8f8f8', + }, + title: { + fontSize: 24, + fontWeight: 'bold', + }, + message: { + fontSize: 18, + marginVertical: 20, + textAlign: 'center' + }, +}); + +export default OfflinePage; diff --git a/src/screens/Quizzes/TakeQuizzes.tsx b/src/screens/Quizzes/TakeQuizzes.tsx index 57dd5c6..a3ed72f 100644 --- a/src/screens/Quizzes/TakeQuizzes.tsx +++ b/src/screens/Quizzes/TakeQuizzes.tsx @@ -25,7 +25,9 @@ class TakeQuizzes extends React.Component{ scrollView: any; token: any; state: any = { - academicYear: '' + academicYear: '', + data: {}, + info: {} }; constructor(props: any) { @@ -35,6 +37,7 @@ class TakeQuizzes extends React.Component{ async componentDidMount() { const { navigation, route } = this.props; const title = route.params?.data?.question_name || 'Quizzes'; + this.setState({data: route.params?.data, info: route.params?.info }) navigation.setOptions({ title }); this.getCurrentAcademicYearData() //fetch the Current Academic year from Login Response this.token = await AsyncStorage.getItem('token') @@ -103,8 +106,8 @@ class TakeQuizzes extends React.Component{ } onTakeQuizzes = (data: any) => { - const quizAdminparams: any = this.props.route.params.data - const classData = this.props.route.params.info + const quizAdminparams: any = this.state.data + const classData = this.state.info if(quizAdminparams?.is_teacher_present && (classData?.is_attendance_taken || this.props.is_attendance_taken)){ const classDataInfo: any = JSON.parse(JSON.stringify(classData)) let studentList: any = [] diff --git a/src/screens/Student/StudentCreate.tsx b/src/screens/Student/StudentCreate.tsx index 11b0ca7..1904e57 100644 --- a/src/screens/Student/StudentCreate.tsx +++ b/src/screens/Student/StudentCreate.tsx @@ -13,7 +13,8 @@ import { FontAwesome } from "@expo/vector-icons" import BaseColors from "@theme/Colors" //NOSONAR import * as ImagePicker from 'expo-image-picker' import Constants from "expo-constants" -import { RadioButton } from 'react-native-paper' +import { RadioButton } from 'react-native-paper' +import DateTimePickerModal from 'react-native-modal-datetime-picker'; const Sepator = ({ style }: any) => @@ -57,7 +58,8 @@ class StudentCreate extends React.Component{ isImageUploaded: false, image: '', imagePreviewURL: '', - academicYear: '' + academicYear: '', + isDatePickerVisible: false, }; token: any; @@ -221,6 +223,14 @@ class StudentCreate extends React.Component{ } } + showDatePicker = () => this.setState({ isDatePickerVisible: true }); + hideDatePicker = () => this.setState({ isDatePickerVisible: false }); + + handleConfirm = (date: any, setFieldValue: any) => { + setFieldValue('date_of_birth', date.toISOString().split('T')[0]); + this.hideDatePicker(); + }; + render() { return ( @@ -283,6 +293,7 @@ class StudentCreate extends React.Component{ email_id: '', student_name: '', gender:'', + date_of_birth: '', }} onSubmit={(values, actions) => this.onStudentSubmit(values, actions)} > @@ -343,6 +354,22 @@ class StudentCreate extends React.Component{ {(errors.parent_lastname && touched.parent_lastname) && {errors.parent_lastname}} + Date of Birth + + + + {values.date_of_birth ? values.date_of_birth : 'Select Date'} + + + {(errors.date_of_birth && touched.date_of_birth) && {errors.date_of_birth}} + + this.handleConfirm(date, setFieldValue)} + onCancel={this.hideDatePicker} + /> + diff --git a/src/screens/Student/StudentProfile.tsx b/src/screens/Student/StudentProfile.tsx index 727e386..769a22b 100644 --- a/src/screens/Student/StudentProfile.tsx +++ b/src/screens/Student/StudentProfile.tsx @@ -291,7 +291,7 @@ class StudentProfile extends React.Component{ Performance By Subjects - Week 0% + Weak 0% diff --git a/src/screens/Student/StudentReport.tsx b/src/screens/Student/StudentReport.tsx index 66bf273..6fb8114 100644 --- a/src/screens/Student/StudentReport.tsx +++ b/src/screens/Student/StudentReport.tsx @@ -198,7 +198,7 @@ class StudentReport extends React.Component{ } - {this.props.studentsList.data && + {this.props.studentsList.data && this.props.classes.data.status !== false && { {perfomanceReportByTopic.questions && perfomanceReportByTopic.questions.map((questionItem: any, questionIndex: any) => ( - + {questionItem?.question_name} diff --git a/src/screens/Student/StudentUpdate.tsx b/src/screens/Student/StudentUpdate.tsx index df88b58..4a62d87 100644 --- a/src/screens/Student/StudentUpdate.tsx +++ b/src/screens/Student/StudentUpdate.tsx @@ -14,6 +14,7 @@ import BaseColors from "@theme/Colors" //NOSONAR import * as ImagePicker from 'expo-image-picker' import Constants from "expo-constants" import { RadioButton } from 'react-native-paper' +import DateTimePickerModal from 'react-native-modal-datetime-picker'; const Sepator = ({ style }: any) => @@ -57,7 +58,8 @@ class StudentUpdate extends React.Component{ isImageUploaded: false, image: '', imagePreviewURL: '', - academicYear: '' + academicYear: '', + isDatePickerVisible: false, }; token: any; @@ -211,6 +213,14 @@ class StudentUpdate extends React.Component{ } } + showDatePicker = () => this.setState({ isDatePickerVisible: true }); + hideDatePicker = () => this.setState({ isDatePickerVisible: false }); + + handleConfirm = (date: any, setFieldValue: any) => { + setFieldValue('date_of_birth', date.toISOString().split('T')[0]); + this.hideDatePicker(); + }; + render() { let studentInfo: any = {} @@ -253,7 +263,8 @@ class StudentUpdate extends React.Component{ phone_number: studentInfo?.phone_number, email_id: studentInfo?.email_id, student_name: studentInfo?.student_name, - gender: studentInfo?.gender + gender: studentInfo?.gender, + date_of_birth: studentInfo?.date_of_birth, }} onSubmit={(values, actions) => this.onStudentSubmit(values, actions)} > @@ -348,6 +359,22 @@ class StudentUpdate extends React.Component{ {(errors.parent_lastname && touched.parent_lastname) && {errors.parent_lastname}} + Date of Birth + + + + {values.date_of_birth ? values.date_of_birth : 'Select Date'} + + + {(errors.date_of_birth && touched.date_of_birth) && {errors.date_of_birth}} + + this.handleConfirm(date, setFieldValue)} + onCancel={this.hideDatePicker} + /> + diff --git a/src/screens/Teacher/TeacherCreate.tsx b/src/screens/Teacher/TeacherCreate.tsx index b073298..1201bfa 100644 --- a/src/screens/Teacher/TeacherCreate.tsx +++ b/src/screens/Teacher/TeacherCreate.tsx @@ -8,6 +8,7 @@ import { connect } from "react-redux" import { ActionCreators } from "@actions" //NOSONAR import PropTypes from 'prop-types' import AsyncStorage from "@react-native-async-storage/async-storage" +import DateTimePickerModal from 'react-native-modal-datetime-picker'; const teacherCreateValidationSchema = yup.object().shape({ firstname: yup @@ -35,7 +36,9 @@ const teacherCreateValidationSchema = yup.object().shape({ class TeacherCreate extends React.Component{ formikActions: any; static propTypes = {}; - state = {}; + state = { + isDatePickerVisible: false, + }; token: any; constructor(props: any) { @@ -79,6 +82,14 @@ class TeacherCreate extends React.Component{ this.props.createTeacher({ data, token: this.token }) } + showDatePicker = () => this.setState({ isDatePickerVisible: true }); + hideDatePicker = () => this.setState({ isDatePickerVisible: false }); + + handleConfirm = (date: any, setFieldValue: any) => { + setFieldValue('date_of_birth', date.toISOString().split('T')[0]); + this.hideDatePicker(); + }; + render() { return ( @@ -95,7 +106,8 @@ class TeacherCreate extends React.Component{ firstname: '', lastname: '', phone_number: '', - email_id: '' + email_id: '', + date_of_birth: '' }} onSubmit={(values, actions) => this.onTeacherSubmit(values, actions)} > @@ -128,6 +140,23 @@ class TeacherCreate extends React.Component{ value={values.email_id} keyboardType="default" /> {(errors.email_id && touched.email_id) && {errors.email_id}} + + Date of Birth + + + + {values.date_of_birth ? values.date_of_birth : 'Select Date'} + + + {(errors.date_of_birth && touched.date_of_birth) && {errors.date_of_birth}} + + this.handleConfirm(date, setFieldValue)} + onCancel={this.hideDatePicker} + /> + diff --git a/src/screens/Teacher/TeacherUpdate.tsx b/src/screens/Teacher/TeacherUpdate.tsx index 2c2f117..be3596b 100644 --- a/src/screens/Teacher/TeacherUpdate.tsx +++ b/src/screens/Teacher/TeacherUpdate.tsx @@ -8,6 +8,7 @@ import { connect } from "react-redux" import { ActionCreators } from "@actions" //NOSONAR import PropTypes from 'prop-types' import AsyncStorage from "@react-native-async-storage/async-storage" +import DateTimePickerModal from 'react-native-modal-datetime-picker'; const teacherUpdateValidationSchema = yup.object().shape({ firstname: yup @@ -36,7 +37,8 @@ class TeacherUpdate extends React.Component{ formikActions: any; static propTypes = {}; state = { - id: this.props.route.teacher_id + id: this.props.route.teacher_id, + isDatePickerVisible: false, }; token: any; @@ -86,6 +88,13 @@ class TeacherUpdate extends React.Component{ this.props.updateTeacher({ teacher_id: this.props.route.params.teacher_id, data, token: this.token}) } + showDatePicker = () => this.setState({ isDatePickerVisible: true }); + hideDatePicker = () => this.setState({ isDatePickerVisible: false }); + + handleConfirm = (date: any, setFieldValue: any) => { + setFieldValue('date_of_birth', date.toISOString().split('T')[0]); + this.hideDatePicker(); + }; render() { @@ -94,6 +103,7 @@ class TeacherUpdate extends React.Component{ let phoneNumber: any let emailId: any let imageInput: any + let date_of_birth: any if (this.props.info.hasOwnProperty('status')) { if (this.props.info.status) { @@ -101,7 +111,8 @@ class TeacherUpdate extends React.Component{ lastname = this.props.route.params.data.lastname phoneNumber = this.props.route.params.data.phone_number emailId = this.props.route.params.data.email_id - imageInput = this.props.route.params.data.image + imageInput = this.props.route.params.data.image, + date_of_birth = this.props.route.params.data.date_of_birth } } @@ -121,11 +132,12 @@ class TeacherUpdate extends React.Component{ lastname: lastname, phone_number: phoneNumber, email_id: emailId, - image:imageInput + image:imageInput, + date_of_birth: '' }} onSubmit={(values, actions) => this.onTeacherUpdate(values, actions)} > - {({ handleChange, handleBlur, handleSubmit, values, errors, touched, isValid, dirty }) => ( + {({ handleChange, handleBlur, handleSubmit, values, errors, touched, isValid, dirty, setFieldValue }) => ( <> First Name * @@ -155,6 +167,22 @@ class TeacherUpdate extends React.Component{ {(errors.email_id && touched.email_id) && {errors.email_id}} + Date of Birth + + + + {values.date_of_birth ? values.date_of_birth : 'Select Date'} + + + {(errors.date_of_birth && touched.date_of_birth) && {errors.date_of_birth}} + + this.handleConfirm(date, setFieldValue)} + onCancel={this.hideDatePicker} + /> + diff --git a/src/screens/class/classCreate.tsx b/src/screens/class/classCreate.tsx index 8afd7ef..37175c0 100644 --- a/src/screens/class/classCreate.tsx +++ b/src/screens/class/classCreate.tsx @@ -169,7 +169,7 @@ class ClassCreate extends React.Component{ this.onSelectChange(itemValue, 'standard', setFieldValue) } placeholder={{ - label: '--Select Standard--', + label: '--Select Section--', value: null, }} useNativeAndroidPickerStyle={false} diff --git a/src/theme/BaseStyles.tsx b/src/theme/BaseStyles.tsx index 84d8ba9..b8e449c 100644 --- a/src/theme/BaseStyles.tsx +++ b/src/theme/BaseStyles.tsx @@ -398,7 +398,7 @@ export const AppStyles = StyleSheet.create({ // flex-grow: 1; color: "white", textAlignVertical:"center", - padding: 10, + padding: 5, textAlign: "center", margin:2, width: 80,