diff --git a/src/components/AdminRoute.js b/src/components/AdminRoute.js index 4abe455..6b4057a 100644 --- a/src/components/AdminRoute.js +++ b/src/components/AdminRoute.js @@ -9,7 +9,7 @@ const AdminRoute = () => { const userDetails = useSelector((state) => state.userDetails) const { userInfo } = userDetails - return isAuth && userInfo.isAdmin ? : + return isAuth && userInfo?.isAdmin ? : } export default AdminRoute diff --git a/src/components/HowItWorks.js b/src/components/HowItWorks.js index 424b354..52f0892 100644 --- a/src/components/HowItWorks.js +++ b/src/components/HowItWorks.js @@ -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 (
@@ -23,7 +32,19 @@ const HowItWorks = () => {
- + {steps.map((step) => ( @@ -42,11 +63,6 @@ const HowItWorks = () => { - {/* - {step.title} - - {step.text} */} -

{step.title}

{step.text}

diff --git a/src/components/Statistics/Statistics.js b/src/components/Statistics/Statistics.js index 720a6b1..124a15d 100644 --- a/src/components/Statistics/Statistics.js +++ b/src/components/Statistics/Statistics.js @@ -45,7 +45,7 @@ const Statistics = () => {

Total Donars

{inView ? (

- +

) : null} diff --git a/src/screens/DonarDetailsScreen.js b/src/screens/DonarDetailsScreen.js index d234c24..636d1f6 100644 --- a/src/screens/DonarDetailsScreen.js +++ b/src/screens/DonarDetailsScreen.js @@ -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' diff --git a/src/screens/ManageRequestsScreen.js b/src/screens/ManageRequestsScreen.js index cb3d307..31a4725 100644 --- a/src/screens/ManageRequestsScreen.js +++ b/src/screens/ManageRequestsScreen.js @@ -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' @@ -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(() => { @@ -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 ( <> {loading && } + {message && {message}} {error && {error}} @@ -68,9 +96,18 @@ const ManageRequestsScreen = () => { ) diff --git a/src/screens/RequestDetailsScreen.js b/src/screens/RequestDetailsScreen.js index 78bd300..239f9f5 100644 --- a/src/screens/RequestDetailsScreen.js +++ b/src/screens/RequestDetailsScreen.js @@ -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' @@ -110,8 +109,8 @@ function RequestDetailsScreen() { Bag managed: {numManaged} Posted in:{' '} - {new Date(createdAt?.toDate()).toLocaleString()} ( - {moment(createdAt?.toDate()).fromNow()}) + {new Date(createdAt?.toDate()).toLocaleString()} + {/* ({moment(createdAt?.toDate()).fromNow()}) */} diff --git a/src/screens/RequestEditScreen.js b/src/screens/RequestEditScreen.js index aa50e92..2eca3f6 100644 --- a/src/screens/RequestEditScreen.js +++ b/src/screens/RequestEditScreen.js @@ -104,7 +104,7 @@ const RequestEditScreen = () => { {error && {error}} {loading && } - {uid === userInfo.uid ? ( + {uid === userInfo.uid || userInfo.isAdmin ? (
{ ) : ( diff --git a/src/screens/RequestScreen.js b/src/screens/RequestScreen.js index f0fddcf..a0febd5 100644 --- a/src/screens/RequestScreen.js +++ b/src/screens/RequestScreen.js @@ -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('') @@ -24,6 +25,8 @@ const RequestPage = () => { const userDetails = useSelector((state) => state.userDetails) const { userInfo } = userDetails + const navigate = useNavigate() + const submitHandler = async (e) => { e.preventDefault() @@ -57,6 +60,8 @@ const RequestPage = () => { setDate('') setLoading(false) setSuccess(true) + + navigate('/feed') } catch (error) { setLoading(false) setError(error.message) @@ -83,6 +88,7 @@ const RequestPage = () => { { setBloodGroup(e.target.value)} required={true} @@ -122,6 +129,7 @@ const RequestPage = () => { { { { { {
{isManaged ? 'Managed' : 'Not Managed'} {moment(createdAt?.toDate()).fromNow()} - - - + + + + + + + deleteHandler(id)} + > + +