11import React from 'react' ;
22import type { ReactElement } from 'react' ;
33
4- import { useQuery } from '@tanstack/react-query' ;
4+ import { useMutation , useQuery } from '@tanstack/react-query' ;
55import {
66 Button ,
77 ButtonSize ,
@@ -14,6 +14,9 @@ import { opportunityMatchOptions } from '../queries';
1414import { OpportunityMatchStatus } from '../types' ;
1515import { useLogContext } from '../../../contexts/LogContext' ;
1616import { LogEvent } from '../../../lib/log' ;
17+ import { useToastNotification } from '../../../hooks' ;
18+ import { rejectOpportunityMatchMutationOptions } from '../mutations' ;
19+ import { useUpdateQuery } from '../../../hooks/useUpdateQuery' ;
1720
1821export const ResponseButtons = ( {
1922 id,
@@ -24,11 +27,25 @@ export const ResponseButtons = ({
2427 className ?: { container ?: string ; buttons ?: string } ;
2528 size ?: ButtonSize ;
2629} ) : ReactElement => {
30+ const { displayToast } = useToastNotification ( ) ;
2731 const { logEvent } = useLogContext ( ) ;
28- const { data } = useQuery ( opportunityMatchOptions ( { id } ) ) ;
32+ const opts = opportunityMatchOptions ( { id } ) ;
33+ const updateQuery = useUpdateQuery ( opts ) ;
34+ const { data } = useQuery ( opts ) ;
2935 const status = data ?. status ;
3036
31- const handleClick = ( event_name : LogEvent ) : void => {
37+ const { mutateAsync : rejectOpportunity } = useMutation ( {
38+ ...rejectOpportunityMatchMutationOptions ( id , updateQuery ) ,
39+ onError : ( ) => {
40+ displayToast ( 'Failed to reject opportunity. Please try again.' ) ;
41+ } ,
42+ } ) ;
43+
44+ const handleClick = async ( event_name : LogEvent ) : Promise < void > => {
45+ if ( event_name === LogEvent . RejectOpportunityMatch ) {
46+ await rejectOpportunity ( ) ;
47+ }
48+
3249 logEvent ( {
3350 event_name,
3451 target_id : id ,
0 commit comments