Skip to content

Commit 464a95c

Browse files
Merge pull request #452 from daostack/main
Update staging
2 parents 3fe3ab4 + a14849e commit 464a95c

File tree

204 files changed

+17217
-9481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+17217
-9481
lines changed

.run/Admin.run.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Admin" type="js.build_tools.npm">
3+
<package-json value="$PROJECT_DIR$/packages/admin/package.json"/>
4+
<command value="run"/>
5+
<scripts>
6+
<script value="dev"/>
7+
</scripts>
8+
<node-interpreter value="project"/>
9+
<envs/>
10+
<method v="2"/>
11+
</configuration>
12+
</component>

.run/GraphQL.run.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="GraphQL" type="js.build_tools.npm">
3-
<package-json value="$PROJECT_DIR$/packages/graphql/package.json" />
4-
<command value="run" />
3+
<package-json value="$PROJECT_DIR$/packages/graphql/package.json"/>
4+
<command value="run"/>
55
<scripts>
6-
<script value="dev" />
6+
<script value="dev"/>
77
</scripts>
8-
<node-interpreter value="project" />
9-
<envs />
10-
<method v="2" />
8+
<node-interpreter value="/usr/local/bin/node"/>
9+
<package-manager value="/usr/local/Cellar/yarn/1.22.10/libexec"/>
10+
<envs/>
11+
<method v="2"/>
1112
</configuration>
1213
</component>

packages/admin/.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
NEXT_PUBLIC_Firebase.ApiKey="AIzaSyClh8UZh-PDyVgwPrHZwURoA4HWuiXUbR8"
2+
NEXT_PUBLIC_Firebase.ProjectId="common-staging-50741"
3+
NEXT_PUBLIC_Firebase.AuthDomain="common-staging-50741.firebaseapp.com"
4+
NEXT_PUBLIC_Firebase.DatabaseUrl="https://common-staging-50741.firebaseio.com"
5+
16
NEXT_PUBLIC_ADMIN_GRAPH_ENDPOINT=https://us-central1-common-staging-50741.cloudfunctions.net/graph/graphql
27

38
NEXT_PUBLIC_Firebase.apiKey=AIzaSyClh8UZh-PDyVgwPrHZwURoA4HWuiXUbR8

packages/admin/.env.local

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
NEXT_PUBLIC_ADMIN_GRAPH_ENDPOINT=http://localhost:5003/common-staging-50741/us-central1/graph/graphql
1+
NEXT_PUBLIC_Firebase.ApiKey="AIzaSyClh8UZh-PDyVgwPrHZwURoA4HWuiXUbR8"
2+
NEXT_PUBLIC_Firebase.ProjectId="common-staging-50741"
3+
NEXT_PUBLIC_Firebase.AuthDomain="common-staging-50741.firebaseapp.com"
4+
NEXT_PUBLIC_Firebase.DatabaseUrl="https://common-staging-50741.firebaseio.com"
5+
6+
NEXT_PUBLIC_GraphQl.Endpoint=http://localhost:4000/graphql

packages/admin/.env.local.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
NEXT_PUBLIC_Firebase.ApiKey="AIzaSyClh8UZh-PDyVgwPrHZwURoA4HWuiXUbR8"
2+
NEXT_PUBLIC_Firebase.ProjectId="common-staging-50741"
3+
NEXT_PUBLIC_Firebase.AuthDomain="common-staging-50741.firebaseapp.com"
4+
NEXT_PUBLIC_Firebase.DatabaseUrl="https://common-staging-50741.firebaseio.com"
5+
6+
NEXT_PUBLIC_GraphQl.Endpoint=http://localhost:4000/graphql

packages/admin/codegen.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
overwrite: true
2-
schema: "http://localhost:5003/common-staging-50741/us-central1/graph/graphql"
3-
documents: "src/**/*.tsx"
2+
schema: "http://localhost:4000/graphql"
3+
documents:
4+
- "src/core/**/*.tsx"
5+
- "src/components/tables/LatestEventsTable.tsx"
6+
- "src/components/CommonSettings.tsx"
7+
- "src/pages/dashboard/index.tsx"
8+
- "src/pages/commons/index.tsx"
9+
- "src/pages/proposals/index.tsx"
10+
- "src/pages/users/index.tsx"
11+
- "src/pages/commons/details/[commonId].tsx"
12+
- "src/pages/proposals/details/[proposalId].tsx"
13+
- "src/pages/users/details/[userId].tsx"
14+
- "src/pages/notifications/**/*.tsx"
415
generates:
5-
./src/graphql/index.ts:
16+
./src/core/graphql/index.ts:
617
plugins:
718
- "typescript"
819
- "typescript-operations"
920
- "typescript-react-apollo"
10-
./src/graphql/schema.json:
21+
./src/core/graphql/schema.json:
1122
plugins:
1223
- "introspection"
13-
./src/graphql/schema.graphql:
24+
./src/core/graphql/schema.graphql:
1425
plugins:
1526
- schema-ast
1627
config:

packages/admin/next.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
const withImages = require('next-images')
22

3-
module.exports = withImages()
3+
module.exports = withImages({
4+
future: {
5+
webpack5: true
6+
}
7+
});

packages/admin/public/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* {
2+
user-select: none;
3+
}

packages/admin/src/components/CommonSettings.tsx

Lines changed: 92 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,133 @@
11
import React from 'react';
2-
3-
import { gql } from '@apollo/client';
42
import { Tooltip, Row, useToasts, Spacer } from '@geist-ui/react';
5-
import { Settings, Award, RefreshCcw, Edit, Trash2 } from '@geist-ui/react-icons';
3+
import { Award, RefreshCcw, Edit, Trash2, Slash, Settings } from '@geist-ui/react-icons';
4+
import { gql } from '@apollo/client';
65

6+
import { useWhitelistCommonMutation, useDelistCommonMutation } from '@core/graphql';
7+
import { Hoverable } from '@components/Hoverable';
78
import { Centered } from '@components/Centered';
8-
import { useWhitelistCommonMutation } from '@graphql';
99

1010
interface ICommonSettingsProps {
1111
commonId: string;
12+
whitelisted: boolean;
13+
refetch: () => any;
1214
}
1315

1416
const WhitelistCommonMutation = gql`
15-
mutation whitelistCommon($commonId: ID!) {
17+
mutation whitelistCommon($commonId: String!) {
1618
whitelistCommon(commonId: $commonId)
1719
}
1820
`;
1921

20-
export const CommonSettings: React.FC<ICommonSettingsProps> = ({ commonId }) => {
22+
const DelistCommonMutation = gql`
23+
mutation delistCommon($commonId: String!) {
24+
delistCommon(commonId: $commonId)
25+
}
26+
`;
27+
28+
export const CommonSettings: React.FC<ICommonSettingsProps> = ({ commonId, whitelisted, refetch }) => {
2129
const [, setToast] = useToasts();
2230

2331
// - Networking
24-
const [whitelistCommon, { data }] = useWhitelistCommonMutation();
32+
const [whitelistCommon, { data: whitelistResult }] = useWhitelistCommonMutation();
33+
const [delistCommon, { data: delistResult }] = useDelistCommonMutation();
2534

2635
// - Actions
27-
const onCommonWhitelisted = async () => {
36+
const onWhitelistCommon = async () => {
2837
await whitelistCommon({
2938
variables: {
3039
commonId
3140
}
3241
});
42+
43+
if (typeof refetch === 'function') {
44+
refetch();
45+
}
46+
};
47+
48+
const onCommonDelist = async () => {
49+
await delistCommon({
50+
variables: {
51+
commonId
52+
}
53+
});
54+
55+
if (typeof refetch === 'function') {
56+
refetch();
57+
}
3358
};
3459

3560
// - Effects
3661
React.useEffect(() => {
37-
if (data?.whitelistCommon) {
62+
if (whitelistResult?.whitelistCommon) {
3863
setToast({
3964
text: 'Common whitelisted!'
4065
});
4166
}
42-
}, [data]);
67+
}, [whitelistResult]);
68+
69+
React.useEffect(() => {
70+
if (delistResult?.delistCommon) {
71+
setToast({
72+
text: 'Common delisted!'
73+
});
74+
}
75+
}, [delistResult]);
4376

4477
return (
4578
<Tooltip
4679
placement="bottomEnd"
4780
trigger="click"
4881
text={(
49-
<div style={{ width: '250px', margin: '.7rem 0' }}>
50-
<Row style={{ cursor: 'pointer' }} onClick={onCommonWhitelisted}>
51-
<Award/>
52-
<Spacer x={.5} />
53-
Whitelist Common
54-
</Row>
55-
56-
<Spacer y={.7} />
57-
58-
<Row style={{ cursor: 'pointer' }}>
59-
<RefreshCcw/>
60-
<Spacer x={.5} />
61-
Refresh Common Members
62-
</Row>
63-
64-
<Spacer y={.7} />
65-
66-
<Row style={{ cursor: 'pointer' }}>
67-
<Edit/>
68-
<Spacer x={.5} />
69-
Edit Common Details
70-
</Row>
71-
72-
<Spacer y={.7} />
73-
74-
<Row style={{ cursor: 'pointer', color: 'red' }}>
75-
<Trash2 />
76-
<Spacer x={.5} />
77-
Delete Common
78-
</Row>
82+
<div style={{ width: '270px', margin: '.3em -0.7em' }}>
83+
<React.Fragment>
84+
<Hoverable>
85+
{whitelisted
86+
? (
87+
<Row style={{ cursor: 'pointer' }} onClick={onCommonDelist}>
88+
<Slash/>
89+
<Spacer x={.5}/>
90+
Delist Common
91+
</Row>
92+
) : (
93+
<Row style={{ cursor: 'pointer' }} onClick={onWhitelistCommon}>
94+
<Award/>
95+
<Spacer x={.5}/>
96+
Whitelist Common
97+
</Row>
98+
)}
99+
</Hoverable>
100+
101+
<Spacer y={.5}/>
102+
</React.Fragment>
103+
104+
<Hoverable>
105+
<Row style={{ cursor: 'pointer' }}>
106+
<RefreshCcw/>
107+
<Spacer x={.5}/>
108+
Refresh Common Members
109+
</Row>
110+
</Hoverable>
111+
112+
<Spacer y={.5}/>
113+
114+
<Hoverable>
115+
<Row style={{ cursor: 'pointer' }}>
116+
<Edit/>
117+
<Spacer x={.5}/>
118+
Edit Common Details
119+
</Row>
120+
</Hoverable>
121+
122+
<Spacer y={.5}/>
123+
124+
<Hoverable>
125+
<Row style={{ cursor: 'pointer', color: 'red' }}>
126+
<Trash2/>
127+
<Spacer x={.5}/>
128+
Delete Common
129+
</Row>
130+
</Hoverable>
79131
</div>
80132
)}
81133
>
Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PropsWithChildren } from 'react';
22

3-
import { usePermissionsContext, useAuthContext } from '@context';
43
import { useRouter } from 'next/router';
4+
import { useUserContext } from '@core/context';
55

66
interface IHasPermissionProps {
77
permission: string;
@@ -10,43 +10,40 @@ interface IHasPermissionProps {
1010
}
1111

1212
export const HasPermission: React.FC<PropsWithChildren<IHasPermissionProps>> = ({ children, permission, redirect }) => {
13-
const permissionsContext = usePermissionsContext();
14-
const authContext = useAuthContext();
1513
const router = useRouter();
14+
const userContext = useUserContext();
1615

1716
const hasPermission = (permission: string): boolean => {
1817
let hasPermission = false;
1918

20-
if (permissionsContext.loaded) {
19+
if (userContext.loaded) {
20+
const permissions = userContext.permissions;
21+
22+
console.log(permissions);
23+
2124
if (permission.includes('*')) {
22-
hasPermission = permissionsContext.permissions
23-
.some((userPermission) => matchRuleExpl(userPermission, permission));
25+
hasPermission = permissions.some((userPermission) =>
26+
matchRuleExpl(userPermission, permission));
2427
} else {
25-
hasPermission = permissionsContext.permissions.includes(permission);
28+
hasPermission = permissions.includes(permission);
2629
}
2730
}
2831

2932
console.debug(`Permission check for [${permission}]: ${hasPermission}`);
3033

31-
if (!hasPermission && redirect) {
32-
if (authContext.authenticated) {
33-
router.push({
34+
if (!hasPermission && userContext.loaded && redirect) {
35+
router
36+
.push({
3437
pathname: '/error/unauthorized',
3538
query: {
3639
redirected: true,
3740
redirectedFrom: router.pathname,
3841
failedPermission: permission
3942
}
43+
})
44+
.then(() => {
45+
console.log('Redirected unauthorized request');
4046
});
41-
} else {
42-
router.push({
43-
pathname: '/auth',
44-
query: {
45-
redirected: true,
46-
redirectedFrom: router.pathname
47-
}
48-
});
49-
}
5047
}
5148

5249
return true;
@@ -72,13 +69,9 @@ export const HasPermission: React.FC<PropsWithChildren<IHasPermissionProps>> = (
7269
};
7370

7471

75-
return (
72+
return hasPermission(permission) && (
7673
<React.Fragment>
77-
{permissionsContext.loaded && hasPermission(permission) && (
78-
<React.Fragment>
79-
{children}
80-
</React.Fragment>
81-
)}
74+
{children}
8275
</React.Fragment>
8376
);
8477
};

0 commit comments

Comments
 (0)