From 2e796c3647c121a5be4bc53ccbf71ac57ec670dc Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 25 Sep 2020 04:11:43 -0700 Subject: [PATCH] Fix creating new parties --- src/components/WeaponGrid/WeaponGrid.tsx | 16 ++++++++-------- src/routes/New/New.tsx | 11 ++++++++--- src/routes/Party/Party.tsx | 9 ++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/components/WeaponGrid/WeaponGrid.tsx b/src/components/WeaponGrid/WeaponGrid.tsx index 975a7177..4933f943 100644 --- a/src/components/WeaponGrid/WeaponGrid.tsx +++ b/src/components/WeaponGrid/WeaponGrid.tsx @@ -7,13 +7,13 @@ import Button from '~components/Button/Button' import './WeaponGrid.css' interface Props { - userId: string - partyId: string - mainhand: Weapon | undefined - grid: GridArray + userId?: string + partyId?: string + mainhand?: Weapon | undefined + grid?: GridArray editable: boolean exists: boolean - found: boolean + found?: boolean } type GridArray = { [key: number]: Weapon } @@ -31,11 +31,11 @@ const WeaponGrid = (props: Props) => { function configure() { setMainhand(props.mainhand) - setWeapons(props.grid) + setWeapons(props.grid || {}) } function createParty() { - const body = (props.userId === '') ? {} : { + const body = (props.userId === undefined) ? {} : { party: { user_id: props.userId } @@ -129,7 +129,7 @@ const WeaponGrid = (props: Props) => { ) } - return (props.found) ? renderGrid() : renderGridNotFound() + return (!props.exists || props.found) ? renderGrid() : renderGridNotFound() } export default WeaponGrid diff --git a/src/routes/New/New.tsx b/src/routes/New/New.tsx index 69454554..28c7cfd9 100644 --- a/src/routes/New/New.tsx +++ b/src/routes/New/New.tsx @@ -1,9 +1,14 @@ import React from 'react' +import { useCookies } from 'react-cookie' import SearchModal from '../../components/SearchModal/SearchModal' import WeaponGrid from '../../components/WeaponGrid/WeaponGrid' -const New = () => ( - -) +const New = () => { + const [cookies, setCookie] = useCookies(['userId']) + + return ( + + ) +} export default New \ No newline at end of file diff --git a/src/routes/Party/Party.tsx b/src/routes/Party/Party.tsx index cd46e87e..20f16000 100644 --- a/src/routes/Party/Party.tsx +++ b/src/routes/Party/Party.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react' -import { withCookies, useCookies, Cookies } from 'react-cookie' +import { withCookies, useCookies } from 'react-cookie' import { RouteComponentProps, withRouter } from 'react-router-dom' import api from '~utils/api' @@ -46,7 +46,10 @@ const Party: React.FC = ({ match }, state: State) => { .then(response => { const party = response.data.party - if (party.user_id === cookies.user_id) + const partyUser = party.user_id + const loggedInUser = (cookies.user) ? cookies.user.user_id : '' + + if (partyUser != undefined && loggedInUser != undefined && partyUser === loggedInUser) setEditable(true) let weapons: GridArray = {} @@ -75,7 +78,7 @@ const Party: React.FC = ({ match }, state: State) => { return (