Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -14,6 +14,8 @@ 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';

export const ResponseButtons = ({
id,
Expand All @@ -24,11 +26,23 @@ export const ResponseButtons = ({
className?: { container?: string; buttons?: string };
size?: ButtonSize;
}): ReactElement => {
const { displayToast } = useToastNotification();
const { logEvent } = useLogContext();
const { data } = useQuery(opportunityMatchOptions({ id }));
const status = data?.status;

const handleClick = (event_name: LogEvent): void => {
const { mutateAsync: rejectOpportunity } = useMutation({
...rejectOpportunityMatchMutationOptions(id),
onError: () => {
displayToast('Failed to reject opportunity. Please try again.');
},
});

const handleClick = async (event_name: LogEvent): Promise<void> => {
if (event_name === LogEvent.RejectOpportunityMatch) {
await rejectOpportunity();
}

logEvent({
event_name,
target_id: id,
Expand Down
8 changes: 8 additions & 0 deletions packages/shared/src/features/opportunity/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions packages/shared/src/features/opportunity/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -83,6 +84,15 @@ export const acceptOpportunityMatchMutationOptions = (
};
};

export const rejectOpportunityMatchMutationOptions = (
opportunityId: string,
): MutationOptions<EmptyResponse> => ({
mutationFn: async () =>
gqlClient.request(REJECT_OPPORTUNITY_MATCH, {
id: opportunityId,
}),
});

export const clearResumeMutationOptions = (
[get, set]: UseUpdateQuery<UserCandidatePreferences>,
successCallback?: () => void,
Expand Down