Changeset 899b19d for frontend/src/FrontPage.js
- Timestamp:
- 07/10/22 10:27:45 (2 years ago)
- Branches:
- master
- Children:
- a26f6a1
- Parents:
- cc4db18
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/FrontPage.js
rcc4db18 r899b19d 2 2 import {Header} from "./Header"; 3 3 import {useNavigate} from "react-router-dom"; 4 import {Button, Card, Image, Modal, Spin} from "antd";4 import {Button, Card, DatePicker, Form, Image, Input, Modal, notification, Rate, Spin} from "antd"; 5 5 import placeholderImage from '../src/Assets/placeholder.png' 6 6 import AddNewReservation from "./Dashboard/AddNewReservation"; 7 7 import axios from "axios"; 8 8 import env from "./env"; 9 import Review from "./Dashboard/Review"; 9 10 10 const FrontPage = ({ }) => {11 const FrontPage = ({user, logout}) => { 11 12 const [restaurant, setRestaurant] = useState({name:'Sample Restaurant name', address: 'Sample street 1', city:'Sample'}); 12 13 const [newReservationModal, setNewReservationModal] = useState(false); 13 14 const [saveModalLoading, setSaveModalLoading] = useState(false); 15 const [newReviewModal, setNewReviewModal] = useState(false); 14 16 const [loading, setLoading] = useState(true); 17 const [refreshToggle, setRefreshToggle] = useState(false); 15 18 const history = useNavigate(); 16 19 … … 23 26 },[]) 24 27 28 const saveNewReview = data =>{ 29 setSaveModalLoading(true) 30 axios.post(env.api + 'Reviews',data,{ headers: {Authorization: sessionStorage.getItem('Auth')}}).then(res=>{ 31 setNewReviewModal(false) 32 setSaveModalLoading(false) 33 notification['success']({ 34 message: 'Успешно зачувано', 35 }); 36 setRefreshToggle(ref => !ref); 37 }).catch(err=>{ 38 setSaveModalLoading(false) 39 notification['error']({ 40 message: 'Се случи проблем при зачувување', 41 }); 42 }); 43 } 44 25 45 return( 26 46 <div> 27 <Header onClickButton={ ()=>history('/login')} buttonText={'Логирајсе'}/>47 <Header onClickButton={!user?()=>history('/login'):logout} buttonText={!user?'Најави се':'Одјави се'}/> 28 48 {loading ? <Spin style={{margin: 20}}/> : 29 49 <div style={{ … … 69 89 </div> 70 90 <div style={{textAlign: 'start', backgroundColor: '#F2F2F2'}}> 71 <h2 style={{textAlign:'center',paddingTop:'20px'}}>Мени</h2> 91 <div style={{ 92 width: '100%', 93 height:'75px', 94 backgroundColor: 'white', 95 padding: '20px', 96 border: '1px solid lightgray' 97 }} > 98 <h2 style={{float: 'left'}}>Мени</h2> 99 </div> 72 100 {restaurant.menu.map(el => 73 <Card title={el.title} style={{ width: 280, display:'inline-block', margin:'10px' }} size="small">101 <Card key={el.id} title={el.title} style={{ width: 280, display:'inline-block', margin:'10px' }} size="small"> 74 102 <p>{el.description}</p> 75 103 <b>{el.price} ден.</b> 76 104 </Card> 77 105 )} 106 <Review user={user} front refresh={refreshToggle} setVisible={setNewReviewModal}/> 78 107 </div> 79 108 </div> … … 92 121 <AddNewReservation setModalSaveLoading={setSaveModalLoading} setModalVisible={setNewReservationModal} /> 93 122 </Modal> 123 <Modal 124 style={{top: 20}} 125 width={'700px'} 126 title="Нова оценка" 127 footer={[ 128 <Button form="newReviewForm" key="submit" htmlType="submit" type={'primary'} loading={saveModalLoading}> 129 Прати 130 </Button> 131 ]} 132 onCancel={()=>setNewReviewModal(false)} 133 visible={newReviewModal}> 134 <Form onFinish={saveNewReview} 135 id={'newReviewForm'} 136 onFinishFailed={()=> 137 notification['error']({ 138 message: 'Ве молиме поправете ги сите грешки пред зачувување!', 139 })}> 140 <Form.Item 141 label="Наслов" 142 name="title" 143 rules={[ 144 { 145 required: true, 146 message: 'Ве молиме внесете наслов!', 147 }, 148 ]} 149 > 150 <Input/> 151 </Form.Item> 152 <Form.Item 153 label="Опис" 154 name="description" 155 rules={[ 156 { 157 required: true, 158 message: 'Ве молиме внесете опис!', 159 }, 160 ]} 161 > 162 <Input.TextArea rows={4}/> 163 </Form.Item> 164 <Form.Item 165 label="Оценка" 166 name="stars" 167 rules={[ 168 { 169 required: true, 170 message: 'Ве молиме внесете оценка!', 171 }, 172 ]} 173 > 174 <Rate/> 175 </Form.Item> 176 </Form> 177 </Modal> 94 178 </div> 95 96 179 ) 97 180 } 98 99 181 export default FrontPage;
Note:
See TracChangeset
for help on using the changeset viewer.