sei-ec-remote / project-4-issues

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

Unable to Delete Actions #255

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 actions but am unable to delete them.

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

action/delete api


export const removeAction = (user, goalId, actionId)=> {
    return axios({
        url: `${apiUrl}/goals/${goalId}/${actionId}`,
        method: `DELETE`,
        headers: {
            Authorization: `Token token=${user.token}`
        }
    })
}

actionshow

import {useState} from 'react'
import{Card, Button} from 'react-bootstrap'
import { removeAction } from '../../api/action'
import { removeActionFailure, removeActionSuccess  } from '../shared/AutoDismissAlert/messages'

const ActionShow = (props) => {
    const { action, msgAlert, triggerRefresh, user, goal} = props

    const deleteAction = () =>{
        removeAction(user, goal._id, action._id)
            .then(() => 
                msgAlert({
                    heading:'removed successfuly',
                    message: removeActionSuccess,
                    variant: 'success'
                })
            )
                .then(() => triggerRefresh())
                .catch(() => 
                    msgAlert({
                        heading:'oh no!',
                        message: removeActionFailure,
                        variant: 'danger'
                    })

                )
    }

    return (
        <>
        <Card className='m-2'>
            <Card.Header>
                {props.action.action}
                <Card.Body>

                </Card.Body>
            </Card.Header>
            <Card.Footer>
                <small></small>
                <Button className='m-2' variant="danger"
                        onClick={() => deleteAction()}
                >
                    Delete Toy
                </Button>
            </Card.Footer>

        </Card>
        </>
    )
}

export default ActionShow

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

seeing my error message for deleteActionFailure

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

I think it is in my API because it is also not working in postman.

What things have you already tried to solve the problem?

Paste a link to your repository here

https://github.com/jpineda48/myGoalsApp

timmshinbone commented 11 months ago

Share your route you're trying to hit, the place those routes are registered in server.js and your Postman error.

jpineda48 commented 11 months ago

literally mentioned that, and it was a route issue! I had "goals" where "actions" should be.