Delete Button working on both Android and ios

This commit is contained in:
Ninjas Code - 4 2023-03-31 08:50:24 +05:00
parent c441ebfd13
commit de0c5dd168
6 changed files with 177 additions and 166 deletions

View File

@ -1,7 +1,7 @@
{
"expo": {
"name": "Enatega",
"version": "1.0.19",
"version": "1.0.20",
"scheme": "enategasinglevendor",
"description": "Enatega is a starter kit food ordering app built in React Native using Expo for IOS and Android. It's made keeping good aesthetics in mind as well keeping the best coding practices in mind. Its fully customisable to easily help you in your next food delivery project. https://market.nativebase.io/view/react-native-food-delivery-backend-app",
"slug": "enategasinglevendor",

1
CustomerApp/src/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules

View File

@ -62,19 +62,26 @@ const CreateAccount = () => {
}
async function onCompleted(data) {
try {
const trackingOpts = {
id: data.login.userId,
usernameOrEmail: data.login.email,
};
Analytics.identify(data.login.userId, trackingOpts);
Analytics.track(Analytics.events.USER_CREATED_ACCOUNT, trackingOpts);
setTokenAsync(data.login.token);
navigation.navigate(NAVIGATION_SCREEN.Menu);
} catch (e) {
console.log(e);
} finally {
if (!data.login.is_active) {
FlashMessage({
message: "Can't Login,This Account is Deleted!",
});
setLoading(false);
} else {
try {
const trackingOpts = {
id: data.login.userId,
usernameOrEmail: data.login.email,
};
Analytics.identify(data.login.userId, trackingOpts);
Analytics.track(Analytics.events.USER_CREATED_ACCOUNT, trackingOpts);
setTokenAsync(data.login.token);
navigation.navigate(NAVIGATION_SCREEN.Menu);
} catch (e) {
console.log(e);
} finally {
setLoading(false);
}
}
}
function onError(error) {
@ -139,6 +146,7 @@ const CreateAccount = () => {
};
mutateLogin(user);
}
loginButtonSetter("Apple");
// signed in
} catch (e) {

View File

@ -49,7 +49,7 @@ function Login() {
const [loading, setLoading] = useState(false);
const [password, setPassword] = useState("123123");
const [emailError, setEmailError] = useState("");
const { setTokenAsync } = useContext(UserContext);
const { setTokenAsync, logout } = useContext(UserContext);
const [passwordError, setPasswordError] = useState(null);
const [mutate] = useMutation(LOGIN, { onCompleted, onError });
@ -99,34 +99,28 @@ function Login() {
return result;
}
async function onCompleted(data) {
try {
const trackingOpts = {
id: data.login.userId,
usernameOrEmail: data.login.email,
};
Analytics.identify(data.login.userId, trackingOpts);
Analytics.track(Analytics.events.USER_LOGGED_IN, trackingOpts);
setTokenAsync(data.login.token);
console.log("Data Before Navigation:", data.login.is_active);
if (!data.login.is_active) {
FlashMessage({
message: "Can't Login,This Account is Deleted!",
});
}
{
data.login.is_active && navigation.navigate(NAVIGATION_SCREEN.Menu);
}
// {
// FlashMessage({
// message: "Can't Login,This Account is Deleted!",
// });
// }
} catch (e) {
console.log(e);
} finally {
if (!data.login.is_active) {
FlashMessage({
message: "Can't Login,This Account is Deleted!",
});
setLoading(false);
} else {
try {
const trackingOpts = {
id: data.login.userId,
usernameOrEmail: data.login.email,
};
Analytics.identify(data.login.userId, trackingOpts);
Analytics.track(Analytics.events.USER_LOGGED_IN, trackingOpts);
setTokenAsync(data.login.token);
console.log("Data Before Navigation:", data.login.is_active);
navigation.navigate(NAVIGATION_SCREEN.Menu);
} catch (e) {
console.log(e);
} finally {
setLoading(false);
}
}
}
function onError(error) {

View File

@ -1,139 +1,139 @@
import { useMutation } from '@apollo/react-hooks'
import { MaterialCommunityIcons } from '@expo/vector-icons'
import { useNavigation, useRoute, useTheme } from '@react-navigation/native'
import gql from 'graphql-tag'
import { useMutation } from "@apollo/react-hooks";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { useNavigation, useRoute, useTheme } from "@react-navigation/native";
import gql from "graphql-tag";
import React, {
useContext,
useEffect,
useLayoutEffect,
useRef,
useState
} from 'react'
useState,
} from "react";
import {
KeyboardAvoidingView,
Platform,
ScrollView,
TouchableOpacity,
View
} from 'react-native'
import { TextField } from 'react-native-material-textfield'
import i18n from '../../../i18n'
import { updateUser } from '../../apollo/server'
View,
} from "react-native";
import { TextField } from "react-native-material-textfield";
import i18n from "../../../i18n";
import { updateUser } from "../../apollo/server";
import {
FlashMessage,
RightButton,
TextDefault,
WrapperView
} from '../../components'
import UserContext from '../../context/User'
import { alignment } from '../../utils/alignment'
import { ICONS_NAME } from '../../utils/constant'
import { moderateScale, scale } from '../../utils/scaling'
import { textStyles } from '../../utils/textStyles'
import ChangePassword from './ChangePassword'
import useStyle from './styles'
WrapperView,
} from "../../components";
import UserContext from "../../context/User";
import { alignment } from "../../utils/alignment";
import { ICONS_NAME } from "../../utils/constant";
import { moderateScale, scale } from "../../utils/scaling";
import { textStyles } from "../../utils/textStyles";
import ChangePassword from "./ChangePassword";
import useStyle from "./styles";
const UPDATEUSER = gql`
${updateUser}
`
`;
function Profile() {
const refName = useRef()
const route = useRoute()
const styles = useStyle()
const refPhone = useRef(null)
const { colors } = useTheme()
const navigation = useNavigation()
const refName = useRef();
const route = useRoute();
const styles = useStyle();
const refPhone = useRef(null);
const { colors } = useTheme();
const navigation = useNavigation();
const [nameError, setNameError] = useState('')
const [phoneError, setPhoneError] = useState('')
const [toggleView, setToggleView] = useState(true)
const [modelVisible, setModalVisible] = useState(false)
const [nameError, setNameError] = useState("");
const [phoneError, setPhoneError] = useState("");
const [toggleView, setToggleView] = useState(true);
const [modelVisible, setModalVisible] = useState(false);
const { profile } = useContext(UserContext)
const backScreen = route.params ? route.params.backScreen : null
const { profile } = useContext(UserContext);
const backScreen = route.params ? route.params.backScreen : null;
const [mutate, { loading: loadingMutation }] = useMutation(UPDATEUSER, {
onCompleted,
onError
})
onError,
});
useLayoutEffect(() => {
navigation.setOptions({
title: 'Profile',
title: "Profile",
headerRight: () => (
<RightButton
icon={toggleView ? ICONS_NAME.Pencil : ICONS_NAME.Cross}
onPress={viewHideAndShow}
iconSize={scale(18)}
/>
)
})
}, [navigation, toggleView])
),
});
}, [navigation, toggleView]);
useEffect(() => {
if (backScreen) {
viewHideAndShow()
setPhoneError('Phone number is required')
viewHideAndShow();
setPhoneError("Phone number is required");
FlashMessage({
message: 'Phone Number is missing'
})
message: "Phone Number is missing",
});
}
}, [backScreen])
}, [backScreen]);
function viewHideAndShow() {
setToggleView(prev => !prev)
setToggleView((prev) => !prev);
}
function onCompleted({ updateUser }) {
if (updateUser) {
FlashMessage({
message: "User's Info Updated"
})
message: "User's Info Updated",
});
if (backScreen) {
navigation.goBack()
navigation.goBack();
}
}
}
function validateInfo() {
// clear errors
setNameError('')
setPhoneError('')
setNameError("");
setPhoneError("");
const name = refName.current.value()
const phone = refPhone.current.value()
const name = refName.current.value();
const phone = refPhone.current.value();
if (name === profile.name && phone === profile.phone && phone.length > 0) {
return
return;
}
let res = true
let res = true;
if (!name.trim()) {
refName.current.focus()
setNameError('Name is required')
res = false
refName.current.focus();
setNameError("Name is required");
res = false;
}
const num = phone.trim().replace('.', '')
const num = phone.trim().replace(".", "");
if (num.length < 11 || num.length > 15 || isNaN(num)) {
setPhoneError('Minimum 11 and maximum 15 characters allowed')
setPhoneError("Minimum 11 and maximum 15 characters allowed");
if (res) {
refPhone.current.focus()
refPhone.current.focus();
}
res = false
res = false;
}
return res
return res;
}
function onError(error) {
try {
if (error.graphQLErrors) {
FlashMessage({
message: error.graphQLErrors[0].message
})
message: error.graphQLErrors[0].message,
});
} else if (error.networkError) {
FlashMessage({
message: error.networkError.result.errors[0].message
})
message: error.networkError.result.errors[0].message,
});
}
} catch (err) {}
}
@ -142,7 +142,7 @@ function Profile() {
return (
<View style={styles.containerInfo}>
<TextField
label={i18n.t('name')}
label={i18n.t("name")}
ref={refName}
editable={false}
defaultValue={profile.name}
@ -151,27 +151,27 @@ function Profile() {
style={{
...textStyles.Medium,
...textStyles.H5,
color: colors.fontMainColor
color: colors.fontMainColor,
}}
maxLength={20}
textColor={colors.fontMainColor}
baseColor={colors.fontSecondColor}
errorColor={colors.errorColor}
tintColor={!nameError ? colors.tagColor : 'red'}
tintColor={!nameError ? colors.tagColor : "red"}
labelTextStyle={{
...textStyles.Normal,
paddingTop: scale(1)
paddingTop: scale(1),
}}
error={nameError}
/>
<View style={{ ...alignment.MTxSmall }}></View>
<TextField
keyboardType={'email-address'}
label={i18n.t('email')}
keyboardType={"email-address"}
label={i18n.t("email")}
style={{
...textStyles.Medium,
...textStyles.H5,
color: colors.fontMainColor
color: colors.fontMainColor,
}}
editable={false}
defaultValue={profile.email}
@ -183,20 +183,20 @@ function Profile() {
tintColor={colors.tagColor}
labelTextStyle={{
...textStyles.Normal,
paddingTop: scale(1)
paddingTop: scale(1),
}}
/>
<View style={{ ...alignment.MTxSmall }}></View>
<TextField
keyboardType={'phone-pad'}
label={i18n.t('phone')}
keyboardType={"phone-pad"}
label={i18n.t("phone")}
ref={refPhone}
editable={false}
defaultValue={profile.phone}
style={{
...textStyles.Medium,
...textStyles.H5,
color: colors.fontMainColor
color: colors.fontMainColor,
}}
labelFontSize={scale(12)}
fontSize={scale(12)}
@ -204,25 +204,26 @@ function Profile() {
textColor={colors.fontMainColor}
baseColor={colors.fontSecondColor}
errorColor={colors.errorColor}
tintColor={!phoneError ? colors.tagColor : 'red'}
tintColor={!phoneError ? colors.tagColor : "red"}
labelTextStyle={{
...textStyles.Normal,
paddingTop: scale(1)
paddingTop: scale(1),
}}
error={phoneError}
/>
<TouchableOpacity
onPress={() => setModalVisible(true)}
style={styles.changePassword}>
style={styles.changePassword}
>
<TextDefault>Change Password</TextDefault>
<MaterialCommunityIcons
name={'pencil'}
name={"pencil"}
size={20}
color={colors.tagColor}
/>
</TouchableOpacity>
</View>
)
);
}
return (
@ -230,29 +231,31 @@ function Profile() {
<ChangePassword
modalVisible={modelVisible}
hideModal={() => {
setModalVisible(false)
setModalVisible(false);
}}
/>
<View style={styles.formContainer}>
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : null}
style={styles.flex}>
behavior={Platform.OS === "ios" ? "padding" : null}
style={styles.flex}
>
<ScrollView style={styles.flex}>
<View style={[styles.formSubContainer]}>
<View
style={{
width: scale(100),
paddingTop: scale(10),
position: 'absolute',
alignItems: 'center',
justifyContent: 'center',
position: "absolute",
alignItems: "center",
justifyContent: "center",
height: scale(100),
top: moderateScale(-50),
borderColor: colors.buttonBackground,
borderWidth: 2,
borderRadius: scale(10),
borderStyle: 'dashed'
}}>
borderStyle: "dashed",
}}
>
<View style={styles.imgContainer}>
<TextDefault textColor={colors.tagColor} bold H1>
{profile.name.substr(0, 1).toUpperCase()}
@ -266,13 +269,13 @@ function Profile() {
<View>
<View style={{ margin: scale(0) }}></View>
<TextField
label={i18n.t('name')}
label={i18n.t("name")}
ref={refName}
defaultValue={profile.name}
style={{
...textStyles.Bold,
...textStyles.H5,
color: colors.fontMainColor
color: colors.fontMainColor,
}}
labelFontSize={scale(12)}
fontSize={scale(12)}
@ -280,21 +283,21 @@ function Profile() {
textColor={colors.fontMainColor}
baseColor={colors.fontSecondColor}
errorColor={colors.errorColor}
tintColor={!nameError ? colors.buttonBackground : 'red'}
tintColor={!nameError ? colors.buttonBackground : "red"}
labelTextStyle={{
...textStyles.Normal,
paddingTop: scale(1)
paddingTop: scale(1),
}}
error={nameError}
/>
<View style={{ ...alignment.MTxSmall }}></View>
<TextField
keyboardType={'email-address'}
label={i18n.t('email')}
keyboardType={"email-address"}
label={i18n.t("email")}
style={{
...textStyles.Bold,
...textStyles.H5,
color: colors.fontMainColor
color: colors.fontMainColor,
}}
editable={false}
defaultValue={profile.email}
@ -306,17 +309,17 @@ function Profile() {
tintColor={colors.buttonBackground}
labelTextStyle={{
...textStyles.Normal,
paddingTop: scale(1)
paddingTop: scale(1),
}}
/>
<View style={{ ...alignment.MTxSmall }}></View>
<TextField
keyboardType={'phone-pad'}
label={i18n.t('phone')}
keyboardType={"phone-pad"}
label={i18n.t("phone")}
style={{
...textStyles.Bold,
...textStyles.H5,
color: colors.fontMainColor
color: colors.fontMainColor,
}}
ref={refPhone}
defaultValue={profile.phone}
@ -326,10 +329,10 @@ function Profile() {
textColor={colors.fontMainColor}
baseColor={colors.fontSecondColor}
errorColor={colors.errorColor}
tintColor={!phoneError ? colors.buttonBackground : 'red'}
tintColor={!phoneError ? colors.buttonBackground : "red"}
labelTextStyle={{
...textStyles.Normal,
paddingTop: scale(1)
paddingTop: scale(1),
}}
error={phoneError}
/>
@ -344,29 +347,34 @@ function Profile() {
mutate({
variables: {
name: refName.current.value(),
phone: refPhone.current.value()
}
})
phone: refPhone.current.value(),
is_active: true,
},
});
}
}}>
}}
>
<TextDefault
textColor={colors.buttonText}
H5
bold
style={[alignment.MTsmall, alignment.MBsmall]}>
{i18n.t('saveBtn')}
style={[alignment.MTsmall, alignment.MBsmall]}
>
{i18n.t("saveBtn")}
</TextDefault>
</TouchableOpacity>
<TouchableOpacity
style={{ alignSelf: 'center', ...alignment.MTsmall }}
style={{ alignSelf: "center", ...alignment.MTsmall }}
activeOpacity={0.7}
onPress={viewHideAndShow}>
onPress={viewHideAndShow}
>
<TextDefault
textColor={colors.fontMainColor}
H5
bold
style={[alignment.MTsmall, alignment.MBsmall]}>
{'Cancel'}
style={[alignment.MTsmall, alignment.MBsmall]}
>
{"Cancel"}
</TextDefault>
</TouchableOpacity>
</View>
@ -375,14 +383,15 @@ function Profile() {
<TextDefault
center
textColor={colors.fontSecondColor}
style={alignment.MBsmall}>
style={alignment.MBsmall}
>
All rights are reserved by Enatega
</TextDefault>
</ScrollView>
</KeyboardAvoidingView>
</View>
</WrapperView>
)
);
}
export default Profile
export default Profile;

View File

@ -70,8 +70,12 @@ function Settings() {
const { profile, logout } = useContext(UserContext);
const [languageName, languageNameSetter] = useState("English");
const [offerNotification, offerNotificationSetter] = useState();
const [orderNotification, orderNotificationSetter] = useState();
const [offerNotification, offerNotificationSetter] = useState(
profile.is_offer_notification
);
const [orderNotification, orderNotificationSetter] = useState(
profile.is_order_notification
);
const [activeRadio, activeRadioSetter] = useState(languageTypes[0].index);
// eslint-disable-next-line no-unused-vars
const [appState, setAppState] = useState(AppState.currentState);
@ -207,19 +211,14 @@ function Settings() {
},
});
}
// console.log(profile.name);
// console.log(profile.phone);
// console.log(profile.is_active);
//console.log(profile.is_activated);
async function updateUserInformation() {
console.log("profile data", profile);
updateUserInfo({
variables: {
//updateUserInput: {
name: profile.name,
phone: profile.phone,
is_active: false,
//is_activated: false,
// },
},
});
}