-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathConnect.js
More file actions
145 lines (133 loc) · 4.46 KB
/
Connect.js
File metadata and controls
145 lines (133 loc) · 4.46 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { React, useState, useEffect } from 'react';
import * as ga from 'lib/ga';
import ModalAlert from 'components/common/modals/ModalAlert';
import Avatar from 'components/common/elements/Avatar';
import Confetti from 'react-confetti';
import { sendSlackMessage } from 'utils/slack/sendMessageSlack';
import { IoCode } from 'react-icons/io5';
const ButtonConnect = ({
connectionPending,
connectFrom,
connectTo,
size = '',
label,
}) => {
const [showPendingButton, setShowPendingButton] = useState(false);
const [showModal, setShowModal] = useState(false);
const [displayConnectionSuccess, setDisplayConnectionSuccess] =
useState(false);
const actionConnect = async () => {
let formData = {
requester_user_id: connectFrom.userId,
connectTo: connectTo.displayName,
company: null,
};
const response = await fetch(`${process.env.BASEURL}/api/profile/connect`, {
method: 'POST',
body: JSON.stringify(formData),
headers: {
'Content-Type': 'application/json',
},
});
if (response.status != 200) {
console.log('Connection request could not be sent at this time');
} else {
sendSlackMessage(
`CONNECTION REQUEST from ${connectFrom.name} to ${connectTo.name}.`
);
setDisplayConnectionSuccess(true);
ga.event({
action: 'user_sent_connection_request',
});
}
};
useEffect(() => {
setShowPendingButton(connectionPending);
}, [connectionPending]);
return (
<>
{!showPendingButton && (
<button
className={`btn btn-primary ${size}`}
onClick={() => setShowModal(true)}
>
<span>{label ? label : 'Connect'}</span>
</button>
)}
{showPendingButton && (
<div className="btn btn-secondary group" disabled>
<span>Pending...</span>
</div>
)}
<ModalAlert
show={showModal}
setShow={setShowModal}
title="Connection request"
>
{!displayConnectionSuccess && (
<div className="space-y-6 py-6">
<div className="my-0 flex w-full justify-center space-x-2 sm:space-x-4">
<Avatar
image={connectTo?.profilePicUrl}
name={connectTo?.name}
dimensions="w-24 h-24"
/>
<IoCode className="h-auto w-9 text-base-300" />
<Avatar
image={connectFrom?.profilePicUrl}
name={connectFrom?.name}
dimensions="w-24 h-24"
/>
</div>
<div className="mt-6 flex max-w-7xl flex-col items-center">
<span className="text-center text-xl font-semibold sm:text-2xl">
Connect to {connectTo?.name}
</span>
<span className="text-center dark:text-base-300">
Send a connection request.
</span>
</div>
<div className="flex justify-center">
<button
className="btn btn-primary px-10"
onClick={() => actionConnect()}
>
<span>Send</span>
</button>
</div>
</div>
)}
{displayConnectionSuccess && (
<div className="relative overflow-hidden py-6">
<Confetti />
<div className="my-0 flex w-full justify-center space-x-2 sm:-space-x-4">
<Avatar
image={connectTo.profilePicUrl}
name={connectTo.name}
dimensions="w-24 h-24 border-2 border-base-800"
/>
<Avatar
image={connectFrom.profilePicUrl}
name={connectFrom.name}
dimensions="w-24 h-24 border-2 border-base-800"
/>
</div>
<div className="mt-6 mb-6 flex max-w-7xl flex-col items-center sm:px-12">
<span className="space-x-2 text-center text-xl font-bold tracking-tight sm:text-3xl">
Boom!
</span>
<span className="mt-2 space-x-2 text-center text-base font-light tracking-tight sm:text-xl">
Your request was sent to {connectTo.name}.
</span>
<span className="my-4 text-center">
Good luck to you both becoming buddies. <br />
Happy coding!
</span>
</div>
</div>
)}
</ModalAlert>
</>
);
};
export default ButtonConnect;