Skip to content

Commit

Permalink
feat: Adds more fields for user
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshnirmalya committed Apr 10, 2020
1 parent 144f619 commit e68c3c4
Show file tree
Hide file tree
Showing 22 changed files with 739 additions and 193 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."user" DROP COLUMN "first_name";
type: run_sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."user" ADD COLUMN "first_name" bpchar NULL;
type: run_sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."user" DROP COLUMN "last_name";
type: run_sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."user" ADD COLUMN "last_name" bpchar NULL;
type: run_sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- args:
role: user
table:
name: user
schema: public
type: drop_insert_permission
- args:
permission:
check:
id:
_eq: X-Hasura-User-Id
columns:
- active
- email
- password
- updated_at
localPresets:
- key: ""
value: ""
set: {}
role: user
table:
name: user
schema: public
type: create_insert_permission
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- args:
role: user
table:
name: user
schema: public
type: drop_insert_permission
- args:
permission:
check:
id:
_eq: X-Hasura-User-Id
columns:
- id
- password
- created_at
- active
- email
- updated_at
- first_name
- last_name
localPresets:
- key: ""
value: ""
set: {}
role: user
table:
name: user
schema: public
type: create_insert_permission
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- args:
role: user
table:
name: user
schema: public
type: drop_select_permission
- args:
permission:
allow_aggregations: false
columns:
- active
- email
- password
- created_at
- updated_at
- id
computed_fields: []
filter:
id:
_eq: X-Hasura-User-Id
role: user
table:
name: user
schema: public
type: create_select_permission
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- args:
role: user
table:
name: user
schema: public
type: drop_select_permission
- args:
permission:
allow_aggregations: false
columns:
- active
- email
- first_name
- last_name
- password
- created_at
- updated_at
- id
computed_fields: []
filter:
id:
_eq: X-Hasura-User-Id
role: user
table:
name: user
schema: public
type: create_select_permission
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- args:
role: user
table:
name: user
schema: public
type: drop_update_permission
- args:
permission:
columns:
- active
- email
- password
- updated_at
filter:
id:
_eq: X-Hasura-User-Id
localPresets:
- key: ""
value: ""
set: {}
role: user
table:
name: user
schema: public
type: create_update_permission
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- args:
role: user
table:
name: user
schema: public
type: drop_update_permission
- args:
permission:
columns:
- active
- email
- first_name
- last_name
- password
- created_at
- updated_at
- id
filter:
id:
_eq: X-Hasura-User-Id
localPresets:
- key: ""
value: ""
set: {}
role: user
table:
name: user
schema: public
type: create_update_permission
104 changes: 104 additions & 0 deletions packages/frontend/components/navbar/authenticated.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React from "react";
import { Box, Link as _Link, Button, Stack } from "@chakra-ui/core";
import { NextComponentType } from "next";
import Link from "next/link";
import { cookieRemover } from "lib/cookie";
import Router from "next/router";
import gql from "graphql-tag";
import { useQuery } from "react-apollo";
import withApollo from "lib/with-apollo";
import { cookieParser } from "lib/cookie";

const FETCH_USER_QUERY = gql`
query fetchUser($id: uuid!) {
user_by_pk(id: $id) {
id
user_roles {
role {
name
}
}
}
}
`;

const Navbar: NextComponentType = () => {
const currentUserId = cookieParser("user-id");

const { data, loading, error } = useQuery(FETCH_USER_QUERY, {
variables: { id: currentUserId },
fetchPolicy: "network-only",
});

if (loading) {
return <div>Loading...</div>;
}

if (error) {
return <p>Error: {error.message}</p>;
}

const { user_roles } = data.user_by_pk;

const handleSignOut = () => {
cookieRemover("token");
cookieRemover("user-id");

Router.push("/sign-up");
};

return (
<Box borderBottomWidth={1} bg="white">
<Box
maxW="6xl"
w="full"
mx="auto"
d="flex"
justifyContent="space-between"
p={4}
color="gray.700"
>
<Stack
isInline
spacing={4}
align="center"
justifyContent="space-between"
w="full"
>
<Box>
<Stack isInline spacing={4} align="center">
<Box>
<Link href="/">
<_Link>Home</_Link>
</Link>
</Box>
{user_roles[0].role.name === "admin" ? (
<Box>
<Link href="/users">
<_Link>Users</_Link>
</Link>
</Box>
) : null}
</Stack>
</Box>
<Box>
<Stack isInline spacing={4} align="center">
<Box>
<Link href="/my-profile">
<_Link>My Profile</_Link>
</Link>
</Box>
<Box>
<Button variantColor="purple" onClick={handleSignOut}>
Sign out
</Button>
</Box>
</Stack>
</Box>
</Stack>
</Box>
</Box>
);
};

export default withApollo(Navbar);
59 changes: 0 additions & 59 deletions packages/frontend/components/navbar/index.tsx

This file was deleted.

Loading

0 comments on commit e68c3c4

Please sign in to comment.