Send local_id with remix API call

This commit is contained in:
Justin Edmund 2023-02-03 19:34:28 -08:00
parent cd4f808166
commit b36fd03c11
3 changed files with 24 additions and 18 deletions

View file

@ -10,6 +10,7 @@ import Link from 'next/link'
import api from '~utils/api'
import { accountState, initialAccountState } from '~utils/accountState'
import { appState, initialAppState } from '~utils/appState'
import { getLocalId } from '~utils/localId'
import { retrieveLocaleCookies } from '~utils/retrieveCookies'
import {
@ -189,12 +190,16 @@ const Header = () => {
function remixTeam() {
setOriginalName(partySnapshot.name ? partySnapshot.name : t('no_title'))
if (partySnapshot.shortcode)
api.remix(partySnapshot.shortcode).then((response) => {
const remix = response.data.party
router.push(`/p/${remix.shortcode}`)
setRemixToastOpen(true)
})
if (partySnapshot.shortcode) {
const body = getLocalId()
api
.remix({ shortcode: partySnapshot.shortcode, body: body })
.then((response) => {
const remix = response.data.party
router.push(`/p/${remix.shortcode}`)
setRemixToastOpen(true)
})
}
}
function toggleFavorite() {

View file

@ -12,15 +12,16 @@ import SummonGrid from '~components/SummonGrid'
import CharacterGrid from '~components/CharacterGrid'
import api from '~utils/api'
import { accountState } from '~utils/accountState'
import { appState, initialAppState } from '~utils/appState'
import { getLocalId } from '~utils/localId'
import { GridType } from '~utils/enums'
import { retrieveCookies } from '~utils/retrieveCookies'
import { accountCookie, setEditKey, unsetEditKey } from '~utils/userToken'
import { setEditKey, unsetEditKey } from '~utils/userToken'
import type { DetailsObject } from '~types'
import './index.scss'
import { accountState } from '~utils/accountState'
// Props
interface Props {
@ -109,7 +110,7 @@ const Party = (props: Props) => {
if (details) payload = formatDetailsObject(details)
return await api.endpoints.parties
.create({ ...payload, ...localId() })
.create({ ...payload, ...getLocalId() })
.then((response) => storeParty(response.data.party))
}
@ -300,15 +301,6 @@ const Party = (props: Props) => {
}
}
// Methods: Unauth validation
function localId() {
const cookie = accountCookie()
const parsed = JSON.parse(cookie as string)
if (parsed && !parsed.token) {
return { local_id: parsed.userId }
} else return {}
}
// Render: JSX components
const navigation = (
<PartySegmentedControl

9
utils/localId.tsx Normal file
View file

@ -0,0 +1,9 @@
import { accountCookie } from './userToken'
export function getLocalId() {
const cookie = accountCookie()
const parsed = JSON.parse(cookie as string)
if (parsed && !parsed.token) {
return { local_id: parsed.userId }
} else return {}
}