fix: adiciona optional chaining para prevenir erros de undefined

- Corrige acesso a propriedades undefined em story.content.pages
- Adiciona verificações de segurança com optional chaining (?.)
- Implementa fallback para texto quando conteúdo não está disponível
- Previne erros de runtime em:
  - StudentDashboardPage
  - StudentStoriesPage
  - StoryPage

Resolves: #BUG-789
This commit is contained in:
Lucas Santana 2024-12-23 07:33:22 -03:00
parent 4f3b80246f
commit 3701e692f1
3 changed files with 4 additions and 4 deletions

View File

@ -334,7 +334,7 @@ export function StoryPage() {
<div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden"> <div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
{/* Imagem da página atual */} {/* Imagem da página atual */}
{story.content.pages[currentPage].image && ( {story.content?.pages?.[currentPage]?.image && (
<div className="relative aspect-video"> <div className="relative aspect-video">
<img <img
src={story.content.pages[currentPage].image} src={story.content.pages[currentPage].image}
@ -349,7 +349,7 @@ export function StoryPage() {
{/* Texto da página atual */} {/* Texto da página atual */}
<p className="text-lg text-gray-700 mb-8"> <p className="text-lg text-gray-700 mb-8">
{story.content.pages[currentPage].text} {story.content?.pages?.[currentPage]?.text || 'Carregando...'}
</p> </p>
{/* Gravador de áudio */} {/* Gravador de áudio */}

View File

@ -231,7 +231,7 @@ export function StudentDashboardPage() {
className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden cursor-pointer hover:shadow-md transition" className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden cursor-pointer hover:shadow-md transition"
onClick={() => navigate(`/aluno/historias/${story.id}`)} onClick={() => navigate(`/aluno/historias/${story.id}`)}
> >
{story.content.pages[0].image && ( {story.content?.pages?.[0]?.image && (
<img <img
src={story.content.pages[0].image} src={story.content.pages[0].image}
alt={story.title} alt={story.title}

View File

@ -197,7 +197,7 @@ export function StudentStoriesPage() {
className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden cursor-pointer hover:shadow-md transition" className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden cursor-pointer hover:shadow-md transition"
onClick={() => navigate(`/aluno/historias/${story.id}`)} onClick={() => navigate(`/aluno/historias/${story.id}`)}
> >
{story.content.pages[0].image && ( {story.content?.pages?.[0]?.image && (
<img <img
src={story.content.pages[0].image} src={story.content.pages[0].image}
alt={story.title} alt={story.title}