@@ -36,6 +36,7 @@ import RefundPurchaseModal from "@/components/modals/refund-purchase-modal";
3636import CreatePurchaseModal from "@/components/modals/create-purchase-modal" ;
3737import { ScreenshotModal } from "@/components/modals/screenshot-modal" ;
3838import ButtonAddFeedbackOrReturn from "@/components/button-add-feedback-or-return" ;
39+ import ReturnPurchaseModal from "@/components/modals/return-purchase" ;
3940
4041/**
4142 * Main page of the application displaying purchase data in a tabular format
@@ -53,14 +54,15 @@ import ButtonAddFeedbackOrReturn from "@/components/button-add-feedback-or-retur
5354export default function IndexPage ( ) {
5455 const { t } = useTranslation ( ) ;
5556 const { isAuthenticated } = useAuth0 ( ) ;
56- const [ createNewPurchase , setCreateNewPurchase ] = useState ( false ) ;
57- const [ refundPurchases , setRefundPurchases ] = useState ( false ) ;
5857 const [ createFeedbackPurchase , setCreateFeedbackPurchase ] = useState ( false ) ;
58+ const [ createNewPurchase , setCreateNewPurchase ] = useState ( false ) ;
5959 const [ publishFeedbackPurchase , setPublishFeedbackPurchase ] = useState ( false ) ;
60- const [ toggleAllPurchases , setToggleAllPurchases ] = useState ( false ) ;
61- const [ refreshTrigger , setRefreshTrigger ] = useState ( 0 ) ;
6260 const [ purchase , setPurchase ] = useState ( { purchaseId : "" , amount : 0 } ) ;
61+ const [ refreshTrigger , setRefreshTrigger ] = useState ( 0 ) ;
62+ const [ refundPurchases , setRefundPurchases ] = useState ( false ) ;
63+ const [ returnPurchase , setReturnPurchase ] = useState ( false ) ;
6364 const [ screenshot , setScreenshot ] = useState < string | null > ( null ) ;
65+ const [ toggleAllPurchases , setToggleAllPurchases ] = useState ( false ) ;
6466
6567 // Function to refresh the table
6668 const refreshTable = ( ) => {
@@ -195,13 +197,17 @@ export default function IndexPage() {
195197
196198 /**
197199 * Handles opening the return modal for a specific purchase
200+ * Show a confirmation Modal to confirm the return
201+ * and then call the API to directly set the purchase as refunded
202+ * the refund amount is set to the purchase amount
203+ * the date is set to the current date
198204 *
199205 * @param {string } purchaseId - The ID of the purchase to return
200206 * @param {number } amount - The purchase amount
201207 */
202208 const handleReturnItem = ( purchaseId : string , amount : number ) => {
203209 setPurchase ( { purchaseId, amount } ) ;
204- window . alert ( "This feature is not implemented yet." ) ;
210+ setReturnPurchase ( true ) ;
205211 } ;
206212
207213 /**
@@ -391,6 +397,17 @@ export default function IndexPage() {
391397 onClose = { ( ) => setScreenshot ( null ) }
392398 />
393399 ) }
400+
401+ { /* Return Modal */ }
402+ { returnPurchase && (
403+ < ReturnPurchaseModal
404+ children = { undefined }
405+ isOpen = { returnPurchase }
406+ purchaseId = { purchase . purchaseId }
407+ onClose = { ( ) => setReturnPurchase ( false ) }
408+ onSuccess = { refreshTable }
409+ />
410+ ) }
394411 </ DefaultLayout >
395412 ) ;
396413}
0 commit comments