-
Notifications
You must be signed in to change notification settings - Fork 5
feat: changePassword, forgotPassword, resetPassword apis #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anhle10051996
wants to merge
4
commits into
main
Choose a base branch
from
feature/password_apis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './user' | ||
| export * from './ApiResponseModel' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './PasswordModel' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/rn-api/src/screens/AuthComponent/ChangePasswordScreen.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
66
packages/rn-api/src/screens/AuthComponent/ForgotPasswordScreen.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | ||
| import RouteKey from '../../navigation/RouteKey' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shorten import
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', | ||
| }, | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shorten import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated