Skip to content

Commit 93690fb

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
🔨 Switch TeamInvite to use useOvermind (codesandbox#2525)
* 🔨 Switch TeamInvite to use useOvermind * Fix types * Create acceptTeamInvitation & rejectTeamInvitation actions
1 parent 0f2bf6d commit 93690fb

File tree

2 files changed

+84
-73
lines changed

2 files changed

+84
-73
lines changed

‎packages/app/src/app/overmind/actions.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,21 @@ export const refetchSandboxInfo: AsyncAction = async ({
238238
await actions.editor.internal.initializeLiveSandbox(sandbox);
239239
}
240240
};
241+
242+
export const acceptTeamInvitation: Action<{ teamName: string }> = (
243+
{ effects },
244+
{ teamName }
245+
) => {
246+
effects.analytics.track('Team - Invitation Accepted', {});
247+
248+
effects.notificationToast.success(`Accepted invitation to ${teamName}`);
249+
};
250+
251+
export const rejectTeamInvitation: Action<{ teamName: string }> = (
252+
{ effects },
253+
{ teamName }
254+
) => {
255+
effects.analytics.track('Team - Invitation Accepted', {});
256+
257+
effects.notificationToast.success(`Rejected invitation to ${teamName}`);
258+
};
Lines changed: 66 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,79 @@
1-
import React from 'react';
2-
3-
import { Mutation } from 'react-apollo';
4-
import history from 'app/utils/history';
51
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';
84

9-
import { NotificationImage as Image } from '../elements';
10-
import { Container, Buttons, Button, W } from './elements';
5+
import { useOvermind } from 'app/overmind';
116
import {
127
REJECT_TEAM_INVITATION,
138
ACCEPT_TEAM_INVITATION,
14-
} from '../../../../Dashboard/queries';
9+
} from 'app/pages/Dashboard/queries';
10+
import history from 'app/utils/history';
1511

16-
interface Props {
12+
import { NotificationImage as Image } from '../elements';
13+
14+
import { Container, Buttons, Button, W } from './elements';
15+
16+
type Props = {
1717
read: boolean;
1818
teamId: string;
1919
teamName: string;
2020
inviterName: string;
2121
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>
2358

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 });
7165

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

Comments
 (0)