-
Notifications
You must be signed in to change notification settings - Fork 16
fix(PM-1610): Show confirm modal while accepting application #1180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable react/jsx-no-bind */ | ||
import { FC } from 'react' | ||
|
||
import { BaseModal, Button } from '~/libs/ui' | ||
|
||
import styles from './styles.module.scss' | ||
|
||
interface ConfirmModalProps { | ||
onClose: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | ||
onApply: () => void | ||
} | ||
|
||
const ConfirmModal: FC<ConfirmModalProps> = props => ( | ||
<BaseModal | ||
onClose={props.onClose as () => void} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Casting |
||
open | ||
size='lg' | ||
title='Confirm to accept as copilot' | ||
buttons={( | ||
<> | ||
<Button primary onClick={props.onApply} label='Confirm' /> | ||
<Button secondary onClick={props.onClose} label='Cancel' /> | ||
</> | ||
)} | ||
> | ||
<div className={styles.applyCopilotModal}> | ||
<div className={styles.info}> | ||
Click 'Confirm' to accept by updating project role to 'Copilot' | ||
and complete this opportunity | ||
</div> | ||
</div> | ||
</BaseModal> | ||
) | ||
|
||
export default ConfirmModal |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { CopilotApplication, CopilotApplicationStatus } from '~/apps/copilots/sr | |
import { IconSolid, Tooltip } from '~/libs/ui' | ||
|
||
import AlreadyMemberModal from './AlreadyMemberModal' | ||
import ConfirmModal from './ConfirmModal' | ||
import styles from './styles.module.scss' | ||
|
||
const CopilotApplicationAction = ( | ||
|
@@ -15,6 +16,7 @@ const CopilotApplicationAction = ( | |
): JSX.Element => { | ||
const { opportunityId }: {opportunityId?: string} = useParams<{ opportunityId?: string }>() | ||
const [showAlreadyMemberModal, setShowAlreadyMemberModal] = useState(false) | ||
const [showConfirmModal, setShowConfirmModal] = useState(false) | ||
const isInvited = useMemo( | ||
() => allCopilotApplications | ||
&& allCopilotApplications.findIndex(item => item.status === CopilotApplicationStatus.INVITED) > -1, | ||
|
@@ -31,19 +33,8 @@ const CopilotApplicationAction = ( | |
|
||
if (copilotApplication.existingMembership) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
setShowAlreadyMemberModal(true) | ||
return | ||
} | ||
|
||
if (opportunityId) { | ||
try { | ||
await assignCopilotOpportunity(opportunityId, copilotApplication.id) | ||
toast.success('Accepted as copilot') | ||
copilotApplication.onApplied() | ||
} catch (e) { | ||
const error = e as Error | ||
toast.error(error.message) | ||
} | ||
|
||
} else { | ||
setShowConfirmModal(true) | ||
} | ||
}, [opportunityId, copilotApplication]) | ||
|
||
|
@@ -57,6 +48,7 @@ const CopilotApplicationAction = ( | |
toast.success('Accepted as copilot') | ||
copilotApplication.onApplied() | ||
setShowAlreadyMemberModal(false) | ||
setShowConfirmModal(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like |
||
} catch (e) { | ||
const error = e as Error | ||
toast.error(error.message) | ||
|
@@ -67,6 +59,7 @@ const CopilotApplicationAction = ( | |
e.preventDefault() | ||
e.stopPropagation() | ||
setShowAlreadyMemberModal(false) | ||
setShowConfirmModal(false) | ||
}, [showAlreadyMemberModal]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dependency array for the |
||
|
||
return ( | ||
|
@@ -83,7 +76,7 @@ const CopilotApplicationAction = ( | |
!isInvited | ||
&& copilotApplication.status === CopilotApplicationStatus.PENDING | ||
&& copilotApplication.opportunityStatus === 'active' && ( | ||
<Tooltip content='Accept Application'> | ||
<Tooltip content='Accept'> | ||
<IconSolid.UserAddIcon /> | ||
</Tooltip> | ||
) | ||
|
@@ -106,6 +99,13 @@ const CopilotApplicationAction = ( | |
copilotApplication={copilotApplication} | ||
/> | ||
)} | ||
|
||
{showConfirmModal && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable |
||
<ConfirmModal | ||
onClose={onCloseModal} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling or user feedback in case |
||
onApply={onApply} | ||
/> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using
/* eslint-disable react/jsx-no-bind */
. Instead, consider refactoring the code to avoid inline function definitions, which can lead to performance issues due to unnecessary re-renders.