Skip to content
Merged
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
Binary file modified .yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion src/components/cards/QrCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const QrCard = ({
style={{ width: '100%' }}
showsVerticalScrollIndicator={false}
>
<Text style={styles.qrTitle}>์ž„์‹œ ์ถœ์ž… QR</Text>
<Text style={styles.qrTitle}>์ถœ์ž… QR</Text>
<QRCode
value={qrData}
// value={qrData_sample}
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/MyAccessDetailModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const MyAccessDetailModal = ({ isVisible, onClose, onConfirm, data }) => {
<Text style={styles.modalText}>๋ฐฉ๋ฌธ์ž: {data.visitorType}</Text>
<Text style={styles.modalText}>์‹œ์ž‘์ผ: {data.startDate}</Text>
<Text style={styles.modalText}>๋งŒ๋ฃŒ์ผ: {data.expireDate}</Text>
<Text style={styles.modalText}>์Šน์ธ ์—ฌ๋ถ€: {data.approval}</Text>
<Text style={styles.modalText}>์Šน์ธ ์—ฌ๋ถ€: {data.approval.replace(/\n/g, '')}</Text>
<Text style={styles.modalText}>ํ™˜์ž ๋ฒˆํ˜ธ: {data.patientNumber}</Text>
</View>
<View style={[styles.textContainer, { alignItems: 'center' }]}>
Expand Down
14 changes: 11 additions & 3 deletions src/components/modals/PasswordConfirmModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { useState, useEffect } from 'react';
import { View, Text, Modal } from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import { verifyPassword } from '../../apis/PasswordApi';
import { useAuthStore } from '../../stores/authStore';
import { useModalStore } from '../../stores/modalStore';
import { styles } from './styles/PasswordConfirmModal.styles';
import NormalInput from '../textinputs/NormalInput';
import NormalButton from '../buttons/NormalButton';
import WaveHeader from '../headers/WaveHeader';

const PasswordConfirmModal = ({ navigationRef }) => {
const { isPasswordModalVisible, pendingTab, prevTab, hidePasswordModal } = useModalStore();
const { isPasswordModalVisible, pendingTab, prevTab, isFromAppState, hidePasswordModal } =
useModalStore();
const [password, setPassword] = useState('');
const [errorText, setErrorText] = useState(''); // mediumText ErrorText
const setLastAuthTime = useAuthStore((state) => state.setLastAuthTime);

useEffect(() => {
if (isPasswordModalVisible) {
Expand Down Expand Up @@ -43,7 +46,8 @@ const PasswordConfirmModal = ({ navigationRef }) => {

try {
await verifyPassword(password);

// ์ธ์ฆ ์„ฑ๊ณต ์‹œ ์ธ์ฆ ์‹œ๊ฐ ์ €์žฅ
setLastAuthTime(Date.now());
navigationRef.current?.navigate(pendingTab);
hidePasswordModal();
} catch (error) {
Expand All @@ -53,7 +57,11 @@ const PasswordConfirmModal = ({ navigationRef }) => {

const onClosePasswordModal = () => {
hidePasswordModal();
navigationRef.current?.navigate(prevTab);
if (isFromAppState) {
navigationRef.current?.navigate('MainPage'); // ํ™ˆ์œผ๋กœ ๊ฐ•์ œ ์ด๋™
} else {
navigationRef.current?.navigate(prevTab); // ์ด์ „ ํƒญ์œผ๋กœ ์ด๋™
}
};

return (
Expand Down
36 changes: 31 additions & 5 deletions src/navigations/AppNavigator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useRef } from 'react';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { StatusBar } from 'react-native';
import { StatusBar, AppState } from 'react-native';
import { NavigationContainer, DefaultTheme } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import Ionicons from 'react-native-vector-icons/Ionicons';
Expand Down Expand Up @@ -28,6 +28,7 @@ import AccessRequestRolePage from '../pages/AccessRequestRolePage';

const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
const PASSWORD_AUTH_VALID_MS = 5 * 60 * 1000; // ๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌ์ธ์ฆ ์‹œ๊ฐ„ (5๋ถ„)

// StatusBar ์Šคํƒ€์ผ ์„ค์ •
const WHITE_TAB_SCREENS = ['MainPage', 'WelcomePage'];
Expand Down Expand Up @@ -106,11 +107,13 @@ export default function AppNavigator() {
clearAccessToken,
_hasHydrated, // hydration flag
} = useAuthStore();
const lastAuthTime = useAuthStore((state) => state.lastAuthTime);
const appState = useRef(AppState.currentState);

const showPasswordModal = useModalStore((state) => state.showPasswordModal);

// ํ˜„์žฌ ๋ผ์šฐํŠธ ์ด๋ฆ„์„ ์ €์žฅํ•˜๋Š” state
const [currentRouteName, setCurrentRouteName] = useState('WelcomePage');
const [currentRouteName, setCurrentRouteName] = useState(isLoggedIn ? 'MainPage' : 'WelcomePage');

// ์•Œ๋ฆผ ์ฝ์Œ ์—ฌ๋ถ€ ๊ด€๋ จ
const { hasUnread, markAllAsRead } = useNoticeBadge();
Expand Down Expand Up @@ -143,10 +146,33 @@ export default function AppNavigator() {

// ํƒญ ํด๋ฆญ ์‹œ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ชจ๋‹ฌ ํ˜ธ์ถœ
const handleTabPress = (e, tabName) => {
e.preventDefault();
showPasswordModal(tabName, currentRouteName || 'MainPage');
if (!lastAuthTime || Date.now() - lastAuthTime > PASSWORD_AUTH_VALID_MS) {
e.preventDefault();
showPasswordModal(tabName, currentRouteName || 'MainPage');
}
};

// ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ชจ๋‹ฌ ๋ฐฑ๊ทธ๋ผ์šด๋“œ -> ํฌ๊ทธ๋ผ์šด๋“œ ๋ณ€๊ฒฝ์‹œ ์ ์šฉ
useEffect(() => {
const subscription = AppState.addEventListener('change', (nextAppState) => {
// ํฌ๊ทธ๋ผ์šด๋“œ๋กœ ๋Œ์•„์˜ฌ ๋•Œ
if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
// ํ˜„์žฌ ๋ผ์šฐํŠธ๊ฐ€ ๋งˆ์ดํŽ˜์ด์ง€(ํ˜น์€ ๋งˆ์ดํŽ˜์ด์ง€ stack ๋‚ด๋ถ€)๋ผ๋ฉด
if (currentRouteName === 'MyPage' || currentRouteName === 'MyPageStack') {
// ์ธ์ฆ ๋งŒ๋ฃŒ๋์œผ๋ฉด ๋ชจ๋‹ฌ ๋„์šฐ๊ธฐ
if (!lastAuthTime || Date.now() - lastAuthTime > PASSWORD_AUTH_VALID_MS) {
showPasswordModal('MyPageStack', currentRouteName, true);
}
}
}
appState.current = nextAppState;
});

return () => {
subscription.remove();
};
}, [currentRouteName, lastAuthTime]);

const navTheme = {
...DefaultTheme,
colors: {
Expand Down
5 changes: 5 additions & 0 deletions src/stores/authStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export const useAuthStore = create(
// hydration(์Šคํ† ๋ฆฌ์ง€ ๋ณต์›) ์ƒํƒœ
_hasHydrated: false,
setHasHydrated: (state) => set({ _hasHydrated: state }),

//์ธ์ฆ ์‹œ๊ฐ ๊ด€๋ฆฌ
lastAuthTime: 0,
setLastAuthTime: (time) => set({ lastAuthTime: time }),
}),
{
name: 'auth-storage',
Expand All @@ -47,6 +51,7 @@ export const useAuthStore = create(
accessToken: state.accessToken,
isLoggedIn: state.isLoggedIn,
userInfo: state.userInfo,
lastAuthTime: state.lastAuthTime,
}),
// ๋ณต์› ์™„๋ฃŒ ์‹œ _hasHydrated๋ฅผ true๋กœ ๋ณ€๊ฒฝ
onRehydrateStorage: () => (state, error) => {
Expand Down
5 changes: 4 additions & 1 deletion src/stores/modalStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ export const useModalStore = create((set) => ({
isPasswordModalVisible: false,
pendingTab: null, // ์ด๋™ ์‹œ๋„ํ•œ ํƒญ ์ด๋ฆ„
prevTab: '', // ์ด์ „ ํƒญ ์ด๋ฆ„
showPasswordModal: (tabName, prevTab) =>
isFromAppState: false, // ๋ชจ๋‹ฌ ์ถœํ˜„ ์ด์œ 
showPasswordModal: (tabName, prevTab, isFromAppState = false) =>
set({
isPasswordModalVisible: true,
pendingTab: tabName,
prevTab,
isFromAppState,
}),
hidePasswordModal: () =>
set({
isPasswordModalVisible: false,
pendingTab: null,
isFromAppState: false, // ๋‹ซ์„ ๋•Œ ์ดˆ๊ธฐํ™”
}),
}));