sei-ec-remote / project-4-issues

Open an issue to receive help on project 4
0 stars 0 forks source link

Not Able to Render Goals #246

Closed jpineda48 closed 11 months ago

jpineda48 commented 11 months ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

What's the problem you're trying to solve?

Ive created a GoalsIndex function and trying to render the goals. I didnt seed the database however I was able to sucessfully create some goals in Postman. I am also not seing my res console.log.

Post any code you think might be relevant (one fenced block per file)

Goals.Index

import { getAllGoals } from '../../api/goal'
import { useState, useEffect } from "react";
import {Card} from 'react-bootstrap'
import { Link } from 'react-router-dom'
import messages from '../shared/AutoDismissAlert/messages'

const GoalsIndex = (props) => {
    const [goals, setGoals] = useState(null)
    const [error, setError] = useState(false)
    const { msgAlert } = props

    useEffect(() => {
        getAllGoals()
            .then(res => {
                console.log('thegoals', res)
            }) 
            .catch(err => {
                msgAlert({
                    heading: 'error getting goals',
                    message: messages.indexGoalsFailure,
                    variant:'danger'
                })
                setError(true)
            })
    }, [])

    return (
        <div className="container-md">
            <h1>Goals Index</h1>

        </div>
    )
}

export default GoalsIndex

Home.js

import GoalsIndex from "./goals/GoalsIndex"

import {Container} from 'react-bootstrap'

const Home = (props) => {
    const { msgAlert, user } = props
    // console.log('props in home', props)

    return (
        <Container>
            <h2>Home Page</h2>
            <GoalsIndex msgAlert={msgAlert}/>
        </Container>
    )
}

export default Home

api/goals.js

import apiUrl from '../apiConfig'
import axios from 'axios'

//index
export const getAllGoals = () => {
    return axios(`${apiUrl}/goals`)
}

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

I am seeing a messages.indexGoalsFailure

What is your best guess as to the source of the problem?

My best guess is it has to do with seeding the database. However, my thought was that you didnt have to seed if you can successfully create in Postman.

What things have you already tried to solve the problem?

Paste a link to your repository here

https://github.com/jpineda48/myGoalsApp

asands94 commented 11 months ago

What's your error message and what do you see in the console for your res?

jpineda48 commented 11 months ago
Screen Shot 2023-10-09 at 9 53 15 AM