|
1 | | -import React from 'react'; |
2 | | - |
3 | | -import { Mutation } from 'react-apollo'; |
4 | | -import history from 'app/utils/history'; |
5 | 1 | import { teamOverviewUrl } from '@codesandbox/common/lib/utils/url-generator'; |
6 | | -import track from '@codesandbox/common/lib/utils/analytics'; |
7 | | -import { inject, hooksObserver } from 'app/componentConnectors'; |
| 2 | +import React, { FunctionComponent } from 'react'; |
| 3 | +import { Mutation } from 'react-apollo'; |
8 | 4 |
|
9 | | -import { NotificationImage as Image } from '../elements'; |
10 | | -import { Container, Buttons, Button, W } from './elements'; |
| 5 | +import { useOvermind } from 'app/overmind'; |
11 | 6 | import { |
12 | 7 | REJECT_TEAM_INVITATION, |
13 | 8 | ACCEPT_TEAM_INVITATION, |
14 | | -} from '../../../../Dashboard/queries'; |
| 9 | +} from 'app/pages/Dashboard/queries'; |
| 10 | +import history from 'app/utils/history'; |
15 | 11 |
|
16 | | -interface Props { |
| 12 | +import { NotificationImage as Image } from '../elements'; |
| 13 | + |
| 14 | +import { Container, Buttons, Button, W } from './elements'; |
| 15 | + |
| 16 | +type Props = { |
17 | 17 | read: boolean; |
18 | 18 | teamId: string; |
19 | 19 | teamName: string; |
20 | 20 | inviterName: string; |
21 | 21 | inviterAvatar: string; |
22 | | -} |
| 22 | +}; |
| 23 | +export const TeamInvite: FunctionComponent<Props> = ({ |
| 24 | + read, |
| 25 | + teamId, |
| 26 | + teamName, |
| 27 | + inviterName, |
| 28 | + inviterAvatar, |
| 29 | +}) => { |
| 30 | + const { |
| 31 | + actions: { acceptTeamInvitation, rejectTeamInvitation }, |
| 32 | + } = useOvermind(); |
| 33 | + |
| 34 | + return ( |
| 35 | + <div> |
| 36 | + <Container read={read}> |
| 37 | + <Image src={inviterAvatar} /> |
| 38 | + |
| 39 | + <div> |
| 40 | + <W>{inviterName}</W> invites you to join team <W>{teamName}</W> |
| 41 | + </div> |
| 42 | + </Container> |
| 43 | + |
| 44 | + {!read && ( |
| 45 | + <Buttons> |
| 46 | + <Mutation |
| 47 | + variables={{ teamId }} |
| 48 | + mutation={REJECT_TEAM_INVITATION} |
| 49 | + refetchQueries={['RecentNotifications']} |
| 50 | + onCompleted={() => rejectTeamInvitation({ teamName })} |
| 51 | + > |
| 52 | + {(mutate, { loading }) => ( |
| 53 | + <Button onClick={() => mutate()} disabled={loading} decline> |
| 54 | + Decline |
| 55 | + </Button> |
| 56 | + )} |
| 57 | + </Mutation> |
23 | 58 |
|
24 | | -export const TeamInvite = inject('signals')( |
25 | | - hooksObserver( |
26 | | - ({ |
27 | | - read, |
28 | | - teamId, |
29 | | - teamName, |
30 | | - inviterName, |
31 | | - inviterAvatar, |
32 | | - signals: { notificationAdded }, |
33 | | - }: Props & { signals: any }) => ( |
34 | | - <div> |
35 | | - <Container read={read}> |
36 | | - <Image src={inviterAvatar} /> |
37 | | - <div> |
38 | | - <W>{inviterName}</W> invites you to join team <W>{teamName}</W> |
39 | | - </div> |
40 | | - </Container> |
41 | | - {!read && ( |
42 | | - <Buttons> |
43 | | - <Mutation |
44 | | - variables={{ teamId }} |
45 | | - mutation={REJECT_TEAM_INVITATION} |
46 | | - refetchQueries={['RecentNotifications']} |
47 | | - onCompleted={() => { |
48 | | - track('Team - Invitation Rejected'); |
49 | | - notificationAdded({ |
50 | | - message: `Rejected invitation to ${teamName}`, |
51 | | - type: 'success', |
52 | | - }); |
53 | | - }} |
54 | | - > |
55 | | - {(mutate, { loading }) => ( |
56 | | - <Button onClick={() => mutate()} disabled={loading} decline> |
57 | | - Decline |
58 | | - </Button> |
59 | | - )} |
60 | | - </Mutation> |
61 | | - <Mutation |
62 | | - variables={{ teamId }} |
63 | | - mutation={ACCEPT_TEAM_INVITATION} |
64 | | - refetchQueries={['RecentNotifications', 'TeamsSidebar']} |
65 | | - onCompleted={() => { |
66 | | - track('Team - Invitation Accepted'); |
67 | | - notificationAdded({ |
68 | | - message: `Accepted invitation to ${teamName}`, |
69 | | - type: 'success', |
70 | | - }); |
| 59 | + <Mutation |
| 60 | + variables={{ teamId }} |
| 61 | + mutation={ACCEPT_TEAM_INVITATION} |
| 62 | + refetchQueries={['RecentNotifications', 'TeamsSidebar']} |
| 63 | + onCompleted={() => { |
| 64 | + acceptTeamInvitation({ teamName }); |
71 | 65 |
|
72 | | - history.push(teamOverviewUrl(teamId)); |
73 | | - }} |
74 | | - > |
75 | | - {(mutate, { loading }) => ( |
76 | | - <Button onClick={() => mutate()} disabled={loading}> |
77 | | - Accept |
78 | | - </Button> |
79 | | - )} |
80 | | - </Mutation> |
81 | | - </Buttons> |
82 | | - )} |
83 | | - </div> |
84 | | - ) |
85 | | - ) |
86 | | -); |
| 66 | + history.push(teamOverviewUrl(teamId)); |
| 67 | + }} |
| 68 | + > |
| 69 | + {(mutate, { loading }) => ( |
| 70 | + <Button onClick={() => mutate()} disabled={loading}> |
| 71 | + Accept |
| 72 | + </Button> |
| 73 | + )} |
| 74 | + </Mutation> |
| 75 | + </Buttons> |
| 76 | + )} |
| 77 | + </div> |
| 78 | + ); |
| 79 | +}; |
0 commit comments