From 4403079733d056a2f3653b0f2721f00ad0d8dfde Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 19 Apr 2023 04:01:46 -0700 Subject: [PATCH] Display guidebook validation error --- components/party/Party/index.tsx | 30 ++++++++++++++++++++++++++++++ public/locales/en/common.json | 3 +++ public/locales/ja/common.json | 3 +++ 3 files changed, 36 insertions(+) diff --git a/components/party/Party/index.tsx b/components/party/Party/index.tsx index d4bbc2ca..042c8ad2 100644 --- a/components/party/Party/index.tsx +++ b/components/party/Party/index.tsx @@ -2,8 +2,10 @@ import React, { useEffect, useState } from 'react' import { getCookie } from 'cookies-next' import { useRouter } from 'next/router' import { subscribe, useSnapshot } from 'valtio' +import { useTranslation } from 'next-i18next' import clonedeep from 'lodash.clonedeep' +import Alert from '~components/common/Alert' import PartySegmentedControl from '~components/party/PartySegmentedControl' import PartyDetails from '~components/party/PartyDetails' import PartyHeader from '~components/party/PartyHeader' @@ -40,11 +42,15 @@ const Party = (props: Props) => { // Set up router const router = useRouter() + // Localization + const { t } = useTranslation('common') + // Set up states const { party } = useSnapshot(appState) const [editable, setEditable] = useState(false) const [currentTab, setCurrentTab] = useState(GridType.Weapon) const [refresh, setRefresh] = useState(false) + const [errorMessage, setErrorMessage] = useState('') // Retrieve cookies const cookies = retrieveCookies() @@ -150,9 +156,20 @@ const Party = (props: Props) => { return await api.endpoints.parties .update(props.team.id, payload) .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) { appState.party.extra = enabled @@ -345,6 +362,17 @@ const Party = (props: Props) => { } // Render: JSX components + const errorAlert = () => { + return ( + 0} + message={errorMessage} + cancelAction={cancelAlert} + cancelActionText={t('buttons.confirm')} + /> + ) + } + const navigation = ( ) @@ -395,6 +423,8 @@ const Party = (props: Props) => { return ( + {errorAlert()} +