diff --git a/resources/scripts/app/Subnet.vue b/resources/scripts/app/Subnet.vue index 39a85a0..3ad4520 100644 --- a/resources/scripts/app/Subnet.vue +++ b/resources/scripts/app/Subnet.vue @@ -15,7 +15,14 @@ const results = ref( {} ); /** * Load subnet data based on input */ -const getSubnetData = async () => { +const getSubnetData = async (): void => { + // Check if subnet is filled + if (subnet.value === '') { + errorMsg('Subnet is required'); + + return; + } + try { // Enable loading state isLoading.value = true; @@ -34,10 +41,7 @@ const getSubnetData = async () => { } catch (error) { // Extract and show error message const errorMessage = error.response?.data?.message || 'Something went wrong.'; - $toast.error(errorMessage, { - position: 'top', - duration: 1500, - }); + errorMsg(errorMessage); } finally { // Reset loading state isLoading.value = false; @@ -47,12 +51,24 @@ const getSubnetData = async () => { /** * Reset form by resetting al vars */ -const resetForm = () => { +const resetForm = (): void => { subnet.value = ''; isLoading.value = false; hasResults.value = false; results.value = {}; } + +/** + * Send error message + * + * @param message + */ +const errorMsg = (message: string): void => { + $toast.error(message, { + position: 'top', + duration: 1500, + }); +}