From ed69e0dcf5a205573b0c464c927898d742723729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20L=C3=A1szl=C3=B3?= <rlacko99@gmail.com> Date: Sat, 7 Nov 2020 21:42:11 +0100 Subject: [PATCH] initial own profile and gql fixes --- client/src/components/Content.tsx | 3 ++- client/src/components/group/GroupInfo.tsx | 9 +++++++-- client/src/components/home/OwnGroupsTable.tsx | 4 ++-- client/src/components/user/OwnProfile.tsx | 11 +++++++++++ .../utils/{CustomCardTable.tsx => CardTable.tsx} | 2 +- client/src/graphql/queries/group/getGroupById.tsx | 6 +++--- 6 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 client/src/components/user/OwnProfile.tsx rename client/src/components/utils/{CustomCardTable.tsx => CardTable.tsx} (93%) diff --git a/client/src/components/Content.tsx b/client/src/components/Content.tsx index 60725de..75e2554 100644 --- a/client/src/components/Content.tsx +++ b/client/src/components/Content.tsx @@ -5,6 +5,7 @@ import { GroupInfo } from './group/GroupInfo'; import { LoggedInHome } from './home/LoggedInHome'; import { LoggedOutHome } from './home/LoggedOutHome'; import { NotAuthorized } from './utils/NotAuthorized'; +import { OwnProfile } from './user/OwnProfile'; import React from 'react'; import { SwitchComponentByAuth } from './utils/SwitchComponentByAuth'; @@ -18,7 +19,7 @@ export const Content: React.FC = () => { <Route path="/admin">admin</Route> <Route path="/qr">qr</Route> <Route path="/profile/me"> - <SwitchComponentByAuth isLoggedIn={'alma'} notLoggedIn={<NotAuthorized />} /> + <SwitchComponentByAuth isLoggedIn={<OwnProfile />} notLoggedIn={<NotAuthorized />} /> </Route> <Route path="/group/:id/info" component={GroupInfo} /> <Route path="/group/:id/admin" component={GroupInfo} /> diff --git a/client/src/components/group/GroupInfo.tsx b/client/src/components/group/GroupInfo.tsx index ae48059..d5421a3 100644 --- a/client/src/components/group/GroupInfo.tsx +++ b/client/src/components/group/GroupInfo.tsx @@ -12,10 +12,15 @@ type TParams = { id: string }; export const GroupInfo: React.FC<RouteComponentProps<TParams>> = ({ match }) => { const theme = useTheme(); - const { loading: groupDataIsLoading, data: groupData } = useQuery<IgetGroupById>( - getGroupById(Number(match.params.id), 'description, memberNum, storageNum, itemNum, name'), + + // TODO get only membership and then other fields + const { loading: groupDataIsLoading, data: groupData, error } = useQuery<IgetGroupById>( + getGroupById('description, memberNum, storageNum, itemNum, name'), + { variables: { groupId: Number(match.params.id) } }, ); + console.log(error); + if (!groupDataIsLoading && !groupData) return ( <> diff --git a/client/src/components/home/OwnGroupsTable.tsx b/client/src/components/home/OwnGroupsTable.tsx index 5ff4d43..e6e8b21 100644 --- a/client/src/components/home/OwnGroupsTable.tsx +++ b/client/src/components/home/OwnGroupsTable.tsx @@ -2,7 +2,7 @@ import { Box, IconButton, Tooltip, Typography } from '@material-ui/core'; import { Group, GroupRole, Member, MemberState } from '../../types/graphqlSchema'; import { IOwnGroupMemberships, ownGroupMemberships } from '../../graphql/queries/group/ownGroupMemberships'; -import { CustomCardTable } from '../utils/CustomCardTable'; +import { CardTable } from '../utils/CardTable'; import GroupIcon from '@material-ui/icons/Group'; import React from 'react'; import SettingsIcon from '@material-ui/icons/Settings'; @@ -55,7 +55,7 @@ export const OwnGroupsTable: React.FC = () => { const history = useHistory(); return ( - <CustomCardTable<ITableRow> + <CardTable<ITableRow> columns={[ { title: 'ID', field: 'id', type: 'numeric', hidden: true }, { diff --git a/client/src/components/user/OwnProfile.tsx b/client/src/components/user/OwnProfile.tsx new file mode 100644 index 0000000..63003ca --- /dev/null +++ b/client/src/components/user/OwnProfile.tsx @@ -0,0 +1,11 @@ +import { Card, CardContent } from '@material-ui/core'; + +import React from 'react'; + +export const OwnProfile: React.FC = () => { + return ( + <Card> + <CardContent>apple</CardContent> + </Card> + ); +}; diff --git a/client/src/components/utils/CustomCardTable.tsx b/client/src/components/utils/CardTable.tsx similarity index 93% rename from client/src/components/utils/CustomCardTable.tsx rename to client/src/components/utils/CardTable.tsx index 62de96e..cbda036 100644 --- a/client/src/components/utils/CustomCardTable.tsx +++ b/client/src/components/utils/CardTable.tsx @@ -14,7 +14,7 @@ const TableCardContent = styled(CardContent)` `; // eslint-disable-next-line @typescript-eslint/ban-types -export const CustomCardTable = <RowData extends object>(props: MaterialTableProps<RowData>): JSX.Element => { +export const CardTable = <RowData extends object>(props: MaterialTableProps<RowData>): JSX.Element => { return ( <Card> <MaterialTable<RowData> diff --git a/client/src/graphql/queries/group/getGroupById.tsx b/client/src/graphql/queries/group/getGroupById.tsx index e5a0a0c..e5834b0 100644 --- a/client/src/graphql/queries/group/getGroupById.tsx +++ b/client/src/graphql/queries/group/getGroupById.tsx @@ -3,10 +3,10 @@ import { Group } from '../../../types/graphqlSchema'; import gql from 'graphql-tag'; // Query -export const getGroupById = (id: number, fields: string): DocumentNode => { +export const getGroupById = (fields: string): DocumentNode => { return gql` - query getGroupById { - group(id: ${id}) { + query getGroupById($groupId: Int!) { + group(id: $groupId) { ownMemberShip { memberState groupRole -- GitLab