Skip to content

Commit

Permalink
feat: 로그아웃 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
potados99 committed Oct 8, 2021
1 parent a8c30e6 commit 2c94678
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/domain/usecases/Logout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* This file is part of INU Cafeteria.
*
* Copyright (C) 2021 INU Global App Center <potados99@gmail.com>
*
* INU Cafeteria is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* INU Cafeteria is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import User from '../entities/User';
import UseCase from './UseCase';

class Logout extends UseCase<void, void> {
async onExecute(params: void): Promise<void> {
const user = await User.find();

user?.remove();
}
}

export default new Logout();
14 changes: 14 additions & 0 deletions src/presentation/components/utils/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,17 @@ export function cancelBookingAlert(title: string, message: string, onPress: () =
},
);
}

export function logoutAlert(title: string, message: string, onPress: () => void) {
Alert.alert(
title,
message,
[
{text: '닫기', style: 'cancel'},
{text: '로그아웃', style: 'destructive', onPress},
],
{
cancelable: true,
},
);
}
12 changes: 12 additions & 0 deletions src/presentation/features/login/UserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import User from '../../../domain/entities/User';
import Login from '../../../domain/usecases/Login';
import Logout from '../../../domain/usecases/Logout';
import notify from '../../components/utils/notify';
import AgreePrivacyPolicy from '../../../domain/usecases/AgreePrivacyPolicy';
import {makeAutoObservable} from 'mobx';
Expand Down Expand Up @@ -179,4 +180,15 @@ export default class UserStore {

this.isAgreementRequired = false;
}

/**
* 로그아웃하고 사용자의 정보를 기기에서 삭제합니다.
*/
async logout() {
this.user = undefined;
this.isLoggedIn = false;
this.isLoggedInAsStudent = false;

await Logout.run();
}
}
26 changes: 25 additions & 1 deletion src/presentation/features/support/Main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,35 @@
import React from 'react';
import palette from '../../../res/palette';
import Feather from 'react-native-vector-icons/Feather';
import useStores from '../../../hooks/useStores';
import AntDesign from 'react-native-vector-icons/AntDesign';
import {observer} from 'mobx-react';
import useUserState from '../../../hooks/useUserState';
import {logoutAlert} from '../../../components/utils/alert';
import SupportOption from './SupportOption';
import ItemSeparator from '../../../components/ItemSeparator';
import ContactsButton from './ContactsButton';
import {ScrollView, View} from 'react-native';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import {SupportMainNavigation} from '../SupportScreen';
import {ScrollView, StyleSheet, Text, View} from 'react-native';

type Props = {
navigation: SupportMainNavigation;
};

function Main({navigation}: Props) {
const {isLoggedIn} = useUserState();
const {userStore} = useStores();

const contacts = <ContactsButton navigation={navigation} />;
const separator = <ItemSeparator style={{marginVertical: 12}} />;

const askForLogout = async () => {
logoutAlert('로그아웃', '로그아웃 하시겠습니까?', async () => {
await userStore.logout();
});
};

const qnaOption = (
<SupportOption.Item
icon={['message-square', Feather]}
Expand Down Expand Up @@ -99,6 +108,12 @@ function Main({navigation}: Props) {
</SupportOption.Section>
);

const logout = isLoggedIn && (
<Text style={styles.logoutButton} onPress={askForLogout}>
로그아웃
</Text>
);

return (
<ScrollView style={palette.whiteBackground}>
<View>
Expand All @@ -109,9 +124,18 @@ function Main({navigation}: Props) {
{separator}
{terms}
{separator}
{logout}
</View>
</ScrollView>
);
}

export default observer(Main);

const styles = StyleSheet.create({
logoutButton: {
...palette.textSecondary,
marginStart: 22,
textDecorationLine: 'underline',
},
});

0 comments on commit 2c94678

Please sign in to comment.