diff --git a/packages/shared/src/features/opportunity/components/ResponseButtons.tsx b/packages/shared/src/features/opportunity/components/ResponseButtons.tsx index 56683d47439..63c1ac4b8a4 100644 --- a/packages/shared/src/features/opportunity/components/ResponseButtons.tsx +++ b/packages/shared/src/features/opportunity/components/ResponseButtons.tsx @@ -1,7 +1,7 @@ import React from 'react'; import type { ReactElement } from 'react'; -import { useQuery } from '@tanstack/react-query'; +import { useMutation, useQuery } from '@tanstack/react-query'; import { Button, ButtonSize, @@ -14,6 +14,9 @@ import { opportunityMatchOptions } from '../queries'; import { OpportunityMatchStatus } from '../types'; import { useLogContext } from '../../../contexts/LogContext'; import { LogEvent } from '../../../lib/log'; +import { useToastNotification } from '../../../hooks'; +import { rejectOpportunityMatchMutationOptions } from '../mutations'; +import { useUpdateQuery } from '../../../hooks/useUpdateQuery'; export const ResponseButtons = ({ id, @@ -24,11 +27,25 @@ export const ResponseButtons = ({ className?: { container?: string; buttons?: string }; size?: ButtonSize; }): ReactElement => { + const { displayToast } = useToastNotification(); const { logEvent } = useLogContext(); - const { data } = useQuery(opportunityMatchOptions({ id })); + const opts = opportunityMatchOptions({ id }); + const updateQuery = useUpdateQuery(opts); + const { data } = useQuery(opts); const status = data?.status; - const handleClick = (event_name: LogEvent): void => { + const { mutateAsync: rejectOpportunity } = useMutation({ + ...rejectOpportunityMatchMutationOptions(id, updateQuery), + onError: () => { + displayToast('Failed to reject opportunity. Please try again.'); + }, + }); + + const handleClick = async (event_name: LogEvent): Promise => { + if (event_name === LogEvent.RejectOpportunityMatch) { + await rejectOpportunity(); + } + logEvent({ event_name, target_id: id, diff --git a/packages/shared/src/features/opportunity/graphql.ts b/packages/shared/src/features/opportunity/graphql.ts index 9eef519e239..4a631753be9 100644 --- a/packages/shared/src/features/opportunity/graphql.ts +++ b/packages/shared/src/features/opportunity/graphql.ts @@ -217,6 +217,14 @@ export const ACCEPT_OPPORTUNITY_MATCH = gql` } `; +export const REJECT_OPPORTUNITY_MATCH = gql` + mutation RejectOpportunityMatch($id: ID!) { + rejectOpportunityMatch(id: $id) { + _ + } + } +`; + export const CLEAR_RESUME_MUTATION = gql` mutation ClearResume { clearResume { diff --git a/packages/shared/src/features/opportunity/mutations.ts b/packages/shared/src/features/opportunity/mutations.ts index 1eca6d3639c..8ea7a121909 100644 --- a/packages/shared/src/features/opportunity/mutations.ts +++ b/packages/shared/src/features/opportunity/mutations.ts @@ -9,6 +9,7 @@ import { CLEAR_RESUME_MUTATION, EDIT_OPPORTUNITY_MUTATION, RECOMMEND_OPPORTUNITY_SCREENING_QUESTIONS_MUTATION, + REJECT_OPPORTUNITY_MATCH, SAVE_OPPORTUNITY_SCREENING_ANSWERS, UPDATE_CANDIDATE_PREFERENCES_MUTATION, UPDATE_OPPORTUNITY_STATE_MUTATION, @@ -17,9 +18,11 @@ import { import type { EmptyResponse } from '../../graphql/emptyResponse'; import type { Opportunity, + OpportunityMatch, OpportunityScreeningAnswer, UserCandidatePreferences, } from './types'; +import { OpportunityMatchStatus } from './types'; import type { UseUpdateQuery } from '../../hooks/useUpdateQuery'; import type { opportunityEditContentSchema, @@ -83,6 +86,25 @@ export const acceptOpportunityMatchMutationOptions = ( }; }; +export const rejectOpportunityMatchMutationOptions = ( + opportunityId: string, + [get, set]: UseUpdateQuery, +): MutationOptions => { + const match = get(); + return { + mutationFn: async () => + gqlClient.request(REJECT_OPPORTUNITY_MATCH, { + id: opportunityId, + }), + onSuccess: () => { + set({ + ...match, + status: OpportunityMatchStatus.CandidateRejected, + }); + }, + }; +}; + export const clearResumeMutationOptions = ( [get, set]: UseUpdateQuery, successCallback?: () => void,