Refactor Dashboard component to implement a structured routing system with dedicated pages for workplace input, login, chain selection, task management, and completion. Introduce centralized localStorage management for user data and navigation logic, enhancing user experience and streamlining the application flow. Remove the deprecated LoginForm component and update the MainPage to redirect users based on their authentication and task status.
Some checks failed
platform/bro-js/challenge-pl/pipeline/head There was a failure building this commit
Some checks failed
platform/bro-js/challenge-pl/pipeline/head There was a failure building this commit
This commit is contained in:
47
src/pages/chains/ChainsPage.tsx
Normal file
47
src/pages/chains/ChainsPage.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import React, { useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
|
||||
import { URLs } from '../../__data__/urls'
|
||||
import { useChallenge } from '../../context/ChallengeContext'
|
||||
import { Header } from '../../components/Header'
|
||||
import { ChainSelector } from '../../components/ChainSelector'
|
||||
import { storage } from '../../utils/storage'
|
||||
import type { ChallengeChain } from '../../__data__/types'
|
||||
|
||||
export const ChainsPage = () => {
|
||||
const navigate = useNavigate()
|
||||
const { nickname } = useChallenge()
|
||||
|
||||
// Проверяем авторизацию
|
||||
useEffect(() => {
|
||||
const workplaceNumber = storage.getWorkplaceNumber()
|
||||
if (!workplaceNumber) {
|
||||
navigate(URLs.workplace, { replace: true })
|
||||
return
|
||||
}
|
||||
if (!nickname) {
|
||||
navigate(URLs.login, { replace: true })
|
||||
}
|
||||
}, [navigate, nickname])
|
||||
|
||||
const handleSelectChain = (chain: ChallengeChain) => {
|
||||
storage.setSelectedChainId(chain.id)
|
||||
// Переходим к первому заданию цепочки
|
||||
if (chain.tasks.length > 0) {
|
||||
storage.setSelectedTaskId(chain.tasks[0].id)
|
||||
navigate(URLs.task(chain.id, chain.tasks[0].id))
|
||||
}
|
||||
}
|
||||
|
||||
if (!nickname) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<ChainSelector onSelectChain={handleSelectChain} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user