From 19b5d9641e83f0085199b3880151c0f807d6a44d Mon Sep 17 00:00:00 2001 From: Geriano Date: Mon, 18 Jul 2022 15:54:48 +0700 Subject: [PATCH] adding question before refetch data when error --- resources/js/Components/DashboardLayout/Sidebar.vue | 11 ++++++++++- resources/js/Pages/Superuser/Permission/Index.vue | 10 ++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/resources/js/Components/DashboardLayout/Sidebar.vue b/resources/js/Components/DashboardLayout/Sidebar.vue index 5ff0ea5..fa90310 100644 --- a/resources/js/Components/DashboardLayout/Sidebar.vue +++ b/resources/js/Components/DashboardLayout/Sidebar.vue @@ -4,6 +4,7 @@ import axios from 'axios' import { usePage } from '@inertiajs/inertia-vue3' import Builder from './Sidebar/Builder.vue' import Icon from '@/Components/Icon.vue' +import Swal from 'sweetalert2' const self = getCurrentInstance() const menus = ref([]) @@ -14,7 +15,15 @@ const fetch = async () => { const response = await axios.get(route('api.v1.user.menu', user.id)) return menus.value = response.data } catch (e) { - setTimeout(fetch, 1000) + const response = await Swal.fire({ + title: 'Do you want to try again?', + text: `${e}`, + icon: 'error', + showCancelButton: true, + showCloseButton: true, + }) + + response.isConfirmed && fetch() } } diff --git a/resources/js/Pages/Superuser/Permission/Index.vue b/resources/js/Pages/Superuser/Permission/Index.vue index 4aa4300..e97010b 100644 --- a/resources/js/Pages/Superuser/Permission/Index.vue +++ b/resources/js/Pages/Superuser/Permission/Index.vue @@ -22,13 +22,15 @@ const fetch = async () => { const response = await axios.get(route('api.v1.superuser.permission')) permissions.value = response.data } catch (e) { - Swal.fire({ - title: 'error', + const response = await Swal.fire({ + title: 'Do you want to try again?', text: `${e}`, icon: 'error', + showCancelButton: true, + showCloseButton: true, }) - - setTimeout(fetch, 2500) + + response.isConfirmed && fetch() } }