-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import React, { CSSProperties } from 'react'; | ||
import { Dialog, DialogContent, DialogContentText, DialogActions, Button } from '@mui/material'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
/* | ||
* this card displays the alert message that a refund has been processed | ||
*/ | ||
|
||
interface Props { | ||
refundedTransactionMessage: string, | ||
refundedTransaction: { | ||
message: string, | ||
block_explorer_link: string | ||
}, | ||
showRefundAlert: boolean, | ||
onRefundClose: () => void, | ||
} | ||
|
||
const modalStyle: CSSProperties = { | ||
background: 'white', | ||
position: 'absolute', | ||
left: '15vw', | ||
top: '40%', | ||
width: '70vw', | ||
height: '25vh', | ||
border: '1px solid black', | ||
textAlign: 'center', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center' | ||
} | ||
|
||
export default function Refund(props: Props) { | ||
return ( | ||
<div style={modalStyle}> | ||
<p style={{ fontWeight: 'bold' }}>Refunded Payment</p> | ||
<div> | ||
<p>{props.refundedTransactionMessage}</p> | ||
<button onClick={props.onRefundClose}>Close</button> | ||
</div> | ||
</div> | ||
<Dialog | ||
open={props.showRefundAlert} | ||
onClose={props.onRefundClose} | ||
> | ||
<DialogContent> | ||
<DialogContentText marginTop={1}> | ||
{props.refundedTransaction.message} | ||
</DialogContentText> | ||
<DialogContentText marginTop={2}> | ||
<a href={props.refundedTransaction.block_explorer_link}>View on the Pi Block Explorer</a> | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={props.onRefundClose}>Close</Button> | ||
</DialogActions> | ||
</Dialog> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import Refund from "../components/Refund"; | |
|
||
const _window: WindowWithEnv = window; | ||
const backendURL = _window.__ENV && _window.__ENV.backendURL; | ||
const axiosClient = axios.create({ baseURL: `${backendURL}`, timeout: 20000, withCredentials: true}); | ||
const axiosClient = axios.create({ baseURL: `${backendURL}`, timeout: 35000, withCredentials: true}); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
/* | ||
* this page retrieves and displays all the eligible refunds a user has. | ||
|
@@ -22,41 +22,52 @@ export default function AppToUserPayments() { | |
const { user, saveUser, saveShowModal, showModal, refunds, saveRefunds, onModalClose } = React.useContext(UserContext) as UserContextType; | ||
const [showRefundAlert, setShowRefundAlert] = useState(false); | ||
const [refundInfoState, setRefundInformation] = useState<{message: string, block_explorer_link: string}>({message: "", block_explorer_link: ""}); | ||
const [refundProcessing, setRefundProcessing] = useState(false); | ||
|
||
const orderRefund = async (memo: string, originalPayment: RefundType) => { | ||
if(user === null) { | ||
if(refundProcessing){ | ||
return console.log("refund already in progress"); | ||
} | ||
|
||
setRefundProcessing(true); | ||
if(user.uid === "") { | ||
setRefundProcessing(false); | ||
return saveShowModal(true); | ||
} | ||
|
||
const refundPaymentID = originalPayment.pi_payment_id; | ||
This comment has been minimized.
Sorry, something went wrong.
Andestra
|
||
const refundPaymentAmount = originalPayment.amount; | ||
const paymentData = { memo, refundPaymentID, refundPaymentAmount}; | ||
const refundInformation: typeof refundInfoState = await axiosClient.post('/payments/refundable_payment/refund_payment', paymentData); | ||
|
||
const returnInfo = await axiosClient.post('/payments/refundable_payment/refund_payment', paymentData); | ||
const refundInformation = returnInfo.data | ||
console.log('refund information: ', refundInformation) | ||
setRefundInformation(refundInformation); | ||
setShowRefundAlert(true); | ||
|
||
saveRefunds(); | ||
setShowRefundAlert(true); | ||
setRefundProcessing(false); | ||
} | ||
|
||
useEffect(() => { | ||
saveRefunds(); | ||
}, []); | ||
},[]); | ||
|
||
return ( | ||
<> | ||
<Header/> | ||
<Typography variant="h4" margin={3}> | ||
App to User Payments | ||
</Typography> | ||
{ | ||
refunds[0] === undefined || refunds[0]._id === '' ? | ||
{(user.uid === '' || refunds[0] === undefined) ? | ||
<RefundCard | ||
name= 'none' | ||
description= "Did the delivery person eat your pie and now you need a refund?" | ||
pictureCaption="Picture by David McLeish - https://www.flickr.com/photos/shishberg/2310078068/, CC BY-SA 2.0" | ||
pictureURL="https://live.staticflickr.com/2143/2310078068_627e69cea2_k.jpg" | ||
amount={1} | ||
onClickRefund={()=> saveRefunds()} | ||
variant={refundProcessing} | ||
/> | ||
: | ||
refunds.map((order: RefundType) =>{ | ||
|
@@ -68,12 +79,14 @@ return ( | |
pictureURL="https://live.staticflickr.com/2143/2310078068_627e69cea2_k.jpg" | ||
amount={order.amount} | ||
onClickRefund={()=> orderRefund("User Requested Refund", order)} | ||
variant={refundProcessing} | ||
/> | ||
}) | ||
} | ||
|
||
{ showModal && <SignIn onSignIn={saveUser} onModalClose={onModalClose} showModal={showModal}/> } | ||
{ showRefundAlert && <Refund refundedTransaction={refundInfoState} onRefundClose={() => setShowRefundAlert(false)} showRefundAlert={showRefundAlert} /> } | ||
|
||
{ showModal && <SignIn onSignIn={saveUser} onModalClose={onModalClose} /> } | ||
{ showRefundAlert && <Refund refundedTransactionMessage={refundInfoState.message} onRefundClose={() => setShowRefundAlert(false)} /> } | ||
<Footer/> | ||
</> | ||
) | ||
|
ES8915632626313261614466