Fix form keyboard issues and sticky footers in agent screens
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../app/hooks';
|
||||
import { bootstrapAuthSession, logoutSession } from '../modules/auth/store/authThunk';
|
||||
import { selectIsAuthenticated } from '../modules/auth/store/authSelectors';
|
||||
import { seedDashboardState } from '../modules/home/store/accountThunk';
|
||||
import { seedBeneficiaries } from '../modules/transfer/store/transferThunk';
|
||||
import { seedRecentPayees } from '../modules/payments/store/paymentsThunk';
|
||||
import { seedDepositProducts } from '../modules/deposit/store/depositThunk';
|
||||
import {
|
||||
seedServiceRequests,
|
||||
seedSupportMessages,
|
||||
} from '../modules/services/store/serviceThunk';
|
||||
import { seedLoanProducts } from '../modules/loan/store/loanThunk';
|
||||
import { seedInsurancePlans } from '../modules/insurance/store/insuranceThunk';
|
||||
import { seedCards } from '../modules/cards/store/cardsThunk';
|
||||
import { seedUserProfile } from '../modules/profile/store/userThunk';
|
||||
import { markAppReady } from '../modules/ui/store/uiThunk';
|
||||
import { registerUnauthorizedHandler } from '../services/api/interceptors';
|
||||
import { registerForPushNotifications } from '../services/notifications/pushNotifications';
|
||||
import { useSessionTimeout } from './useSessionTimeout';
|
||||
import { useToast } from './useToast';
|
||||
|
||||
/** Dispatch all seed thunks to populate demo/mock data. */
|
||||
const seedAllData = (dispatch: ReturnType<typeof useAppDispatch>) => {
|
||||
dispatch(seedUserProfile());
|
||||
dispatch(seedDashboardState());
|
||||
dispatch(seedBeneficiaries());
|
||||
dispatch(seedRecentPayees());
|
||||
dispatch(seedDepositProducts());
|
||||
dispatch(seedServiceRequests());
|
||||
dispatch(seedSupportMessages());
|
||||
dispatch(seedLoanProducts());
|
||||
dispatch(seedInsurancePlans());
|
||||
dispatch(seedCards());
|
||||
};
|
||||
|
||||
export const useAppBootstrap = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
const toast = useToast();
|
||||
const isAuthenticated = useAppSelector(selectIsAuthenticated);
|
||||
const hasBootstrapped = useRef(false);
|
||||
|
||||
useSessionTimeout();
|
||||
|
||||
// Initial bootstrap on mount
|
||||
useEffect(() => {
|
||||
dispatch(bootstrapAuthSession());
|
||||
seedAllData(dispatch);
|
||||
dispatch(markAppReady());
|
||||
|
||||
void registerForPushNotifications();
|
||||
hasBootstrapped.current = true;
|
||||
}, [dispatch]);
|
||||
|
||||
// Re-seed all data when the user logs back in after a logout.
|
||||
// Logout wipes all Redux state via rootReducer, so profile/dashboard/etc.
|
||||
// need to be re-populated when isAuthenticated flips back to true.
|
||||
useEffect(() => {
|
||||
if (isAuthenticated && hasBootstrapped.current) {
|
||||
seedAllData(dispatch);
|
||||
}
|
||||
}, [isAuthenticated, dispatch]);
|
||||
|
||||
useEffect(() => {
|
||||
const unregister = registerUnauthorizedHandler(() => {
|
||||
dispatch(logoutSession());
|
||||
toast('Signed out', 'info', 'Your session was refreshed for security reasons.');
|
||||
});
|
||||
|
||||
return unregister;
|
||||
}, [dispatch, toast]);
|
||||
};
|
||||
Reference in New Issue
Block a user