Skip to content

Commit 6d707de

Browse files
authored
feat: add mutation to reject opportunity match (#5034)
1 parent 7ca3319 commit 6d707de

3 files changed

Lines changed: 50 additions & 3 deletions

File tree

packages/shared/src/features/opportunity/components/ResponseButtons.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import type { ReactElement } from 'react';
33

4-
import { useQuery } from '@tanstack/react-query';
4+
import { useMutation, useQuery } from '@tanstack/react-query';
55
import {
66
Button,
77
ButtonSize,
@@ -14,6 +14,9 @@ import { opportunityMatchOptions } from '../queries';
1414
import { OpportunityMatchStatus } from '../types';
1515
import { useLogContext } from '../../../contexts/LogContext';
1616
import { LogEvent } from '../../../lib/log';
17+
import { useToastNotification } from '../../../hooks';
18+
import { rejectOpportunityMatchMutationOptions } from '../mutations';
19+
import { useUpdateQuery } from '../../../hooks/useUpdateQuery';
1720

1821
export 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,

packages/shared/src/features/opportunity/graphql.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ export const ACCEPT_OPPORTUNITY_MATCH = gql`
217217
}
218218
`;
219219

220+
export const REJECT_OPPORTUNITY_MATCH = gql`
221+
mutation RejectOpportunityMatch($id: ID!) {
222+
rejectOpportunityMatch(id: $id) {
223+
_
224+
}
225+
}
226+
`;
227+
220228
export const CLEAR_RESUME_MUTATION = gql`
221229
mutation ClearResume {
222230
clearResume {

packages/shared/src/features/opportunity/mutations.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
CLEAR_RESUME_MUTATION,
1010
EDIT_OPPORTUNITY_MUTATION,
1111
RECOMMEND_OPPORTUNITY_SCREENING_QUESTIONS_MUTATION,
12+
REJECT_OPPORTUNITY_MATCH,
1213
SAVE_OPPORTUNITY_SCREENING_ANSWERS,
1314
UPDATE_CANDIDATE_PREFERENCES_MUTATION,
1415
UPDATE_OPPORTUNITY_STATE_MUTATION,
@@ -17,9 +18,11 @@ import {
1718
import type { EmptyResponse } from '../../graphql/emptyResponse';
1819
import type {
1920
Opportunity,
21+
OpportunityMatch,
2022
OpportunityScreeningAnswer,
2123
UserCandidatePreferences,
2224
} from './types';
25+
import { OpportunityMatchStatus } from './types';
2326
import type { UseUpdateQuery } from '../../hooks/useUpdateQuery';
2427
import type {
2528
opportunityEditContentSchema,
@@ -83,6 +86,25 @@ export const acceptOpportunityMatchMutationOptions = (
8386
};
8487
};
8588

89+
export const rejectOpportunityMatchMutationOptions = (
90+
opportunityId: string,
91+
[get, set]: UseUpdateQuery<OpportunityMatch>,
92+
): MutationOptions<EmptyResponse> => {
93+
const match = get();
94+
return {
95+
mutationFn: async () =>
96+
gqlClient.request(REJECT_OPPORTUNITY_MATCH, {
97+
id: opportunityId,
98+
}),
99+
onSuccess: () => {
100+
set({
101+
...match,
102+
status: OpportunityMatchStatus.CandidateRejected,
103+
});
104+
},
105+
};
106+
};
107+
86108
export const clearResumeMutationOptions = (
87109
[get, set]: UseUpdateQuery<UserCandidatePreferences>,
88110
successCallback?: () => void,

0 commit comments

Comments
 (0)