Files
maternal-app/maternal-web/store/store.ts
Andrei fb92160322 fix: Resolve black pages issue - Add missing auth slice and update checker
Fixed critical issues causing tracking pages to display black:
1. PWA service worker caching old JavaScript chunks
2. Missing auth Redux slice causing undefined errors

## Service Worker Update Checker
- Added /public/check-updates.js script
- Checks for SW updates every 60 seconds
- Auto-reloads page when new SW is activated
- Forces update check on page load
- Prevents future cache staleness issues

## Auth Redux Slice
- Created store/slices/authSlice.ts with User interface
- Added auth reducer to Redux store configuration
- Included auth in persist whitelist
- Provides selectors: selectUser, selectFamilyId, etc.
- Fixes "Cannot read properties of undefined (reading 'user')" error

## Root Cause
Tracking pages reference state.auth.user.familyId but auth slice
didn't exist in Redux store, causing TypeError on all tracking pages.

Build:  PASSED
Files: 3 new, 2 modified

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-05 06:20:51 +00:00

59 lines
2.1 KiB
TypeScript

import { configureStore, Middleware } from '@reduxjs/toolkit';
import { persistStore, persistReducer, FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER } from 'redux-persist';
import storage from 'redux-persist/lib/storage'; // defaults to localStorage for web
import { combineReducers } from '@reduxjs/toolkit';
// Slices
import authReducer from './slices/authSlice';
import offlineReducer from './slices/offlineSlice';
import activitiesReducer from './slices/activitiesSlice';
import childrenReducer from './slices/childrenSlice';
import networkReducer from './slices/networkSlice';
// Middleware
import { offlineMiddleware } from './middleware/offlineMiddleware';
import { syncMiddleware } from './middleware/syncMiddleware';
// Persist configuration
const persistConfig = {
key: 'root',
version: 1,
storage,
// Only persist these slices (exclude network status as it should be fresh on reload)
whitelist: ['auth', 'offline', 'activities', 'children'],
};
const rootReducer = combineReducers({
auth: authReducer,
offline: offlineReducer,
activities: activitiesReducer,
children: childrenReducer,
network: networkReducer,
});
const persistedReducer = persistReducer(persistConfig, rootReducer);
export const store = configureStore({
reducer: persistedReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
// Ignore redux-persist action types
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER, 'persist/PERSIST', 'persist/REHYDRATE'],
// Ignore these field paths in all actions
ignoredActionPaths: ['meta.arg', 'payload.timestamp', 'register'],
// Ignore these paths in the state
ignoredPaths: ['items.dates', 'register'],
},
}).concat(offlineMiddleware, syncMiddleware),
});
export const persistor = persistStore(store);
// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
// Export store instance
export default store;