Skip to content

Commit

Permalink
timeline responsive, request delete, admin route fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
SMNAFI committed Dec 11, 2022
1 parent f4916e2 commit 8351245
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/components/AdminRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const AdminRoute = () => {
const userDetails = useSelector((state) => state.userDetails)
const { userInfo } = userDetails

return isAuth && userInfo.isAdmin ? <Outlet /> : <LoginScreen />
return isAuth && userInfo?.isAdmin ? <Outlet /> : <LoginScreen />
}

export default AdminRoute
32 changes: 24 additions & 8 deletions src/components/HowItWorks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@ import { Container } from 'react-bootstrap'
import './HowItWorks.css'

import Timeline from '@mui/lab/Timeline'
import TimelineItem from '@mui/lab/TimelineItem'
import TimelineItem, { timelineItemClasses } from '@mui/lab/TimelineItem'
import useMediaQuery from '@mui/material/useMediaQuery'
import TimelineSeparator from '@mui/lab/TimelineSeparator'
import TimelineConnector from '@mui/lab/TimelineConnector'
import TimelineContent from '@mui/lab/TimelineContent'
import TimelineDot from '@mui/lab/TimelineDot'
// import Typography from '@mui/material/Typography'
import steps from './../assets/data/stepsData'

const HowItWorks = () => {
const isMobile = useMediaQuery('(max-width:768px)')

// const [isMobile, setIsMobile] = useState(window.innerWidth < 768)
// useEffect(() => {
// window.addEventListener('resize', () => {
// setIsMobile(window.innerWidth < 768)
// })
// }, [])

return (
<section className='works-container'>
<Container className='my-5'>
Expand All @@ -23,7 +32,19 @@ const HowItWorks = () => {
</div>

<div style={{ maxWidth: '800px' }} className='mx-auto'>
<Timeline position='alternate'>
<Timeline
position={`${isMobile ? 'right' : 'alternate'}`}
sx={
isMobile
? {
[`& .${timelineItemClasses.root}:before`]: {
flex: 0,
padding: 0,
},
}
: {}
}
>
{steps.map((step) => (
<TimelineItem key={step.id}>
<TimelineSeparator>
Expand All @@ -42,11 +63,6 @@ const HowItWorks = () => {
<TimelineConnector />
</TimelineSeparator>
<TimelineContent sx={{ py: '12px', px: 2 }}>
{/* <Typography variant='h6' component='span'>
{step.title}
</Typography>
<Typography>{step.text}</Typography> */}

<p className='step-title'>{step.title}</p>
<p className='step-subtitle'>{step.text}</p>
</TimelineContent>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Statistics/Statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const Statistics = () => {
<h3 className='text-center'>Total Donars</h3>
{inView ? (
<h2 className='count'>
<CountUp start={0} end={donarCount} duration={2} />
<CountUp start={0} end={donarCount} duration={1} />
</h2>
) : null}
</Col>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/DonarDetailsScreen.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react'
import { doc, onSnapshot } from 'firebase/firestore'
import { db } from '../firebase'
import { useNavigate, useParams } from 'react-router-dom'
import { useParams } from 'react-router-dom'
import Loader from '../components/Loader'
import Message from '../components/Message'
import { Card, Col, Container, Row } from 'react-bootstrap'
Expand Down
45 changes: 41 additions & 4 deletions src/screens/ManageRequestsScreen.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { collection, onSnapshot, orderBy, query } from 'firebase/firestore'
import {
collection,
deleteDoc,
doc,
onSnapshot,
orderBy,
query,
} from 'firebase/firestore'
import moment from 'moment'
import React, { useEffect, useState } from 'react'
import { Container, Table } from 'react-bootstrap'
import { Link } from 'react-router-dom'
import Loader from '../components/Loader'
import Message from '../components/Message'
import { db } from '../firebase'
Expand All @@ -10,6 +18,7 @@ import SubHero from './../components/SubHero/SubHero'
const ManageRequestsScreen = () => {
const [requests, setRequests] = useState([])
const [error, setError] = useState(null)
const [message, setMessage] = useState(null)
const [loading, setLoading] = useState(false)

useEffect(() => {
Expand Down Expand Up @@ -40,11 +49,30 @@ const ManageRequestsScreen = () => {
}
}, [])

const deleteHandler = async (id) => {
if (window.confirm('Are you sure?')) {
try {
setLoading(true)
setError(null)
setMessage(null)

await deleteDoc(doc(db, 'requests', id))

setMessage('Request is deleted.')
} catch (error) {
setLoading(false)

setError(error.message)
}
}
}

return (
<>
<SubHero title='Manage Requests'></SubHero>
<Container className='my-5'>
{loading && <Loader />}
{message && <Message>{message}</Message>}
{error && <Message variant='error'>{error}</Message>}

<Table striped bordered size='sm' responsive='xl'>
Expand All @@ -68,9 +96,18 @@ const ManageRequestsScreen = () => {
<td>{isManaged ? 'Managed' : 'Not Managed'}</td>
<td>{moment(createdAt?.toDate()).fromNow()}</td>
<td>
<i className='fa-solid fa-eye me-3'></i>
<i className='fa-solid fa-pen-to-square me-3'></i>
<i className='fa-solid fa-trash-can'></i>
<Link to={`/feed/${id}`}>
<i className='fa-solid fa-eye me-3'></i>
</Link>
<Link to={`/feed/${id}/edit`}>
<i className='fa-solid fa-pen-to-square me-3'></i>
</Link>
<span
style={{ cursor: 'pointer' }}
onClick={() => deleteHandler(id)}
>
<i className='fa-solid fa-trash-can text-danger'></i>
</span>
</td>
</tr>
)
Expand Down
5 changes: 2 additions & 3 deletions src/screens/RequestDetailsScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState } from 'react'
import moment from 'moment'
import { doc, onSnapshot } from 'firebase/firestore'
import { db } from '../firebase'
import { useParams } from 'react-router-dom'
Expand Down Expand Up @@ -110,8 +109,8 @@ function RequestDetailsScreen() {
<Card.Text>Bag managed: {numManaged}</Card.Text>
<Card.Text>
Posted in:{' '}
{new Date(createdAt?.toDate()).toLocaleString()} (
{moment(createdAt?.toDate()).fromNow()})
{new Date(createdAt?.toDate()).toLocaleString()}
{/* ({moment(createdAt?.toDate()).fromNow()}) */}
</Card.Text>
</Col>
</Row>
Expand Down
4 changes: 2 additions & 2 deletions src/screens/RequestEditScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const RequestEditScreen = () => {
{error && <Message variant='danger'>{error}</Message>}
{loading && <Loader />}

{uid === userInfo.uid ? (
{uid === userInfo.uid || userInfo.isAdmin ? (
<Form onSubmit={submitHandler} className='my-5'>
<Form.Group controlId='isManged' className='mb-3'>
<Form.Check
Expand Down Expand Up @@ -246,7 +246,7 @@ const RequestEditScreen = () => {
</Row>

<Button type='submit' varient='primary'>
Update Your Request
Update Request
</Button>
</Form>
) : (
Expand Down
13 changes: 13 additions & 0 deletions src/screens/RequestScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Loader from './../components/Loader'
import { useSelector } from 'react-redux'
import Required from './../components/Required'
import SubHero from '../components/SubHero/SubHero'
import { useNavigate } from 'react-router-dom'

const RequestPage = () => {
const [problem, setProblem] = useState('')
Expand All @@ -24,6 +25,8 @@ const RequestPage = () => {
const userDetails = useSelector((state) => state.userDetails)
const { userInfo } = userDetails

const navigate = useNavigate()

const submitHandler = async (e) => {
e.preventDefault()

Expand Down Expand Up @@ -57,6 +60,8 @@ const RequestPage = () => {
setDate('')
setLoading(false)
setSuccess(true)

navigate('/feed')
} catch (error) {
setLoading(false)
setError(error.message)
Expand All @@ -83,6 +88,7 @@ const RequestPage = () => {
<Required />
</Form.Label>
<Form.Control
className='shadow-none'
as='textarea'
placeholder="Enter patient's problem"
value={problem}
Expand All @@ -99,6 +105,7 @@ const RequestPage = () => {
<Required />
</Form.Label>
<Form.Select
className='shadow-none'
value={bloodGroup}
onChange={(e) => setBloodGroup(e.target.value)}
required={true}
Expand All @@ -122,6 +129,7 @@ const RequestPage = () => {
<Required />
</Form.Label>
<Form.Control
className='shadow-none'
type='number'
placeholder='Num of bages'
value={numBag}
Expand All @@ -141,6 +149,7 @@ const RequestPage = () => {
<Required />
</Form.Label>
<Form.Control
className='shadow-none'
type='text'
placeholder='Enter location'
value={location}
Expand All @@ -156,6 +165,7 @@ const RequestPage = () => {
<Required />
</Form.Label>
<Form.Control
className='shadow-none'
type='text'
placeholder='Enter district'
value={district}
Expand All @@ -174,6 +184,7 @@ const RequestPage = () => {
<Required />
</Form.Label>
<Form.Control
className='shadow-none'
type='string'
placeholder='Time'
value={time}
Expand All @@ -189,6 +200,7 @@ const RequestPage = () => {
<Required />
</Form.Label>
<Form.Control
className='shadow-none'
type='date'
placeholder='Date'
value={date}
Expand All @@ -205,6 +217,7 @@ const RequestPage = () => {
<Required />
</Form.Label>
<Form.Control
className='shadow-none'
type='text'
placeholder='Contact Number'
value={contact}
Expand Down

0 comments on commit 8351245

Please sign in to comment.