Congratulations, astronaut! You have reached the final mission in the React Mastery module. It is time to combine all the technologies you have learned into one powerful system -- the Space Mission Command Center. This project is your ultimate test to prove you have mastered advanced React patterns.
You will build a dashboard for managing a space mission that combines key concepts from the entire module:
Use React Portals to render modal mission alert windows outside the main DOM tree. Alerts should appear above the interface with an overlay effect.
Add a language switcher (PL/EN) to the header. The entire dashboard should change interface language dynamically using Context API and translation objects.
Manage mission state (status, fuel, crew, systems) using
useReducer. Define actions such as LAUNCH_MISSION, UPDATE_FUEL, TOGGLE_SYSTEM, ADD_CREW_MEMBER.Create a
<Dashboard.Panel> component using the Compound Components pattern that allows flexible composition of dashboard sections:1<Dashboard>
2 <Dashboard.Header title="Mission Control" />
3 <Dashboard.Panel title="Systems">
4 <SystemsList />
5 </Dashboard.Panel>
6 <Dashboard.Panel title="Crew">
7 <CrewList />
8 </Dashboard.Panel>
9</Dashboard>Wrap dashboard sections in Error Boundaries so that a failure in one panel does not crash the entire application. Display a friendly error message with an option to reload the section.
Apply
React.memo to list components, useMemo for mission statistics calculations, and useCallback for event handlers passed to child components.1App
2βββ LanguageProvider (Context -- i18n)
3βββ MissionProvider (useReducer -- state)
4βββ Dashboard (Compound Component)
5β βββ Dashboard.Header
6β βββ Dashboard.Panel "Mission Status"
7β β βββ ErrorBoundary
8β β βββ MissionStatus (React.memo)
9β βββ Dashboard.Panel "Systems"
10β β βββ ErrorBoundary
11β β βββ SystemsList (React.memo)
12β βββ Dashboard.Panel "Crew"
13β βββ ErrorBoundary
14β βββ CrewList (React.memo)
15βββ Portal -> AlertModal (React Portal)1const initialState = {
2 status: 'preparing',
3 fuel: 100,
4 systems: [
5 { id: 1, name: 'Navigation', active: true },
6 { id: 2, name: 'Life Support', active: true },
7 { id: 3, name: 'Communications', active: false },
8 ],
9 crew: ['Kowalski', 'Nowak', 'Smith'],
10};
11
12function missionReducer(state, action) {
13 switch (action.type) {
14 case 'LAUNCH_MISSION':
15 return { ...state, status: 'in-flight', fuel: state.fuel - 20 };
16 case 'UPDATE_FUEL':
17 return { ...state, fuel: Math.max(0, state.fuel + action.payload) };
18 case 'TOGGLE_SYSTEM':
19 return {
20 ...state,
21 systems: state.systems.map(s =>
22 s.id === action.payload ? { ...s, active: !s.active } : s
23 ),
24 };
25 case 'ADD_CREW_MEMBER':
26 return { ...state, crew: [...state.crew, action.payload] };
27 default:
28 return state;
29 }
30}1const translations = {
2 pl: { launch: 'Rozpocznij misjΔ', fuel: 'Paliwo', systems: 'Systemy' },
3 en: { launch: 'Launch Mission', fuel: 'Fuel', systems: 'Systems' },
4};
5
6const LanguageContext = createContext();
7
8function LanguageProvider({ children }) {
9 const [lang, setLang] = useState('pl');
10 const t = translations[lang];
11 return (
12 <LanguageContext.Provider value={{ lang, setLang, t }}>
13 {children}
14 </LanguageContext.Provider>
15 );
16}1function AlertModal({ message, onClose }) {
2 return createPortal(
3 <div className="modal-overlay">
4 <div className="modal-content">
5 <h2>Alert!</h2>
6 <p>{message}</p>
7 <button onClick={onClose}>Close</button>
8 </div>
9 </div>,
10 document.getElementById('modal-root')
11 );
12}Use the code editor below as a starting point. Expand the application with the missing features and adapt it to the structure described above.