-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathResponseButtons.tsx
More file actions
88 lines (82 loc) · 2.78 KB
/
ResponseButtons.tsx
File metadata and controls
88 lines (82 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react';
import type { ReactElement } from 'react';
import { useMutation, useQuery } from '@tanstack/react-query';
import {
Button,
ButtonSize,
ButtonVariant,
} from '../../../components/buttons/Button';
import { MiniCloseIcon, VIcon } from '../../../components/icons';
import { opportunityUrl } from '../../../lib/constants';
import Link from '../../../components/utilities/Link';
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,
className,
size = ButtonSize.Small,
}: {
id: string;
className?: { container?: string; buttons?: string };
size?: ButtonSize;
}): ReactElement => {
const { displayToast } = useToastNotification();
const { logEvent } = useLogContext();
const { data } = useQuery(opportunityMatchOptions({ id }));
const status = data?.status;
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,
});
};
return (
<div className={className?.container}>
{(status === OpportunityMatchStatus.Pending ||
status === OpportunityMatchStatus.CandidateRejected) && (
<Link href={`${opportunityUrl}/${id}/decline`} passHref>
<Button
tag="a"
className={className?.buttons}
size={size}
icon={<MiniCloseIcon />}
variant={ButtonVariant.Subtle}
disabled={status === OpportunityMatchStatus.CandidateRejected}
onClick={() => handleClick(LogEvent.RejectOpportunityMatch)}
>
Not for me
</Button>
</Link>
)}
{(status === OpportunityMatchStatus.Pending ||
status === OpportunityMatchStatus.CandidateAccepted) && (
<Link href={`${opportunityUrl}/${id}/questions`} passHref>
<Button
tag="a"
className={className?.buttons}
size={size}
icon={<VIcon />}
variant={ButtonVariant.Primary}
disabled={status === OpportunityMatchStatus.CandidateAccepted}
onClick={() => handleClick(LogEvent.ApproveOpportunityMatch)}
>
Interested
</Button>
</Link>
)}
</div>
);
};