diff --git a/ui/src/services/WishDetailsService.js b/ui/src/services/WishDetailsService.js index ec393cfd..e49f87a9 100644 --- a/ui/src/services/WishDetailsService.js +++ b/ui/src/services/WishDetailsService.js @@ -12,6 +12,11 @@ const makeAWish = async(wish) => { return response.data; } +const editAWish = async(id, wish) => { + let response = await axios.put(`${expressDomain}/wishes/${id}`, wish); + return response.data; +} + export const getWishes = async (types) => { let typeParams = types && types.length ? `?types=${types.toString()}` : ''; // TODO query param options @@ -22,5 +27,6 @@ export const getWishes = async (types) => { export default { getWishDetails, makeAWish, + editAWish, getWishes } diff --git a/ui/src/services/WishDetailsService.test.js b/ui/src/services/WishDetailsService.test.js index f0e8ce98..c8705acd 100644 --- a/ui/src/services/WishDetailsService.test.js +++ b/ui/src/services/WishDetailsService.test.js @@ -53,6 +53,25 @@ describe('Wish details service', () => { expect(axios.post).toHaveBeenCalledWith(`${expressDomain}/wishes`, wish); }) + it('should edit a wish when required', async () => { + const wish = { + "child": { + "firstName": "test2", + "lastName": "test2", + "age": "4", + "hometown": "Not Atlanta", + "illness": "sick" + }, + "type": "go", + "details": "to disneyland" + } + + axios.put = jest.fn(() => Promise.resolve({ data: wish })); + const response = await WishDetailsService.editAWish(wishId, wish); + expect(axios.put).toHaveBeenCalledWith(`${expressDomain}/wishes/${wishId}`, wish); + expect(response.child.hometown).toEqual('Not Atlanta') + }); + it('should get wishes', async () => { await WishDetailsService.getWishes(); expect(axios.get).toHaveBeenCalledWith(`${expressDomain}/wishes`); diff --git a/ui/src/wishDetails/WishDetails.js b/ui/src/wishDetails/WishDetails.js index 63a6c3be..7bb67df6 100644 --- a/ui/src/wishDetails/WishDetails.js +++ b/ui/src/wishDetails/WishDetails.js @@ -1,5 +1,4 @@ import React, { Component } from 'react' -import { Link } from 'react-router-dom' import WishDetailsService from '../services/WishDetailsService' import Rocket from '../assets/images/icn_To_Go_Rocket_White_Inside_130x130.png' import Alien from '../assets/images/icn_To_Meet_Alien_White_Inside_130x130.png' @@ -10,6 +9,13 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faCamera } from '@fortawesome/free-solid-svg-icons' import WishHeader from '../wishList/wishHeader' +const styles = { + link:{ + color: '#000000', + textDecoration: 'underline' + } +} + export default class WishDetails extends Component { constructor(props) { super(props) @@ -36,6 +42,24 @@ export default class WishDetails extends Component { } } + updateHometownField(hometown) { + this.setState(prevState => ({ + ...prevState, + wishDetails: { + ...prevState.wishDetails, + child: { + ...prevState.wishDetails.child, + hometown: hometown + } + } + })); + } + // () => this.updateHometown({child: wishDetails.child, type: wishDetails.type, details: wishDetails.details} + updateHometown = async (wish) => { + const { id } = this.props.match.params + return await WishDetailsService.editAWish(id, wish); + } + async componentDidMount() { const { id } = this.props.match.params const wishDetails = await WishDetailsService.getWishDetails(id) @@ -68,15 +92,25 @@ export default class WishDetails extends Component { return image } + goToWishSummary(wish) { + this.updateHometown(wish).then(() => this.props.history.push('/wish-summary')) + } + render() { - const { child, details, sponsor } = this.state.wishDetails + const { child, details, sponsor, type } = this.state.wishDetails const { name, age, hometown } = child + const wish = { + child: child, + type: type, + details: details + } + return (