on f660f7b help sign in
bridge/src/views/Invite.js
88 lines 2.5 kB history raw
1import React from 'react';
2import * as need from 'lib/need';
3import { Grid, Text } from 'indigo-react';
5import { usePointCursor } from 'store/pointCursor';
6import { useHistory } from 'store/history';
8import View from 'components/View';
9import Crumbs from 'components/Crumbs';
10import Highlighted from 'components/Highlighted';
11import { matchBlinky } from 'components/Blinky';
13import useInvites from 'lib/useInvites';
14import { useSyncOwnedPoints } from 'lib/useSyncPoints';
15import useCurrentPointName from 'lib/useCurrentPointName';
16import useRouter from 'lib/useRouter';
17import { LocalRouterProvider } from 'lib/LocalRouter';
19import InviteUrl from './Invite/InviteUrl';
20import InviteEmail from './Invite/InviteEmail';
21import ViewHeader from 'components/ViewHeader';
23const NAMES = {
24 URL: 'URL',
25 EMAIL: 'EMAIL',
26};
28const VIEWS = {
29 URL: InviteUrl,
30 EMAIL: InviteEmail,
31};
33export default function Invite() {
34 const history = useHistory();
35 const { Route, ...router } = useRouter({
36 names: NAMES,
37 views: VIEWS,
38 initialRoutes: [{ key: NAMES.URL }],
39 });
40 const { pointCursor } = usePointCursor();
41 const point = need.point(pointCursor);
42 const name = useCurrentPointName();
44 // sync the current point
45 useSyncOwnedPoints([point]);
47 // get the invites for the current point
48 const { availableInvites, sentInvites, acceptedInvites } = useInvites(point);
50 // number or loading character
51 const availableInvitesText = matchBlinky(availableInvites);
52 const sentInvitesText = matchBlinky(sentInvites);
53 const acceptedInvitesText = matchBlinky(acceptedInvites);
55 return (
56 <LocalRouterProvider value={router}>
57 <View inset>
58 <Grid className="mb4">
59 <Grid.Item
60 as={Crumbs}
61 routes={[
62 {
63 text: name,
64 action: () => history.pop(),
65 },
66 {
67 text: 'Invite',
68 },
69 ]}
70 full
71 />
72 <Grid.Item full as={ViewHeader}>
73 Invite
74 </Grid.Item>
75 <Grid.Item as={Text} className="f5" full>
76 You currently have{' '}
77 <Highlighted>{availableInvitesText} invitations</Highlighted> left.
78 <br />
79 Out of the <Highlighted>{sentInvitesText}</Highlighted> invites you
80 sent, <Highlighted>{acceptedInvitesText}</Highlighted> have been
81 accepted.
82 </Grid.Item>
83 </Grid>
84 <Route />
85 </View>
86 </LocalRouterProvider>
87 );