Add deleteTeam method
This commit is contained in:
parent
83bb782476
commit
9291e5501a
1 changed files with 31 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
import { useSnapshot } from 'valtio'
|
import { useSnapshot } from 'valtio'
|
||||||
import { useCookies } from 'react-cookie'
|
import { useCookies } from 'react-cookie'
|
||||||
import clonedeep from 'lodash.clonedeep'
|
import clonedeep from 'lodash.clonedeep'
|
||||||
|
|
@ -32,6 +33,9 @@ const Party = (props: Props) => {
|
||||||
} : {}
|
} : {}
|
||||||
}, [cookies.account])
|
}, [cookies.account])
|
||||||
|
|
||||||
|
// Set up router
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
// Set up states
|
// Set up states
|
||||||
const { party } = useSnapshot(appState)
|
const { party } = useSnapshot(appState)
|
||||||
const [currentTab, setCurrentTab] = useState<GridType>(GridType.Weapon)
|
const [currentTab, setCurrentTab] = useState<GridType>(GridType.Weapon)
|
||||||
|
|
@ -81,6 +85,30 @@ const Party = (props: Props) => {
|
||||||
appState.party.name = name
|
appState.party.name = name
|
||||||
appState.party.description = description
|
appState.party.description = description
|
||||||
appState.party.raid = raid
|
appState.party.raid = raid
|
||||||
|
appState.party.updated_at = party.updated_at
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deleting the party
|
||||||
|
function deleteTeam(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
||||||
|
if (appState.party.editable && appState.party.id) {
|
||||||
|
api.endpoints.parties.destroy({ id: appState.party.id, params: headers })
|
||||||
|
.then(() => {
|
||||||
|
// Push to route
|
||||||
|
router.push('/')
|
||||||
|
|
||||||
|
// Clean state
|
||||||
|
const resetState = clonedeep(initialAppState)
|
||||||
|
Object.keys(resetState).forEach((key) => {
|
||||||
|
appState[key] = resetState[key]
|
||||||
|
})
|
||||||
|
|
||||||
|
// Set party to be editable
|
||||||
|
appState.party.editable = true
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,6 +138,8 @@ const Party = (props: Props) => {
|
||||||
appState.party.id = response.data.party.id
|
appState.party.id = response.data.party.id
|
||||||
appState.party.user = response.data.party.user
|
appState.party.user = response.data.party.user
|
||||||
appState.party.favorited = response.data.party.favorited
|
appState.party.favorited = response.data.party.favorited
|
||||||
|
appState.party.created_at = response.data.party.created_at
|
||||||
|
appState.party.updated_at = response.data.party.updated_at
|
||||||
|
|
||||||
// Store the party's user-generated details
|
// Store the party's user-generated details
|
||||||
appState.party.name = response.data.party.name
|
appState.party.name = response.data.party.name
|
||||||
|
|
@ -194,6 +224,7 @@ const Party = (props: Props) => {
|
||||||
{ <PartyDetails
|
{ <PartyDetails
|
||||||
editable={party.editable}
|
editable={party.editable}
|
||||||
updateCallback={updateDetails}
|
updateCallback={updateDetails}
|
||||||
|
deleteCallback={deleteTeam}
|
||||||
/>}
|
/>}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue