Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/rn-api/src/components/InputPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityI
import {responsiveHeight} from '../themes/metrics'
import TextInputView from './TextInputView'

const PasswordInput = props => {
export const PasswordInput = props => {
const {style, title, onChangeText, value, defaultValue, ...rest} = props
const [showPassword, setShowPassword] = useState(false)

Expand Down Expand Up @@ -59,5 +59,3 @@ const styles = StyleSheet.create({
height: responsiveHeight(40),
},
})

export default React.memo(PasswordInput)
4 changes: 1 addition & 3 deletions packages/rn-api/src/components/InputWIthLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import {responsiveHeight} from '../themes/metrics'
import TextInputView from './TextInputView'

const InputWithLabel = props => {
export const InputWithLabel = props => {
const {title, style, onChangeText, value, defaultValue, ...rest} = props
return (
<View style={[styles.container, style]}>
Expand Down Expand Up @@ -35,5 +35,3 @@ const styles = StyleSheet.create({
borderRadius: 5,
},
})

export default React.memo(InputWithLabel)
2 changes: 2 additions & 0 deletions packages/rn-api/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export * from './IndicatorDialog'
export * from './Row'
export * from './ScreenContainer'
export * from './Toast'
export * from './InputWithLabel'
export * from './InputPassword'
13 changes: 13 additions & 0 deletions packages/rn-api/src/models/ApiResponseModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class ApiResponseModel {
constructor(message, errorCode, data, isSuccess) {
this.message = message
this.errorCode = errorCode
this.data = data
this.isSuccess = isSuccess
}

static parseFromJson = payload => {
const {message, errorCode, data, isSuccess} = payload
return new ApiResponseModel(message, errorCode, data, isSuccess)
}
}
2 changes: 2 additions & 0 deletions packages/rn-api/src/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './user'
export * from './ApiResponseModel'
18 changes: 18 additions & 0 deletions packages/rn-api/src/models/user/PasswordModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {ApiResponseModel} from '../ApiResponseModel'

export class PasswordModel extends ApiResponseModel {
constructor(message, errorCode, data, isSuccess) {
super(message, errorCode, data, isSuccess)
}

static parseFromJson = payload => {
const {message, errorCode, data, isSuccess} = payload

// Customize the 'data' property in PasswordModel
const customizedData = {
password: data?.password ?? '',
}

return new PasswordModel(message, errorCode, customizedData, isSuccess)
}
}
1 change: 1 addition & 0 deletions packages/rn-api/src/models/user/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './PasswordModel'
3 changes: 3 additions & 0 deletions packages/rn-api/src/navigation/RouteKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default {
LoginScreen: 'LoginScreen',
SignUpScreen: 'SignUpScreen',
HomeScreen: 'HomeScreen',
ForgotPasswordScreen: 'ForgotPasswordScreen',
ResetPasswordScreen: 'ResetPasswordScreen',
ChangePasswordScreen: 'ChangePasswordScreen',

/** Stack */
AuthStack: 'AuthStack',
Expand Down
14 changes: 13 additions & 1 deletion packages/rn-api/src/navigation/ScreenService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import RouteKey from './RouteKey'
import {SignUpScreen, LoginScreen} from '../screens'
import {
SignUpScreen,
LoginScreen,
ForgotPasswordScreen,
ResetPasswordScreen,
ChangePasswordScreen,
} from '../screens'
// Screen Import
import HomeScreen from '../screens/HomeComponent/HomeScreen'
import {colors} from '../themes'
Expand All @@ -13,6 +19,12 @@ export const screenMatch = screen => {
return SignUpScreen
case RouteKey.HomeScreen:
return HomeScreen
case RouteKey.ForgotPasswordScreen:
return ForgotPasswordScreen
case RouteKey.ResetPasswordScreen:
return ResetPasswordScreen
case RouteKey.ChangePasswordScreen:
return ChangePasswordScreen
default:
return ''
}
Expand Down
15 changes: 15 additions & 0 deletions packages/rn-api/src/navigation/StackNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ export const AuthNavigator = () => (
component={screenMatch(RouteKey.SignUpScreen)}
options={optionsMatch}
/>
<Stack.Screen
name={RouteKey.ForgotPasswordScreen}
component={screenMatch(RouteKey.ForgotPasswordScreen)}
options={optionsMatch}
/>
<Stack.Screen
name={RouteKey.ResetPasswordScreen}
component={screenMatch(RouteKey.ResetPasswordScreen)}
options={optionsMatch}
/>
<Stack.Screen
name={RouteKey.ChangePasswordScreen}
component={screenMatch(RouteKey.ChangePasswordScreen)}
options={optionsMatch}
/>
</Stack.Navigator>
)

Expand Down
95 changes: 95 additions & 0 deletions packages/rn-api/src/screens/AuthComponent/ChangePasswordScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React, {useCallback, useReducer} from 'react'
import {ScreenContainer, PasswordInput} from '../../components'
import {Text, StyleSheet, View, TouchableOpacity} from 'react-native'
import {responsiveHeight, colors} from '../../themes'
import {useDispatch} from 'react-redux'
import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view'
import {userActions} from '../../store/reducers'

export const ChangePasswordScreen = () => {
const dispatch = useDispatch()
const [inputValue, setInputValue] = useReducer((prev, next) => ({...prev, ...next}), {
newPassword: '',
confirmPassword: '',
oldPassword: '',
})

const onSaveChangePassword = useCallback(() => {
dispatch(
userActions.changePasswordHandle({
newPassword: inputValue.newPassword,
confirmPassword: inputValue.confirmPassword,
oldPassword: inputValue.oldPassword,
}),
)
}, [inputValue, dispatch])

const onChangeNewPass = useCallback(text => {
setInputValue({newPassword: text})
}, [])

const onChangePassword = useCallback(text => {
setInputValue({confirmPassword: text})
}, [])

const onChangeOldPassword = useCallback(text => {
setInputValue({oldPassword: text})
}, [])

return (
<ScreenContainer style={styles.container}>
<KeyboardAwareScrollView>
<Text style={styles.titleText}>Change Password</Text>
<PasswordInput onChangeText={onChangeNewPass} defaultValue={inputValue.id} title={'New Password'} />
<View style={styles.passwordSection}>
<PasswordInput
onChangeText={onChangePassword}
defaultValue={inputValue.password}
title="Confirm Password"
/>
</View>
<View style={styles.passwordSection}>
<PasswordInput
onChangeText={onChangeOldPassword}
defaultValue={inputValue.password}
title="Old Password"
/>
</View>
<TouchableOpacity style={styles.button} onPress={onSaveChangePassword}>
<Text>SAVE</Text>
</TouchableOpacity>
</KeyboardAwareScrollView>
</ScreenContainer>
)
}

const styles = StyleSheet.create({
container: {
padding: responsiveHeight(10),
alignItems: 'center',
},
titleText: {
fontSize: responsiveHeight(25),
fontWeight: '600',
marginVertical: responsiveHeight(20),
},
passwordSection: {
marginTop: responsiveHeight(10),
},
button: {
backgroundColor: colors.primary,
width: '100%',
height: responsiveHeight(40),
marginTop: responsiveHeight(10),
alignItems: 'center',
justifyContent: 'center',
borderRadius: 10,
},
forgotPassword: {
fontSize: responsiveHeight(18),
marginVertical: responsiveHeight(10),
alignSelf: 'flex-end',
color: colors.primary,
textDecorationLine: 'underline',
},
})
66 changes: 66 additions & 0 deletions packages/rn-api/src/screens/AuthComponent/ForgotPasswordScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, {useCallback, useState} from 'react'
import {ScreenContainer, InputWithLabel} from '../../components'
import {Text, StyleSheet, TouchableOpacity} from 'react-native'
import {responsiveHeight, colors} from '../../themes'
import {useDispatch} from 'react-redux'
import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view'
import {userActions} from '../../store/reducers'

export const ForgotPasswordScreen = () => {
const dispatch = useDispatch()
const [email, setEmail] = useState('')

const onForgotPassword = useCallback(() => {
dispatch(userActions.forgotPasswordHandle({email}))
}, [email, dispatch])

const onChangeEmail = useCallback(text => {
setEmail(text)
}, [])

return (
<ScreenContainer style={styles.container}>
<KeyboardAwareScrollView style={styles.contentSection}>
<Text style={styles.titleText}>Forgot Password</Text>
<InputWithLabel onChangeText={onChangeEmail} defaultValue={email} title={'Email'} />
<TouchableOpacity style={styles.button} onPress={onForgotPassword}>
<Text>SAVE</Text>
</TouchableOpacity>
</KeyboardAwareScrollView>
</ScreenContainer>
)
}

const styles = StyleSheet.create({
container: {
padding: responsiveHeight(10),
alignItems: 'center',
},
contentSection: {
width: '100%',
},
titleText: {
fontSize: responsiveHeight(25),
fontWeight: '600',
marginVertical: responsiveHeight(20),
},
passwordSection: {
marginTop: responsiveHeight(10),
},
button: {
backgroundColor: colors.primary,
width: '100%',
height: responsiveHeight(40),
marginTop: responsiveHeight(10),
alignItems: 'center',
justifyContent: 'center',
borderRadius: 10,
},
forgotPassword: {
fontSize: responsiveHeight(18),
marginVertical: responsiveHeight(10),
alignSelf: 'flex-end',
color: colors.primary,
textDecorationLine: 'underline',
},
})
95 changes: 92 additions & 3 deletions packages/rn-api/src/screens/AuthComponent/LoginScreen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,93 @@
import React from 'react'
import {ScreenContainer} from '../../components'
import React, {useCallback, useReducer} from 'react'
import {ScreenContainer, InputWithLabel, PasswordInput} from '../../components'
import {Text, StyleSheet, View, TouchableOpacity} from 'react-native'
import {responsiveHeight, colors} from '../../themes'
import {useDispatch} from 'react-redux'
import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view'
import {userActions} from '../../store/reducers'
import {navigate} from '../../navigation/NavigationService'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorten import

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

import RouteKey from '../../navigation/RouteKey'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorten import

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


export const LoginScreen = () => <ScreenContainer />
export const LoginScreen = () => {
const dispatch = useDispatch()
const [inputValue, setInputValue] = useReducer((prev, next) => ({...prev, ...next}), {
email: '',
password: '',
})

const onPressLogin = useCallback(() => {
dispatch(userActions.userLogin())
}, [dispatch])

const onChangeEmail = useCallback(text => {
setInputValue({email: text})
}, [])

const onChangePassword = useCallback(text => {
setInputValue({password: text})
}, [])

return (
<ScreenContainer style={styles.container}>
<KeyboardAwareScrollView>
<Text style={styles.titleText}>Login Screen</Text>
<InputWithLabel onChangeText={onChangeEmail} value={inputValue.id} title={'Email'} />
<View style={styles.passwordSection}>
<PasswordInput onChangeText={onChangePassword} value={inputValue.password} title="Password" />
</View>
<TouchableOpacity
onPress={() => {
navigate(RouteKey.ChangePasswordScreen)
}}>
<Text style={styles.forgotPassword}>Change Password</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
navigate(RouteKey.ForgotPasswordScreen)
}}>
<Text style={styles.forgotPassword}>Forgot Password</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
navigate(RouteKey.ResetPasswordScreen)
}}>
<Text style={styles.forgotPassword}>Reset Password</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={onPressLogin}>
<Text>SAVE</Text>
</TouchableOpacity>
</KeyboardAwareScrollView>
</ScreenContainer>
)
}

const styles = StyleSheet.create({
container: {
padding: responsiveHeight(10),
alignItems: 'center',
},
titleText: {
fontSize: responsiveHeight(25),
fontWeight: '600',
marginVertical: responsiveHeight(20),
},
passwordSection: {
marginTop: responsiveHeight(10),
},
button: {
backgroundColor: colors.primary,
width: '100%',
height: responsiveHeight(40),
marginTop: responsiveHeight(10),
alignItems: 'center',
justifyContent: 'center',
borderRadius: 10,
},
forgotPassword: {
fontSize: responsiveHeight(18),
marginVertical: responsiveHeight(10),
alignSelf: 'flex-end',
color: colors.primary,
textDecorationLine: 'underline',
},
})
Loading