Fix party details when new

This commit is contained in:
Justin Edmund 2022-12-26 00:22:30 -08:00
parent c3f8fa57d0
commit 57a0ce62c2
3 changed files with 43 additions and 20 deletions

View file

@ -238,6 +238,8 @@ const Party = (props: Props) => {
{navigation} {navigation}
<section id="Party">{currentGrid()}</section> <section id="Party">{currentGrid()}</section>
<PartyDetails <PartyDetails
party={props.team}
new={props.new || false}
editable={party.editable} editable={party.editable}
updateCallback={updateDetails} updateCallback={updateDetails}
deleteCallback={deleteTeam} deleteCallback={deleteTeam}

View file

@ -13,6 +13,7 @@ import CharLimitedFieldset from '~components/CharLimitedFieldset'
import RaidDropdown from '~components/RaidDropdown' import RaidDropdown from '~components/RaidDropdown'
import TextFieldset from '~components/TextFieldset' import TextFieldset from '~components/TextFieldset'
import { accountState } from '~utils/accountState'
import { appState } from '~utils/appState' import { appState } from '~utils/appState'
import CheckIcon from '~public/icons/Check.svg' import CheckIcon from '~public/icons/Check.svg'
@ -25,6 +26,8 @@ import { formatTimeAgo } from '~utils/timeAgo'
// Props // Props
interface Props { interface Props {
party?: Party
new: boolean
editable: boolean editable: boolean
updateCallback: (name?: string, description?: string, raid?: Raid) => void updateCallback: (name?: string, description?: string, raid?: Raid) => void
deleteCallback: ( deleteCallback: (
@ -116,34 +119,38 @@ const PartyDetails = (props: Props) => {
toggleDetails() toggleDetails()
} }
const userImage = () => { const userImage = (picture?: string, element?: string) => {
if (party.user) if (picture && element)
return ( return (
<img <img
alt={party.user.avatar.picture} alt={picture}
className={`profile ${party.user.avatar.element}`} className={`profile ${element}`}
srcSet={`/profile/${party.user.avatar.picture}.png, srcSet={`/profile/${picture}.png,
/profile/${party.user.avatar.picture}@2x.png 2x`} /profile/${picture}@2x.png 2x`}
src={`/profile/${party.user.avatar.picture}.png`} src={`/profile/${picture}.png`}
/> />
) )
else return <div className="no-user" /> else return <div className="no-user" />
} }
const userBlock = () => { const userBlock = (username?: string, picture?: string, element?: string) => {
return ( return (
<div className={userClass}> <div className={userClass}>
{userImage()} {userImage(picture, element)}
{party.user ? party.user.username : t('no_user')} {username ? username : t('no_user')}
</div> </div>
) )
} }
const linkedUserBlock = (user: User) => { const linkedUserBlock = (
username?: string,
picture?: string,
element?: string
) => {
return ( return (
<div> <div>
<Link href={`/${user.username}`} passHref> <Link href={`/${username}`} passHref>
<a className={linkClass}>{userBlock()}</a> <a className={linkClass}>{userBlock(username, picture, element)}</a>
</Link> </Link>
</div> </div>
) )
@ -203,7 +210,7 @@ const PartyDetails = (props: Props) => {
<CharLimitedFieldset <CharLimitedFieldset
fieldName="name" fieldName="name"
placeholder="Name your team" placeholder="Name your team"
value={party.name} value={props.party?.name}
limit={50} limit={50}
onChange={handleInputChange} onChange={handleInputChange}
error={errors.name} error={errors.name}
@ -211,7 +218,7 @@ const PartyDetails = (props: Props) => {
/> />
<RaidDropdown <RaidDropdown
showAllRaidsOption={false} showAllRaidsOption={false}
currentRaid={party.raid ? party.raid.slug : undefined} currentRaid={props.party?.raid ? props.party?.raid.slug : undefined}
onChange={receiveRaid} onChange={receiveRaid}
/> />
<TextFieldset <TextFieldset
@ -219,7 +226,7 @@ const PartyDetails = (props: Props) => {
placeholder={ placeholder={
'Write your notes here\n\n\nWatch out for the 50% trigger!\nMake sure to click Fediels 1 first\nGood luck with RNG!' 'Write your notes here\n\n\nWatch out for the 50% trigger!\nMake sure to click Fediels 1 first\nGood luck with RNG!'
} }
value={party.description} value={props.party?.description}
onChange={handleTextAreaChange} onChange={handleTextAreaChange}
error={errors.description} error={errors.description}
ref={descriptionInput} ref={descriptionInput}
@ -249,9 +256,23 @@ const PartyDetails = (props: Props) => {
{party.name ? party.name : 'Untitled'} {party.name ? party.name : 'Untitled'}
</h1> </h1>
<div className="attribution"> <div className="attribution">
{party.user ? linkedUserBlock(party.user) : userBlock()} {accountState.account.authorized && props.new
? linkedUserBlock(
accountState.account.user?.username,
accountState.account.user?.picture,
accountState.account.user?.element
)
: userBlock()}
{party.user && !props.new
? linkedUserBlock(
party.user.username,
party.user.avatar.picture,
party.user.avatar.element
)
: ''}
{!party.user && !props.new ? userBlock() : ''}
{party.raid ? linkedRaidBlock(party.raid) : ''} {party.raid ? linkedRaidBlock(party.raid) : ''}
{party.created_at != undefined ? ( {party.created_at != '' ? (
<time <time
className="last-updated" className="last-updated"
dateTime={new Date(party.created_at).toString()} dateTime={new Date(party.created_at).toString()}

View file

@ -80,8 +80,8 @@ export const initialAppState: AppState = {
extra: false, extra: false,
user: undefined, user: undefined,
favorited: false, favorited: false,
created_at: new Date().toISOString(), created_at: '',
updated_at: new Date().toISOString(), updated_at: '',
}, },
grid: { grid: {
weapons: { weapons: {