forked from stakwork/sphinx-tribes-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request stakwork#346 from chiragDork/issue_328
Add a confirmation pop up when pay bounty button is clicked
- Loading branch information
Showing
6 changed files
with
128 additions
and
6 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/components/common/PaymentConfirmationModal/PaymentConfirmationModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { PropsWithChildren } from 'react'; | ||
import { Stack } from '@mui/system'; | ||
import { BaseModal } from '../BaseModal'; // Assuming you have a BaseModal component | ||
import IconButton from '../IconButton2'; // Assuming you have an IconButton2 component | ||
import { useCreateModal } from '../useCreateModal'; // Assuming you have a custom hook useCreateModal | ||
|
||
export type PaymentConfirmationModalProps = PropsWithChildren<{ | ||
onClose: () => void; | ||
onConfirmPayment: () => void; | ||
onCancel?: () => void; | ||
}>; | ||
|
||
export const PaymentConfirmationModal = ({ | ||
onClose, | ||
children, | ||
onCancel, | ||
onConfirmPayment | ||
}: PaymentConfirmationModalProps) => { | ||
const closeHandler = () => { | ||
onClose(); | ||
onCancel?.(); | ||
}; | ||
|
||
const confirmPaymentHandler = () => { | ||
onConfirmPayment(); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<BaseModal backdrop="white" open onClose={closeHandler}> | ||
<Stack minWidth={350} p={4} alignItems="center" spacing={3}> | ||
{children} | ||
<Stack width="100%" direction="row" justifyContent="space-between"> | ||
<IconButton width={120} height={44} color="white" text="Cancel" onClick={closeHandler} /> | ||
<IconButton | ||
width={120} | ||
height={44} | ||
color="success" // Assuming this color indicates confirmation | ||
text="Confirm" // Changed "Delete" to "Confirm" | ||
onClick={confirmPaymentHandler} // Changed onClick handler | ||
/> | ||
</Stack> | ||
</Stack> | ||
</BaseModal> | ||
); | ||
}; | ||
|
||
export const usePaymentConfirmationModal = () => { | ||
const openModal = useCreateModal(); | ||
|
||
const openPaymentConfirmation = (props: Omit<PaymentConfirmationModalProps, 'onClose'>) => { | ||
openModal({ | ||
Component: PaymentConfirmationModal, | ||
props | ||
}); | ||
}; | ||
|
||
return { openPaymentConfirmation }; | ||
}; |
46 changes: 46 additions & 0 deletions
46
src/components/common/PaymentConfirmationModal/__tests__/PaymentConfirmationModal.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import '@testing-library/jest-dom'; | ||
import { fireEvent, render, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { PaymentConfirmationModal } from '../PaymentConfirmationModal'; | ||
|
||
describe('PaymentConfirmationModal', () => { | ||
it('renders correctly', () => { | ||
const onCloseMock = jest.fn(); | ||
const onConfirmPaymentMock = jest.fn(); | ||
const { getByText } = render( | ||
<PaymentConfirmationModal onClose={onCloseMock} onConfirmPayment={onConfirmPaymentMock}> | ||
Are you sure you want to pay this bounty? | ||
</PaymentConfirmationModal> | ||
); | ||
|
||
expect(getByText('Are you sure you want to pay this bounty?')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls onClose when Cancel button is clicked', async () => { | ||
const onCloseMock = jest.fn(); | ||
const onConfirmPaymentMock = jest.fn(); | ||
const { getByText } = render( | ||
<PaymentConfirmationModal onClose={onCloseMock} onConfirmPayment={onConfirmPaymentMock}> | ||
Are you sure you want to pay this bounty? | ||
</PaymentConfirmationModal> | ||
); | ||
|
||
fireEvent.click(getByText('Cancel')); | ||
await waitFor(() => expect(onCloseMock).toHaveBeenCalledTimes(1)); | ||
expect(onConfirmPaymentMock).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('calls onConfirmPayment and onClose when Confirm button is clicked', async () => { | ||
const onCloseMock = jest.fn(); | ||
const onConfirmPaymentMock = jest.fn(); | ||
const { getByText } = render( | ||
<PaymentConfirmationModal onClose={onCloseMock} onConfirmPayment={onConfirmPaymentMock}> | ||
Are you sure you want to pay this bounty? | ||
</PaymentConfirmationModal> | ||
); | ||
|
||
fireEvent.click(getByText('Confirm')); | ||
await waitFor(() => expect(onCloseMock).toHaveBeenCalledTimes(1)); | ||
expect(onConfirmPaymentMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './PaymentConfirmationModal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters