Fix creating new parties
This commit is contained in:
parent
bbd329532b
commit
2e796c3647
3 changed files with 22 additions and 14 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 = () => (
|
||||
<WeaponGrid key="weapon_grid" editable={true} />
|
||||
)
|
||||
const New = () => {
|
||||
const [cookies, setCookie] = useCookies(['userId'])
|
||||
|
||||
return (
|
||||
<WeaponGrid userId={cookies.user ? cookies.user.user_id : ''} editable={true} exists={false} />
|
||||
)
|
||||
}
|
||||
|
||||
export default New
|
||||
|
|
@ -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<PartyProps> = ({ 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<PartyProps> = ({ match }, state: State) => {
|
|||
return (
|
||||
<div>
|
||||
<WeaponGrid
|
||||
userId={cookies.user_id}
|
||||
userId={cookies.user ? cookies.user.user_id : ''}
|
||||
partyId={partyId}
|
||||
mainhand={mainhand}
|
||||
grid={grid}
|
||||
|
|
|
|||
Loading…
Reference in a new issue