Skip to content

Commit

Permalink
reviews added
Browse files Browse the repository at this point in the history
  • Loading branch information
AchyuthMohan committed Dec 3, 2022
1 parent 5739302 commit 9e1e939
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/components/ReviewDialog/ReviewDialog.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.review_form__container{
width: 100%;
display: flex;
justify-content: center;
align-items: center;
padding: 3rem;
}
.review_main_form{
display: flex;
flex-direction: column;
gap: 2rem;
}
59 changes: 59 additions & 0 deletions src/components/ReviewDialog/ReviewDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { useState } from 'react'
import './ReviewDialog.css'
import Dialog from '@mui/material/Dialog';
import axiosInstance from '../../utils/axios';
import { useEffect } from 'react';
import baseUrl from '../../utils/Urls';
const ReviewDialog = ({open,handleClose}) => {
const[description,setDescription]=useState('')
const[rate,setRate]=useState(0)
const[currUser,setCurrUser]=useState('')
const[currUserId,setCurrUserId]=useState()

useEffect(()=>{
axiosInstance.get(`${baseUrl}/current-user/`).then((response)=>{
setCurrUser(response.data.username)
setCurrUserId(response.data.id)
},(error)=>{

})
},[])
const handleSubmit=()=>{
axiosInstance.post(`${baseUrl}/reviews/`,{
desc: description,
rate: rate,
user_name: currUser,
user_foreign: currUserId
}).then((response)=>{
console.log(response)
},(error)=>{

})
}
return (
<div>
<Dialog
fullWidth={true}
maxWidth={"md"}
PaperProps={{
sx: { width: "100%", borderRadius: 5, m: 2, minHeight: "60vh" },
}}
open={open}
onClose={handleClose}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description">
<div className="review_form__container">
<form className='review_main_form' onSubmit={handleSubmit}>
<input type='text' placeholder='Description'value={description} onChange={(e)=>{setDescription(e.target.value)}}/>
<input type="number" placeholder='Enter your rating out of 10' value={rate} onChange={(e)=>{setRate(e.target.value)}}/>
<button type='submit'>Submit</button>
</form>
</div>


</Dialog>
</div>
)
}

export default ReviewDialog
6 changes: 3 additions & 3 deletions src/pages/ReviewPage/ReviewCards.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import './ReviewPage.css'
function ReviewCards({ desc,rate }) {
function ReviewCards({ desc,rate,name }) {
return (
<section class="t-bq-section" id="paul">
<div class="t-bq-wrapper t-bq-wrapper-boxed">
Expand All @@ -17,8 +17,8 @@ function ReviewCards({ desc,rate }) {
</blockquote>
<div class="t-bq-quote-paul-meta">
<div class="t-bq-quote-paul-meta-info">
<div class="t-bq-quote-paul-author"><cite>Strugatsky Brothers</cite></div>
<div class="t-bq-quote-paul-source"><span>Rating {rate}</span></div>
<div class="t-bq-quote-paul-author"><cite>{name}</cite></div>
<div class="t-bq-quote-paul-source"><span className='rating__text'>Rating {rate}</span></div>
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/pages/ReviewPage/ReviewPage.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ section.t-bq-section {
padding: 30px;
margin-bottom: 60px;
}
.rating__text{
font-size: 1rem;
color: cornflowerblue;
}

.t-bq-wrapper.t-bq-wrapper-boxed {
max-width: 576px;
Expand Down
18 changes: 16 additions & 2 deletions src/pages/ReviewPage/ReviewPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,36 @@ import './ReviewPage.css'
import axios from 'axios'
import baseUrl from '../../utils/Urls'
import ReviewCards from './ReviewCards'
import ReviewDialog from '../../components/ReviewDialog/ReviewDialog'
function ReviewPage() {
const[reviews,setReviews]=useState([])
const[open,setOpen]=useState(false)

const handleClose=()=>{
setOpen(false)
}
const handleClickOpen = () => {
setOpen(true);
}

useEffect(()=>{
axios.get(`${baseUrl}/reviews/`).then((response)=>{
setReviews(response.data)
})
},[])

return (
<Mainlayout>
<ReviewDialog open={open} handleClose={handleClose} />
<div className='review__container'>
{
(localStorage.getItem('refresh_token'))?((<button className="nav_item" onClick={handleClickOpen} >
Review
</button> )):(( null))
}
{
reviews.map((item)=>{
return(
<ReviewCards key={item.id} desc={item.desc} rate={item.rate}/>
<ReviewCards key={item.id} desc={item.desc} rate={item.rate} name={item.user_name}/>
)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import baseUrl from "./Urls";

const axiosInstance= axios.create({
baseURL: "http://127.0.0.1:8000",
timeout:5000,
timeout:30000,
headers:{
Authorization: localStorage.getItem('access_token')
? 'Bearer ' + localStorage.getItem('access_token')
Expand Down

0 comments on commit 9e1e939

Please sign in to comment.