diff --git a/src/components/business/business.js b/src/components/business/business.js index 78bbcc6..a224fc1 100644 --- a/src/components/business/business.js +++ b/src/components/business/business.js @@ -1,199 +1,4 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { withRouter, NavLink } from 'react-router-dom'; -import decode from 'jwt-decode'; -import {NotificationManager} from 'react-notifications'; -import changeCase from 'change-case'; - -import 'react-notifications/lib/notifications.css'; -import 'bootstrap/dist/css/bootstrap.min.css'; -import { getBusiness, deleteBusiness, addReview, getReviews } from '../../actions/getOneBusinessActions'; -import AuthNavigationBar from '../navBar/authNavigationBar'; -import {receivedDataStringify} from '../helper/utilities'; - - -/** - * Business Component where a logged in user can view a business, add a review and view all the reviews. - * Also, a user is able to delete or edit a business they created via this component - * - * ```html - * - * ``` - */ -class BusinessOne extends Component { - - componentDidMount=()=>{ - - //check validity of token before mounting the component - var userToken = sessionStorage.getItem("access_token"); - var userDecoded = decode(userToken); - if ((userToken !== null) && (userDecoded.exp > Date.now() / 1000)) { - const bizId = this.props.match.params.bizid - this.props.getBusiness(bizId) - this.props.getReviews(bizId); - } - else { - this.props.history.push("/") - } - } - - //Function to delete a business - deleteOneBusiness=()=>{ - const popup = window.confirm('Are you sure you want to delete this business?'); - if (popup === true) { - this.props.deleteBusiness(this.props.match.params.bizid) - this.props.history.push("/businesses") - NotificationManager.success("Business successfully deleted", "", 5000); - } - - } - - //Function to a add to review to a business - addOneReview=(event)=>{ - event.preventDefault(); - let reviewBusinessData={ - review_title:event.target.elements.reviewTitle.value, - review_msg:event.target.elements.reviweMsg.value - }; - const bizId = this.props.match.params.bizid - this.props.addReview(bizId, receivedDataStringify(reviewBusinessData)) - window.location.reload(); - } - - //Notification for when a business has no reviews - notificationMessage=()=>{ - if(this.props.getReviewsMessage.message === "Business doesn't have reviews yet!!"){ - document.getElementById("noReviews").className = "show"; - } - } - - //hide edit and delete buttons on the business page when a logged in user did not create the business - hideEditButtons=(userDecoded, businessCreatedBy)=>{ - if (userDecoded.username === businessCreatedBy){ - return "row show" - }else{ - return "row collapse" - } - } - - //hide the add review form if the user who created the business is viewing the business - hideAddReviewForm=(userDecoded, businessCreatedBy)=>{ - if (userDecoded.username === businessCreatedBy){ - return "collapse" - }else{ - return "col bg-light show" - } - } - - //hide the line for a better view when the edit and delete buttons are hidden - hideLine=(userDecoded, businessCreatedBy)=>{ - if (userDecoded.username === businessCreatedBy){ - return "show" - }else{ - return "collapse" - } - } - - render() { - - const oneBusiness=this.props.getBusinessMessage.business; - const reviews=Object.values({...this.props.getReviewsMessage.Reviews}); - - if(oneBusiness){ - var businessID = oneBusiness.id - var businessCreatedBy = oneBusiness.CreatedBy - var businessName = oneBusiness.BusinessName - var businessProfile = oneBusiness.BusinessProfile - var businessCategory = oneBusiness.Category - var businessLocation = oneBusiness.Location - } - - //condition to either show or hide the Delete and Update buttons depending on the logged in user - var userToken = sessionStorage.getItem("access_token"); - var userDecoded = decode(userToken); - let EditDeleteButtonClass = this.hideEditButtons(userDecoded, businessCreatedBy) - let LineClass = this.hideLine(userDecoded, businessCreatedBy) - let addReviewClass = this.hideAddReviewForm(userDecoded, businessCreatedBy) - - if (reviews){ - Array.prototype.reverse.call(reviews) - } - - return ( -
- -
-

{businessName}


-
-   -
-
-
-

-
-


About {businessName}

-
{businessCategory} | {businessLocation}
-
-

- {businessProfile} -

-
-
-


Add a Review


-
-
- -
-
-