Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

booking details sent to database #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/components/booking/book.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//if is loggedin ==true: booking will happen else link to signup page
//here method is post : userdetails and packagedetails
import React, { Component } from 'react'

class BookingPage extends Component {
constructor(props) {
super(props)
//setiing initial state
this.state = {
packageId: '',
userId: '',
}
}

componentDidMount() {
const userdet = localStorage.getItem('userdetails')
const userid = JSON.parse(userdet)
const packageid = this.props.match.params

this.setState({
userId: userid._id,
packageId: packageid.id,
})
}
render() {
const { userId, packageId } = this.state
const bookingDetails = {
userId,
packageId,
}

return <div>hello</div>
}
}

export default BookingPage
4 changes: 2 additions & 2 deletions src/components/home/container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ class Fetch extends React.Component {

<div>
{pkg.map(pkg_item => (
<div key={pkg_item._id}>
<div key={pkg_item.slug}>
{' '}
<h2>
<Link to={`/package/${pkg_item._id}`}>{pkg_item.name}</Link>
<Link to={`/package/${pkg_item.slug}`}>{pkg_item.name}</Link>
</h2>
<h3>{pkg_item.description}</h3>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/login/loginpage.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'
import { PostCredentials } from '../../helpers/api'
import { postCredentials } from '../../helpers/api'

class LoginPage extends Component {
constructor(props) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/login/signup.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'
import { PostUser } from '../../helpers/api'
import { postUser } from '../../helpers/api'

class SignUp extends Component {
constructor(props) {
Expand Down
13 changes: 7 additions & 6 deletions src/components/package/container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react'
import Loader from '../common/loader'
import Error from '../common/error'
import { getPackageId } from '../../helpers/api'
import { Link } from 'react-router-dom'
import { postCredentials } from '../../helpers/api'
class Package extends React.Component {
constructor(props) {
super(props)
Expand All @@ -13,9 +15,10 @@ class Package extends React.Component {
}

componentDidMount() {
const id = this.props.match.params.id
const slug = this.props.match.params.slug
console.log(slug)

getPackageId(id)
getPackageId(slug)
.then(output => {
this.setState({ pkg: output, isloading: false })
console.log(output)
Expand All @@ -35,10 +38,8 @@ class Package extends React.Component {
<div>
<h1>Name:{pkg.name}</h1>
<h2>Description:{pkg.description}</h2>
<h3>Duration:{pkg.duration}</h3>
{pkg.conditions.map(item => (
<h4>condition:{item}</h4>
))}
{/* booking for user */}
<Link to={`/booking/${pkg._id}`}>Book Now</Link>
</div>
)
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Signup from './login/signup'
import Login from './login/loginpage'
import Package from './package'
import Category from './category'
import Booking from './booking/book'

class Routing extends React.Component {
render() {
Expand All @@ -14,7 +15,8 @@ class Routing extends React.Component {
<Route exact path="/" component={Home} />
<Route exact path="/signup" component={Signup} />
<Route exact path="/login" component={Login} />
<Route path="/package/:id/" component={Package} />
<Route path="/booking/:id" component={Booking} />
<Route path="/package/:slug/" component={Package} />
<Route path="/category/:id/" component={Category} />

{/* TODO: <Route component={Nf} /> */}
Expand Down
10 changes: 9 additions & 1 deletion src/helpers/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'

const BASE_URL = 'https://salty-thicket-13140.herokuapp.com/api/v1'
const BASE_URL = 'http://127.0.0.1:3000/api/v1/'

export function getAllPackage() {
return fetch(`${BASE_URL}/package/all`).then(res => res.json())
Expand Down Expand Up @@ -32,3 +32,11 @@ export function postCredentials(user) {
data: user,
})
}

export function postBookingDetails() {
return axios({
method: 'POST',
usrl: `${BASE_URL}/book/`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lln

data: bookingDetails,
})
}