From b36fd03c1159a1861a0f350941b56e6374aa32a2 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 3 Feb 2023 19:34:28 -0800 Subject: [PATCH] Send local_id with remix API call --- components/Header/index.tsx | 17 +++++++++++------ components/Party/index.tsx | 16 ++++------------ utils/localId.tsx | 9 +++++++++ 3 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 utils/localId.tsx diff --git a/components/Header/index.tsx b/components/Header/index.tsx index 57cad9d1..91504b11 100644 --- a/components/Header/index.tsx +++ b/components/Header/index.tsx @@ -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() { diff --git a/components/Party/index.tsx b/components/Party/index.tsx index 2878f17a..3bc61ce1 100644 --- a/components/Party/index.tsx +++ b/components/Party/index.tsx @@ -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 = (