From 1ee55cc1c20f8b458fe527dcfaceec478b7792d4 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 21 Jan 2023 08:21:43 -0800 Subject: [PATCH] Fix delete party alert and redirect to profile on delete --- components/Alert/index.scss | 2 +- components/Party/index.tsx | 12 +++++- components/PartyDetails/index.tsx | 69 ++++++++++++++----------------- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/components/Alert/index.scss b/components/Alert/index.scss index 33f92d99..dbcff33a 100644 --- a/components/Alert/index.scss +++ b/components/Alert/index.scss @@ -2,7 +2,7 @@ align-items: center; display: flex; justify-content: center; - position: absolute; + position: fixed; height: 100vh; width: 100vw; top: 0; diff --git a/components/Party/index.tsx b/components/Party/index.tsx index fd32525d..07e47403 100644 --- a/components/Party/index.tsx +++ b/components/Party/index.tsx @@ -12,6 +12,7 @@ import CharacterGrid from '~components/CharacterGrid' import api from '~utils/api' import { appState, initialAppState } from '~utils/appState' import { GridType } from '~utils/enums' +import { retrieveCookies } from '~utils/retrieveCookies' import type { DetailsObject } from '~types' import './index.scss' @@ -37,6 +38,9 @@ const Party = (props: Props) => { const { party } = useSnapshot(appState) const [currentTab, setCurrentTab] = useState(GridType.Weapon) + // Retrieve cookies + const cookies = retrieveCookies() + // Reset state on first load useEffect(() => { const resetState = clonedeep(initialAppState) @@ -107,13 +111,17 @@ const Party = (props: Props) => { } // Deleting the party - function deleteTeam(event: React.MouseEvent) { + function deleteTeam() { if (appState.party.editable && appState.party.id) { api.endpoints.parties .destroy({ id: appState.party.id }) .then(() => { // Push to route - router.push('/') + if (cookies && cookies.account.username) { + router.push(`/${cookies.account.username}`) + } else { + router.push('/') + } // Clean state const resetState = clonedeep(initialAppState) diff --git a/components/PartyDetails/index.tsx b/components/PartyDetails/index.tsx index ee7440df..285f8f59 100644 --- a/components/PartyDetails/index.tsx +++ b/components/PartyDetails/index.tsx @@ -9,7 +9,7 @@ import LiteYouTubeEmbed from 'react-lite-youtube-embed' import classNames from 'classnames' import reactStringReplace from 'react-string-replace' -import * as AlertDialog from '@radix-ui/react-alert-dialog' +import Alert from '~components/Alert' import Button from '~components/Button' import CharLimitedFieldset from '~components/CharLimitedFieldset' @@ -40,9 +40,7 @@ interface Props { new: boolean editable: boolean updateCallback: (details: DetailsObject) => void - deleteCallback: ( - event: React.MouseEvent - ) => void + deleteCallback: () => void } const PartyDetails = (props: Props) => { @@ -60,6 +58,7 @@ const PartyDetails = (props: Props) => { const [open, setOpen] = useState(false) const [name, setName] = useState('') + const [alertOpen, setAlertOpen] = useState(false) const [chargeAttack, setChargeAttack] = useState(true) const [fullAuto, setFullAuto] = useState(false) @@ -293,6 +292,14 @@ const PartyDetails = (props: Props) => { toggleDetails() } + function handleClick() { + setAlertOpen(!alertOpen) + } + + function deleteParty() { + props.deleteCallback() + } + function extractYoutubeVideoIds(text: string) { // Initialize an array to store the video IDs const videoIds = [] @@ -381,42 +388,18 @@ const PartyDetails = (props: Props) => { ) } - const deleteButton = () => { + const deleteAlert = () => { if (party.editable) { return ( - - - - - - {t('buttons.delete')} - - - - - - {t('modals.delete_team.title')} - - - {t('modals.delete_team.description')} - -
- - {t('modals.delete_team.buttons.cancel')} - - props.deleteCallback(e)} - > - {t('modals.delete_team.buttons.confirm')} - -
-
-
-
+ setAlertOpen(false)} + cancelActionText={t('modals.delete_team.buttons.cancel')} + message={t('modals.delete_team.description')} + /> ) - } else { - return '' } } @@ -553,7 +536,16 @@ const PartyDetails = (props: Props) => {
- {router.pathname !== '/new' ? deleteButton() : ''} + {router.pathname !== '/new' ? ( +
{readOnly} {editable} + {deleteAlert()} ) }