Display guidebook validation error

This commit is contained in:
Justin Edmund 2023-04-19 04:01:46 -07:00
parent bf77a4ffc7
commit 4403079733
3 changed files with 36 additions and 0 deletions

View file

@ -2,8 +2,10 @@ import React, { useEffect, useState } from 'react'
import { getCookie } from 'cookies-next' import { getCookie } from 'cookies-next'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { subscribe, useSnapshot } from 'valtio' import { subscribe, useSnapshot } from 'valtio'
import { useTranslation } from 'next-i18next'
import clonedeep from 'lodash.clonedeep' import clonedeep from 'lodash.clonedeep'
import Alert from '~components/common/Alert'
import PartySegmentedControl from '~components/party/PartySegmentedControl' import PartySegmentedControl from '~components/party/PartySegmentedControl'
import PartyDetails from '~components/party/PartyDetails' import PartyDetails from '~components/party/PartyDetails'
import PartyHeader from '~components/party/PartyHeader' import PartyHeader from '~components/party/PartyHeader'
@ -40,11 +42,15 @@ const Party = (props: Props) => {
// Set up router // Set up router
const router = useRouter() const router = useRouter()
// Localization
const { t } = useTranslation('common')
// Set up states // Set up states
const { party } = useSnapshot(appState) const { party } = useSnapshot(appState)
const [editable, setEditable] = useState(false) const [editable, setEditable] = useState(false)
const [currentTab, setCurrentTab] = useState<GridType>(GridType.Weapon) const [currentTab, setCurrentTab] = useState<GridType>(GridType.Weapon)
const [refresh, setRefresh] = useState(false) const [refresh, setRefresh] = useState(false)
const [errorMessage, setErrorMessage] = useState('')
// Retrieve cookies // Retrieve cookies
const cookies = retrieveCookies() const cookies = retrieveCookies()
@ -150,9 +156,20 @@ const Party = (props: Props) => {
return await api.endpoints.parties return await api.endpoints.parties
.update(props.team.id, payload) .update(props.team.id, payload)
.then((response) => storeParty(response.data.party)) .then((response) => storeParty(response.data.party))
.catch((error) => {
const data = error.response.data
if (data.errors && Object.keys(data.errors).includes('guidebooks')) {
const message = t('errors.validation.guidebooks')
setErrorMessage(message)
}
})
} }
} }
function cancelAlert() {
setErrorMessage('')
}
function checkboxChanged(enabled: boolean) { function checkboxChanged(enabled: boolean) {
appState.party.extra = enabled appState.party.extra = enabled
@ -345,6 +362,17 @@ const Party = (props: Props) => {
} }
// Render: JSX components // Render: JSX components
const errorAlert = () => {
return (
<Alert
open={errorMessage.length > 0}
message={errorMessage}
cancelAction={cancelAlert}
cancelActionText={t('buttons.confirm')}
/>
)
}
const navigation = ( const navigation = (
<PartySegmentedControl selectedTab={currentTab} onClick={segmentClicked} /> <PartySegmentedControl selectedTab={currentTab} onClick={segmentClicked} />
) )
@ -395,6 +423,8 @@ const Party = (props: Props) => {
return ( return (
<React.Fragment> <React.Fragment>
{errorAlert()}
<PartyHeader <PartyHeader
party={props.team} party={props.team}
new={props.new || false} new={props.new || false}

View file

@ -102,6 +102,9 @@
"description": "The page you're looking for couldn't be found", "description": "The page you're looking for couldn't be found",
"button": "Create a new party" "button": "Create a new party"
}, },
"validation": {
"guidebooks": "You cannot equip more than one of each Sephira Guidebook"
},
"unauthorized": "You don't have permission to perform that action" "unauthorized": "You don't have permission to perform that action"
}, },
"proficiencies": { "proficiencies": {

View file

@ -72,6 +72,9 @@
"description": "探しているページは見つかりませんでした", "description": "探しているページは見つかりませんでした",
"button": "新しい編成を作成" "button": "新しい編成を作成"
}, },
"validation": {
"guidebooks": "セフィラ導本を複数個装備することはできません"
},
"unauthorized": "行ったアクションを実行する権限がありません" "unauthorized": "行ったアクションを実行する権限がありません"
}, },
"header": { "header": {