From e5d502beabbc969bc46d3f1e5db57f5e6c8e416c Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Wed, 20 Mar 2024 14:53:34 -0500 Subject: [PATCH] Add option to view work request --- client/src/App.jsx | 20 ++----------- client/src/components/ViewPostModal.jsx | 40 +++++++++++++++++++++++++ client/src/components/WorkRequests.jsx | 33 +++++++++++++++----- 3 files changed, 68 insertions(+), 25 deletions(-) create mode 100644 client/src/components/ViewPostModal.jsx diff --git a/client/src/App.jsx b/client/src/App.jsx index 9d7d69a..957beee 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -12,7 +12,6 @@ import Container from 'react-bootstrap/Container'; import Row from 'react-bootstrap/Row'; import Col from 'react-bootstrap/Col'; import Stack from 'react-bootstrap/Stack'; -import Modal from 'react-bootstrap/Modal'; import './App.css'; @@ -24,6 +23,7 @@ import Work1Artifact from './assets/Work1.json'; import OnboardingArtifact from './assets/Onboarding.json'; import WorkContract from './components/WorkContract'; import AddPostModal from './components/AddPostModal'; +import ViewPostModal from './components/ViewPostModal'; function App() { const { @@ -250,7 +250,7 @@ function App() { }, [DAO, account]); const handleShowAddPost = () => setShowAddPost(true); - const handleCloseViewPost = () => setShowViewPost(false); + const handleShowViewPost = async (post) => { const res = await axios.get(`/api/read/${post.contentId}`); const { data } = res; @@ -275,21 +275,7 @@ function App() { - - - View Post - - -

- {viewPostContent} -

-
- - - -
+ {!connected && } diff --git a/client/src/components/ViewPostModal.jsx b/client/src/components/ViewPostModal.jsx new file mode 100644 index 0000000..8da0c79 --- /dev/null +++ b/client/src/components/ViewPostModal.jsx @@ -0,0 +1,40 @@ +import Button from 'react-bootstrap/Button'; +import Modal from 'react-bootstrap/Modal'; +import PropTypes from 'prop-types'; + +function ViewPostModal({ + show, setShow, title, content, +}) { + const handleClose = () => setShow(false); + + return ( + + + {title} + + +

+ {content} +

+
+ + + +
+ ); +} + +ViewPostModal.propTypes = { + show: PropTypes.bool.isRequired, + setShow: PropTypes.func.isRequired, + title: PropTypes.string, + content: PropTypes.string.isRequired, +}; + +ViewPostModal.defaultProps = { + title: 'View Post', +}; + +export default ViewPostModal; diff --git a/client/src/components/WorkRequests.jsx b/client/src/components/WorkRequests.jsx index bea8ba7..df729e7 100644 --- a/client/src/components/WorkRequests.jsx +++ b/client/src/components/WorkRequests.jsx @@ -2,6 +2,7 @@ import { useCallback, useContext, useEffect, useState, } from 'react'; import { PropTypes } from 'prop-types'; +import axios from 'axios'; import Button from 'react-bootstrap/Button'; import Web3 from 'web3'; @@ -9,6 +10,7 @@ import Web3Context from '../contexts/Web3Context'; import useList from '../utils/List'; import WorkContractContext from '../contexts/WorkContractContext'; import AddPostModal from './AddPostModal'; +import ViewPostModal from './ViewPostModal'; const getRequestStatus = (request) => { switch (Number(request.status)) { @@ -31,9 +33,11 @@ function WorkRequests({ const { workContract, availabilityStakes } = useContext(WorkContractContext); const [workRequests, dispatchWorkRequest] = useList(); const [price, setPrice] = useState(); - const [showWorkRequestModal, setShowWorkRequestModal] = useState(false); - const [showWorkEvidenceModal, setShowWorkEvidenceModal] = useState(false); + const [showRequestModal, setShowRequestModal] = useState(false); + const [showEvidenceModal, setShowEvidenceModal] = useState(false); const [currentRequestId, setCurrentRequestId] = useState(); + const [showViewRequestModal, setShowViewRequestModal] = useState(false); + const [viewRequestContent, setViewRequestContent] = useState(''); const { provider, account, @@ -104,14 +108,14 @@ function WorkRequests({ const handleShowWorkRequest = (requestId) => { setCurrentRequestId(requestId); - setShowWorkRequestModal(true); + setShowRequestModal(true); }; const handleShowWorkEvidence = (requestId) => { setCurrentRequestId(requestId); - setShowWorkEvidenceModal(true); + setShowEvidenceModal(true); }; - const onSubmitWorkRequest = useCallback(async (hash) => { + const onSubmitRequest = useCallback(async (hash) => { // TODO: Accept input, upload to API, include hash in contract call const web3 = new Web3(provider); const priceWei = BigInt(web3.utils.toWei(price, 'ether')); @@ -122,17 +126,27 @@ function WorkRequests({ }); }, [provider, workContract, account, price]); - const onSubmitWorkEvidence = useCallback(async (hash) => { + const onSubmitEvidence = useCallback(async (hash) => { await workContract.methods.submitWorkEvidence(currentRequestId, hash).send({ from: account, gas: 1000000, }); }, [workContract, account, currentRequestId]); + const handleShowViewRequestModal = async (request) => { + const res = await axios.get(`/api/read/${request.requestContentId}`); + const { data } = res; + // TODO: Verify base64url(sha256(JSON.stringify(data))) = contentId + // TODO: Verify data.author = post.author + setViewRequestContent(data.content); + setShowViewRequestModal(true); + }; + return ( <> - - + + +
{`Price: ${price} ETH`}
@@ -174,6 +188,9 @@ function WorkRequests({ {request.stakeIndex.toString()} {request.approval.toString()} + {availabilityStakes.length > 0 && availabilityStakes[Number(request.stakeIndex)]?.currentUserIsWorker() && Number(request.status) === 0 && (