-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.tsx
56 lines (50 loc) · 1.27 KB
/
index.tsx
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
import { DefaultLayout, apolloClient } from '@exogee/graphweaver-admin-ui-components';
import { gql } from '@apollo/client';
import { XeroAuthCodeReceiver } from './xero-auth-code-receiver';
import { AllCompanies, SingleCompany } from './dashboards';
import { TenantsQuery } from './index.generated';
const tenantsQuery = gql`
query Tenants {
tenants {
id
tenantName
}
}
`;
export const customPages = {
routes: () => [
{
// This is where Xero sends us back to after the OAuth flow.
// Its job is to read the code and store it in local storage, then
// redirect back to /.
path: '/xero-auth-code',
element: <XeroAuthCodeReceiver />,
},
{
path: 'xero-dashboard',
element: <DefaultLayout />,
children: [
{
index: true,
element: <AllCompanies />,
},
{
path: ':tenantId',
element: <SingleCompany />,
},
],
},
],
navLinks: async () => {
// To know nav links we need to know the tenants.
const { data } = await apolloClient.query<TenantsQuery>({ query: tenantsQuery });
if (!Array.isArray(data.tenants)) return;
return [
{ name: 'All Companies', route: '/xero-dashboard' },
...data.tenants.map((tenant) => ({
name: tenant.tenantName,
route: `/xero-dashboard/${tenant.id}`,
})),
];
},
};