From 8bb4ef8b54c8898dde40b3758c6a103f12ab9d15 Mon Sep 17 00:00:00 2001 From: Divlo Date: Sat, 9 Apr 2022 11:09:51 +0200 Subject: [PATCH] fix: improve error message for channel deletion --- components/Application/ChannelSettings/ChannelSettings.tsx | 7 ++++++- locales/en/application.json | 1 + locales/fr/application.json | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/components/Application/ChannelSettings/ChannelSettings.tsx b/components/Application/ChannelSettings/ChannelSettings.tsx index 95ebfb1..3eb498e 100644 --- a/components/Application/ChannelSettings/ChannelSettings.tsx +++ b/components/Application/ChannelSettings/ChannelSettings.tsx @@ -2,6 +2,7 @@ import { useRouter } from 'next/router' import { useState } from 'react' import { Form } from 'react-component-form' import useTranslation from 'next-translate/useTranslation' +import axios from 'axios' import { HandleSubmitCallback, useForm } from '../../../hooks/useForm' import { FormState } from '../../design/FormState' @@ -81,7 +82,11 @@ export const ChannelSettings: React.FC = (props) => { await router.push(`/application/${guild.id}/${data.defaultChannelId}`) } catch (error) { setFetchState('error') - setMessageTranslationKey('errors:server-error') + if (axios.isAxiosError(error) && error.response?.status === 400) { + setMessageTranslationKey('application:delete-channel-only-one') + } else { + setMessageTranslationKey('errors:server-error') + } } } diff --git a/locales/en/application.json b/locales/en/application.json index 23b3169..d45129e 100644 --- a/locales/en/application.json +++ b/locales/en/application.json @@ -3,6 +3,7 @@ "create": "Create", "status": "Status", "create-a-channel": "Create a channel", + "delete-channel-only-one": "The guild should have at least one channel. You can't delete the only channel of the guild.", "create-a-guild": "Create a Guild", "create-a-guild-description": "Create your own guild and manage everything.", "join-a-guild": "Join a Guild", diff --git a/locales/fr/application.json b/locales/fr/application.json index 5e95c80..4fd356f 100644 --- a/locales/fr/application.json +++ b/locales/fr/application.json @@ -3,6 +3,7 @@ "create": "Créer", "status": "Statut", "create-a-channel": "Créer un channel", + "delete-channel-only-one": "La guilde doit avoir au moins un channel. Vous ne pouvez pas supprimer le seul channel de la guilde.", "create-a-guild": "Créer une Guilde", "create-a-guild-description": "Créez votre propre guilde et gérez tout.", "join-a-guild": "Rejoindre une Guilde",