Skip to content

Commit df2ace4

Browse files
committed
Add sandbox invitations to notifications
1 parent 6794cf5 commit df2ace4

File tree

5 files changed

+90
-8
lines changed

5 files changed

+90
-8
lines changed

packages/app/src/app/overmind/namespaces/userNotifications/actions.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ export const notificationsOpened: AsyncAction = async ({ state }) => {
1818
}
1919
`,
2020
});
21+
22+
setTimeout(async () => {
23+
await client.mutate({
24+
mutation: gql`
25+
mutation MarkNotificationsAsRead {
26+
markAllNotificationsAsRead {
27+
id
28+
}
29+
}
30+
`,
31+
});
32+
}, 500);
2133
};
2234

2335
export const notificationsClosed: Action = ({ state }) => {

packages/app/src/app/pages/common/Navigation/Notifications/elements.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const NotificationContainer = styled.div<{
4444
read?: boolean;
4545
success?: boolean;
4646
}>`
47-
transition: 0.3s ease border-color;
47+
transition: 0.3s ease all;
4848
padding: 0.75rem 1rem;
4949
5050
border-left: 2px solid transparent;
@@ -54,14 +54,18 @@ export const NotificationContainer = styled.div<{
5454
${props =>
5555
props.read
5656
? css`
57-
border-left-color: rgba(0, 0, 0, 0.3);
58-
opacity: 0.6;
57+
border-left-color: transparent;
58+
59+
&:hover {
60+
background-color: ${props.theme.background2};
61+
}
5962
`
6063
: css`
61-
border-left-color: ${props.theme.secondary.clearer(0.2)()};
64+
border-left-color: ${props.theme.secondary.clearer(0.3)()};
6265
6366
&:hover {
6467
border-left-color: ${props.theme.secondary()};
68+
background-color: ${props.theme.background2};
6569
}
6670
`};
6771

packages/app/src/app/pages/common/Navigation/Notifications/index.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import gql from 'graphql-tag';
44

55
import { TeamInvite } from './notifications/TeamInvite';
66
import { TeamAccepted } from './notifications/TeamAccepted';
7+
import { SandboxInvitation } from './notifications/SandboxInvitation';
78

89
import {
910
Container,
@@ -53,6 +54,19 @@ const getNotificationComponent = (type, data, read) => {
5354
/>
5455
);
5556
}
57+
if (type === 'sandbox_invitation') {
58+
return (
59+
<SandboxInvitation
60+
read={read}
61+
inviterAvatar={parsedData.inviter_avatar}
62+
inviterName={parsedData.inviter_name}
63+
sandboxId={parsedData.sandbox_id}
64+
sandboxAlias={parsedData.sandbox_alias}
65+
sandboxTitle={parsedData.sandbox_title}
66+
authorization={parsedData.authorization.toUpperCase()}
67+
/>
68+
);
69+
}
5670

5771
return <div />;
5872
};
@@ -85,9 +99,8 @@ export const Notifications = props => (
8599

86100
return (
87101
<div>
88-
{data.me.notifications.map((notification, i) => (
89-
/* eslint-disable react/no-array-index-key */
90-
<div key={i}>
102+
{data.me.notifications.map(notification => (
103+
<div key={notification.id}>
91104
{getNotificationComponent(
92105
notification.type,
93106
notification.data,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
import { Link } from 'react-router-dom';
3+
4+
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
5+
import { Authorization } from 'app/graphql/types';
6+
import { NotificationImage as Image } from '../elements';
7+
import { Container, W } from './elements';
8+
9+
interface ISandboxInvitationProps {
10+
read: boolean;
11+
inviterAvatar: string;
12+
inviterName: string;
13+
sandboxId: string;
14+
sandboxAlias: string | null;
15+
sandboxTitle: string | null;
16+
authorization: Authorization;
17+
}
18+
19+
export const SandboxInvitation = ({
20+
read,
21+
inviterAvatar,
22+
inviterName,
23+
sandboxId,
24+
sandboxAlias,
25+
sandboxTitle,
26+
authorization,
27+
}: ISandboxInvitationProps) => {
28+
const niceSandboxTitle = sandboxTitle || sandboxAlias || sandboxId;
29+
let nicePermissionName = 'view';
30+
if (authorization === Authorization.Comment) {
31+
nicePermissionName = 'comment on';
32+
} else if (authorization === Authorization.WriteCode) {
33+
nicePermissionName = 'edit';
34+
}
35+
36+
return (
37+
<div>
38+
<Container
39+
as={Link}
40+
to={sandboxUrl({ id: sandboxId, alias: sandboxAlias })}
41+
read={read}
42+
>
43+
<Image src={inviterAvatar} />
44+
<div>
45+
<W>{inviterName}</W> invited you to {nicePermissionName}{' '}
46+
<W>{niceSandboxTitle}</W>
47+
</div>
48+
</Container>
49+
</div>
50+
);
51+
};

packages/app/src/app/pages/common/Navigation/Notifications/notifications/elements.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { NotificationContainer } from '../elements';
33

44
export const Container = styled(NotificationContainer)`
55
display: flex;
6+
text-decoration: none;
7+
color: rgba(255, 255, 255, 0.6);
68
`;
79

810
export const Buttons = styled.div`
@@ -44,5 +46,5 @@ export const Button = styled.div<{ decline?: boolean; disabled?: boolean }>`
4446
`;
4547

4648
export const W = styled.span`
47-
color: white;
49+
color: rgba(255, 255, 255, 0.95);
4850
`;

0 commit comments

Comments
 (0)