From ddc849a57d8d5a5c7ce8b1eda3f409a91946e4cf Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Tue, 10 Jun 2025 12:17:30 +0800 Subject: [PATCH] reusable dialogs loading state --- next-ui/src/colada/mutations/update-user.ts | 12 -- next-ui/src/components/dialog/Confirm.vue | 121 +++++++++--------- next-ui/src/components/dialog/ConfirmEdit.vue | 111 ++++++++-------- .../components/dialog/instance/Confirm.vue | 16 ++- .../dialog/instance/ConfirmEdit.vue | 16 ++- next-ui/src/pages/server/users.vue | 100 +++++++++++++-- next-ui/src/stores/dialogs.ts | 22 ++-- 7 files changed, 248 insertions(+), 150 deletions(-) diff --git a/next-ui/src/colada/mutations/update-user.ts b/next-ui/src/colada/mutations/update-user.ts index bdc74a24..a6d32489 100644 --- a/next-ui/src/colada/mutations/update-user.ts +++ b/next-ui/src/colada/mutations/update-user.ts @@ -12,9 +12,6 @@ export const useCreateUser = defineMutation(() => { onSuccess: () => { void queryCache.invalidateQueries({ key: ['users'] }) }, - onError: (error) => { - console.log('create user error', error) - }, }) }) export const useUpdateUser = defineMutation(() => { @@ -28,9 +25,6 @@ export const useUpdateUser = defineMutation(() => { onSuccess: () => { void queryCache.invalidateQueries({ key: ['users'] }) }, - onError: (error) => { - console.log('update user error', error) - }, }) }) @@ -43,9 +37,6 @@ export const useUpdateUserPassword = defineMutation(() => { password: newPassword, }, }), - onError: (error) => { - console.log('update user password error', error) - }, }) }) @@ -59,8 +50,5 @@ export const useDeleteUser = defineMutation(() => { onSuccess: () => { void queryCache.invalidateQueries({ key: ['users'] }) }, - onError: (error) => { - console.log('delete user error', error) - }, }) }) diff --git a/next-ui/src/components/dialog/Confirm.vue b/next-ui/src/components/dialog/Confirm.vue index b2dc2663..5c44c234 100644 --- a/next-ui/src/components/dialog/Confirm.vue +++ b/next-ui/src/components/dialog/Confirm.vue @@ -4,61 +4,66 @@ :activator="activator" :max-width="maxWidth" > - - + - - - - + + + + @@ -74,10 +79,10 @@ const formValid = ref(false) const rules = useRules() -function submitForm() { +function submitForm(isActive: Ref) { if (formValid.value) { emit('confirm') - close() + if (closeOnSave) isActive.value = false } } @@ -88,6 +93,8 @@ export interface DialogConfirmProps { validateText?: string maxWidth?: string | number activator?: Element | string + loading?: boolean + closeOnSave?: boolean } const { @@ -97,9 +104,7 @@ const { validateText = 'confirm', maxWidth = undefined, activator = undefined, + loading = false, + closeOnSave = true, } = defineProps() - -function close() { - showDialog.value = false -} diff --git a/next-ui/src/components/dialog/ConfirmEdit.vue b/next-ui/src/components/dialog/ConfirmEdit.vue index 1ed8232b..330efbb2 100644 --- a/next-ui/src/components/dialog/ConfirmEdit.vue +++ b/next-ui/src/components/dialog/ConfirmEdit.vue @@ -4,57 +4,62 @@ :activator="activator" :max-width="maxWidth" > - - + + @@ -77,6 +82,8 @@ export interface DialogConfirmEditProps { subtitle?: string maxWidth?: string | number activator?: Element | string + loading?: boolean + closeOnSave?: boolean } const { @@ -84,9 +91,7 @@ const { subtitle = undefined, maxWidth = undefined, activator = undefined, + loading = false, + closeOnSave = true, } = defineProps() - -function close() { - showDialog.value = false -} diff --git a/next-ui/src/components/dialog/instance/Confirm.vue b/next-ui/src/components/dialog/instance/Confirm.vue index c94170f2..c86d6792 100644 --- a/next-ui/src/components/dialog/instance/Confirm.vue +++ b/next-ui/src/components/dialog/instance/Confirm.vue @@ -1,8 +1,10 @@