Fix creating new parties

This commit is contained in:
Justin Edmund 2020-09-25 04:11:43 -07:00
parent bbd329532b
commit 2e796c3647
3 changed files with 22 additions and 14 deletions

View file

@ -7,13 +7,13 @@ import Button from '~components/Button/Button'
import './WeaponGrid.css' import './WeaponGrid.css'
interface Props { interface Props {
userId: string userId?: string
partyId: string partyId?: string
mainhand: Weapon | undefined mainhand?: Weapon | undefined
grid: GridArray grid?: GridArray
editable: boolean editable: boolean
exists: boolean exists: boolean
found: boolean found?: boolean
} }
type GridArray = { [key: number]: Weapon } type GridArray = { [key: number]: Weapon }
@ -31,11 +31,11 @@ const WeaponGrid = (props: Props) => {
function configure() { function configure() {
setMainhand(props.mainhand) setMainhand(props.mainhand)
setWeapons(props.grid) setWeapons(props.grid || {})
} }
function createParty() { function createParty() {
const body = (props.userId === '') ? {} : { const body = (props.userId === undefined) ? {} : {
party: { party: {
user_id: props.userId 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 export default WeaponGrid

View file

@ -1,9 +1,14 @@
import React from 'react' import React from 'react'
import { useCookies } from 'react-cookie'
import SearchModal from '../../components/SearchModal/SearchModal' import SearchModal from '../../components/SearchModal/SearchModal'
import WeaponGrid from '../../components/WeaponGrid/WeaponGrid' import WeaponGrid from '../../components/WeaponGrid/WeaponGrid'
const New = () => ( const New = () => {
<WeaponGrid key="weapon_grid" editable={true} /> const [cookies, setCookie] = useCookies(['userId'])
)
return (
<WeaponGrid userId={cookies.user ? cookies.user.user_id : ''} editable={true} exists={false} />
)
}
export default New export default New

View file

@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react' 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 { RouteComponentProps, withRouter } from 'react-router-dom'
import api from '~utils/api' import api from '~utils/api'
@ -46,7 +46,10 @@ const Party: React.FC<PartyProps> = ({ match }, state: State) => {
.then(response => { .then(response => {
const party = response.data.party 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) setEditable(true)
let weapons: GridArray = {} let weapons: GridArray = {}
@ -75,7 +78,7 @@ const Party: React.FC<PartyProps> = ({ match }, state: State) => {
return ( return (
<div> <div>
<WeaponGrid <WeaponGrid
userId={cookies.user_id} userId={cookies.user ? cookies.user.user_id : ''}
partyId={partyId} partyId={partyId}
mainhand={mainhand} mainhand={mainhand}
grid={grid} grid={grid}