Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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,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,
Expand All @@ -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<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
22 changes: 22 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 All @@ -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,
Expand Down Expand Up @@ -83,6 +86,25 @@ export const acceptOpportunityMatchMutationOptions = (
};
};

export const rejectOpportunityMatchMutationOptions = (
opportunityId: string,
[get, set]: UseUpdateQuery<OpportunityMatch>,
): MutationOptions<EmptyResponse> => {
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<UserCandidatePreferences>,
successCallback?: () => void,
Expand Down