Skip to content

Commit

Permalink
Logout functionality (#126)
Browse files Browse the repository at this point in the history
* logout functionallity

* logout functionallity format

* merge temoate branch to logout_functionallity format

* add logout

* add logout gormat

* remove forget pass and sc upload

* remove forget pass and sc upload format

* delete record query

* delete record query fomat

* remove base url

* safe db call for remove user

* safe db call for remove user fomat
  • Loading branch information
Mohan29997 committed Apr 11, 2023
1 parent bc5c6e5 commit dae4533
Show file tree
Hide file tree
Showing 35 changed files with 193 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ This is a micro-framework for React Native which is designed to help simplify de

# Screenshots

​ <img src="screenshots/splashScreen.png" alt="splash" title="Splash Screen" width="150" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img src="screenshots/dashboardscreen.png" alt="dashboard" title="Dashboard Screen" width="150" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="screenshots/loginscreen.png" alt="login" title="Login Screen" width="150" />
​ <img src="screenshots/splashScreen.png" alt="splash" title="Splash Screen" width="150" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img src="screenshots/lightTheme.JPEG" alt="dashboard" title="Dashboard Screen" width="150" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="screenshots/darkTheme.JPEG" alt="login" title="Login Screen" width="150" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img src="screenshots/dash-lightTheme.JPEG" alt="dashboard" title="Dashboard Screen" width="150" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="screenshots/dash-darktheme.JPEG" alt="login" title="Login Screen" width="150" />
1 change: 1 addition & 0 deletions packages/data/src/out/database_port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface DatabasePort {
addUser(params?: { email: string; password: string; token: string }): Promise<boolean>
fetchUserData(data: UserModel): Promise<UserModel>
fetchUserExists(data: UserModel): Promise<boolean>
removeUser(params: { email: string }): Promise<boolean>
}
8 changes: 7 additions & 1 deletion packages/data/src/repositories/user_repository_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class UserRepositoryImpl implements UserRepository {

async login(params?: { email: string; password: string }): Promise<boolean> {
const usermodel: any = await this.network.login({ email: params.email, password: params.password })
console.log(usermodel)
if (usermodel == 'Request failed with status code 403') {
return usermodel
} else {
Expand All @@ -31,9 +30,16 @@ export class UserRepositoryImpl implements UserRepository {
email: params.email
})
}

async fetchUserExists(params?: { email: string }): Promise<boolean> {
return await this.database.fetchUserExists({
email: params.email
})
}

async logout(params?: { email: string }): Promise<boolean> {
return await this.database.removeUser({
email: params.email
})
}
}
10 changes: 10 additions & 0 deletions packages/database-watermelon/src/dao/user_dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ export class UserDao extends BaseDao<DbUserModel> {
if (userCount > 0) return true
else return false
}

async deleteUser(data: { email: string }): Promise<boolean> {
await safeDbCall(
this.attachedDatabase.write(async () => {
const response: any = await this.databaseData.query(Q.where('email', Q.eq(data.email))).destroyAllPermanently()
return response
})
)
return true
}
}
5 changes: 5 additions & 0 deletions packages/database-watermelon/src/database_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ class DatabaseAdapter implements DatabasePort {
email: data.email
})
}
async removeUser(params: { email: string }): Promise<boolean> {
return await this.databases.userDao.deleteUser({
email: params.email
})
}
}
export default DatabaseAdapter
10 changes: 8 additions & 2 deletions packages/domain/src/di/domain_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { UserRepository } from './../repository/user_repository'
import { DataModule } from 'data'
import { Graph, ObjectGraph, Provides, Singleton } from 'di'
import { LoginUseCase } from '../usecases/login_user_usecase'
import { FetchUserDataUseCase, FetchUserExistsUseCase } from '../domain'
import { LogoutUseCase } from '../usecases/logout_usecase'
import { FetchUserDataUseCase } from '../usecases/user_details_usecase'
import { FetchUserExistsUseCase } from '../usecases/user_present_data_usecase'

@Singleton()
@Graph({ subgraphs: [DataModule] })
export class DomainModule extends ObjectGraph {
@Provides()
providesLoginUseCase(provideUserRepository: UserRepository): LoginUseCase {
provideLoginUseCase(provideUserRepository: UserRepository): LoginUseCase {
return new LoginUseCase(provideUserRepository)
}
@Provides()
Expand All @@ -19,4 +21,8 @@ export class DomainModule extends ObjectGraph {
provideUserExistsUseCase(provideUserRepository: UserRepository): FetchUserExistsUseCase {
return new FetchUserExistsUseCase(provideUserRepository)
}
@Provides()
provideLogoutUseCase(provideUserRepository: UserRepository): LogoutUseCase {
return new LogoutUseCase(provideUserRepository)
}
}
5 changes: 4 additions & 1 deletion packages/domain/src/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FetchUserDataUseCase, FetchUserDataUseCaseParams } from './usecases/use
import { LoginUseCase, LoginParams } from './usecases/login_user_usecase'
import { DomainModule } from './di/domain_module'
import { UserRepository } from './repository/user_repository'
import { LogoutUseCase, LogoutParams } from './usecases/logout_usecase'

export {
DomainModule,
Expand All @@ -12,5 +13,7 @@ export {
FetchUserDataUseCase,
FetchUserDataUseCaseParams,
FetchUserExistsUseCase,
FetchUserExistsUseCaseParams
FetchUserExistsUseCaseParams,
LogoutUseCase,
LogoutParams
}
1 change: 1 addition & 0 deletions packages/domain/src/repository/user_repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface UserRepository {
login(params?: { email: string; password: string }): Promise<boolean>
fetchUserData(params?: { email: string }): Promise<UserModel>
fetchUserExists(params?: { email: string }): Promise<boolean>
logout(params?: { email: string }): Promise<boolean>
}
29 changes: 29 additions & 0 deletions packages/domain/src/usecases/logout_usecase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { UserRepository } from '../repository/user_repository'
import { FutureUseCase } from './base/base_usecase'
import { Params } from './base/params'

export class LogoutUseCase extends FutureUseCase<LogoutParams, boolean> {
private readonly userRepository: UserRepository
constructor(repo: UserRepository) {
super()
this.userRepository = repo
}
async execute(params?: LogoutParams): Promise<boolean> {
if (params?.verify()) {
return await this.userRepository.logout({
email: params.email
})
} else return false
}
}
export class LogoutParams extends Params {
readonly email?: string

constructor(params?: { email: string }) {
super({})
this.email = params.email
}
verify(): boolean {
return true
}
}
3 changes: 2 additions & 1 deletion packages/localisation/lib/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"getThere": "Get There.",
"getStarted": "Get Started",
"noInput": "please enter data or a valid data",
"errorMessage": "please enter proper email and password"
"errorMessage": "please enter proper email and password",
"logout": "Logout"
}
4 changes: 0 additions & 4 deletions packages/mobile/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import SplashScreen from 'react-native-splash-screen'
import { ThemeProvider } from './src/theme/themeprovider'

class App extends Component {
componentDidMount(): void {
SplashScreen.hide()
}

render() {
return (
<ThemeProvider>
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/src/assets/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const Images = {
icon: require('./images/logo.png'),
car: require('./images/car.png'),
carBlack: require('./images/carblack.png'),
iconBlack: require('./images/logoblack.png')
iconBlack: require('./images/logoblack.png'),
blackLogout: require('./images/blacklogouticon.png'),
whiteLogout: require('./images/whitelogouticon.png')
}
export default Images
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions packages/mobile/src/feature/dashboard/dashboard_screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,35 @@ import { AppButton } from '../../widgets/app_button/app_button'
import { useTheme } from '../../theme/themeprovider'
import { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { logoutAction } from 'presentation'
import { useNavigation } from '@react-navigation/native'
import RoutePaths from '../../navigation/router_path'
import { fetchUserAction } from 'presentation'

const DashboardScreen = () => {
const { theme, isDark } = useTheme()
const [lodingState, setLodingState] = useState(false)
const navigation: any = useNavigation()
const databaseEmail: any = useSelector((state: any) => state?.userData?.data?.payload)
const logoutData: any = useSelector((state: any) => state?.logout?.data?.payload)
const dispatch = useDispatch()
useEffect(() => {
dispatch(fetchUserAction({}))
}, [])
const onLogoutClick = () => {
dispatch(logoutAction({ databaseEmail }))
}
return (
<View style={style.mainView}>
<View style={[style.secView, { backgroundColor: theme.secondaryColor }]}>
<TouchableOpacity style={style.logoutButton} onPress={() => onLogoutClick()}>
<Image
source={isDark ? Images.blackLogout : Images.whiteLogout}
style={style.logoutStyle}
resizeMode="contain"
/>
</TouchableOpacity>
<Text style={[style.uberText, { color: theme.textColor }]}>{`${i18n.t('uber')} - ${databaseEmail}`}</Text>
<Text style={[style.getText, { color: theme.textColor }]}>{i18n.t('getThere')}</Text>

<Image source={isDark ? Images.carBlack : Images.car} style={style.carStyle} resizeMode="contain" />
</View>
<View style={style.thirdView}>
Expand Down
17 changes: 14 additions & 3 deletions packages/mobile/src/feature/dashboard/dashboard_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export default StyleSheet.create({
height: '75%'
},
uberText: {
fontSize: 40,
fontSize: 28,
textAlign: 'center',
marginTop: '15%',
marginTop: '10%',
fontFamily: 'Poppins-Regular'
},
getText: {
Expand All @@ -33,7 +33,18 @@ export default StyleSheet.create({
height: 350,
alignSelf: 'center',
position: 'absolute',
bottom: 20,
bottom: 30,
right: -100
},
logoutStyle: {
marginTop: 10,
width: 30,
height: 30,
alignSelf: 'flex-end'
},
logoutButton: {
width: 30,
height: 30,
alignSelf: 'flex-end'
}
})
8 changes: 0 additions & 8 deletions packages/mobile/src/feature/login/login_screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ const LoginScreen = () => {
else setLodingState(false)
}, [loginData])

useEffect(() => {
if (loginData?.status == Status?.success) navigation.navigate(RoutePaths.dashboard)
else if (loginData?.status == Status?.error) alert(i18n.t('noInput'))
}, [loginData])

return (
<View style={[style.mainView, { backgroundColor: theme.backgroundCOlor }]}>
<View style={style.secView}>
Expand All @@ -51,9 +46,6 @@ const LoginScreen = () => {
<View style={style.buttonVIew}>
<AppButton loadingState={loadingState} value={'login'} saveData={() => saveData()} />
</View>
<TouchableOpacity>
<Text style={[style.forgetpass, { color: theme.textColor }]}>{i18n.t('forgetPassword')}</Text>
</TouchableOpacity>
</View>
)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/mobile/src/feature/login/login_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default StyleSheet.create({
height: Dimensions.get('window').height
},
secView: {
width: '100%'
width: '100%',
marginTop: '10%'
},
loginText: {
fontSize: 24,
Expand Down
20 changes: 16 additions & 4 deletions packages/mobile/src/navigation/app_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,36 @@ import DashboardScreen from '../feature/dashboard/dashboard_screen'
import LoginScreen from '../feature/login/login_screen'
import RoutePaths from './router_path'
import { useDispatch, useSelector } from 'react-redux'
import { fetchUserExistsAction } from 'presentation'
import { Status, fetchUserExistsAction } from 'presentation'
import SplashScreen from 'react-native-splash-screen'

const AppRouter = () => {
const Stack = createNativeStackNavigator()
const databaseEmail: any = useSelector((state: any) => state?.userPresentData?.data?.payload)
const databaseEmail: any = useSelector((state: any) => state?.userExistsData)
const logoutData: any = useSelector((state: any) => state?.logout?.data?.payload)

const dispatch = useDispatch()
useEffect(() => {
dispatch(fetchUserExistsAction({}))
}, [])

useEffect(() => {
if (databaseEmail?.status == Status.success) {
SplashScreen.hide()
}
}, [databaseEmail?.status])
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false
}}
>
{!databaseEmail && <Stack.Screen name={RoutePaths.login} component={LoginScreen} />}
<Stack.Screen name={RoutePaths.dashboard} component={DashboardScreen} />
{(!databaseEmail?.data?.payload && databaseEmail?.status == Status.success) || logoutData ? (
<Stack.Screen name={RoutePaths.login} component={LoginScreen} />
) : (
<Stack.Screen name={RoutePaths.dashboard} component={DashboardScreen} />
)}
</Stack.Navigator>
</NavigationContainer>
)
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/src/widgets/app_button/app_button_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export default StyleSheet.create({
buttonView: {
alignSelf: 'center',
width: '80%',
height: 50,
borderRadius: 15,
justifyContent: 'center',
paddingVertical: '5%'
justifyContent: 'center'
},
buttonText: {
fontSize: 24,
Expand Down
6 changes: 5 additions & 1 deletion packages/presentation/src/feature/login/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import { Obsidian } from 'di'
import { put } from 'redux-saga/effects'
import { LOGIN } from './actions'
import { LoginParams } from 'domain-layer'
import { LOGOUT } from '../logout/action'
import { FETCH_USER_EXISTS } from '../userpresent/action'

function* loginSaga(action) {
const mesage = 'Request failed with status code 403'
try {
const data: any = yield Obsidian.obtain(DomainModule)
.providesLoginUseCase()
.provideLoginUseCase()
.execute(new LoginParams({ email: action?.params?.data?.email, password: action?.params?.data?.password }))
if (data == mesage || data == false) {
yield put({ type: LOGIN.failure, payload: data })
} else {
yield put({ type: LOGIN.success, payload: data })
yield put({ type: LOGOUT.failure, payload: false })
yield put({ type: FETCH_USER_EXISTS.success, payload: true })
}
} catch (e) {
console.log(e)
Expand Down
10 changes: 10 additions & 0 deletions packages/presentation/src/feature/logout/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export enum LOGOUT {
request = 'LOGOUT_REQUEST',
success = 'LOGOUT_SUCCESS',
failure = 'LOGOUT_FAILURE'
}

export const logoutAction = params => ({
type: LOGOUT.request,
params
})
23 changes: 23 additions & 0 deletions packages/presentation/src/feature/logout/reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import data from 'packages/data/lib/data'
import { Resource } from '../../utils/resource'
import { LOGOUT } from './action'

const logoutReducer = (initialState = Resource.none, action) => {
switch (action.type) {
case LOGOUT.request:
return Resource.loading()

case LOGOUT.success:
return Resource.success({
data: action
})

case LOGOUT.failure:
return Resource.error({
error: 'User Not logged in'
})
default:
return initialState
}
}
export default logoutReducer

0 comments on commit dae4533

Please sign in to comment.