mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-07 01:56:53 +00:00
fix: prevent duplicate channel action toasts (#5015)
* fix: prevent duplicate channel action toasts * fix: localize api error fallbacks
This commit is contained in:
+32
-4
@@ -70,6 +70,8 @@ export async function handleEnableChannel(
|
||||
toast.success(i18next.t(SUCCESS_MESSAGES.ENABLED))
|
||||
queryClient?.invalidateQueries({ queryKey: channelsQueryKeys.lists() })
|
||||
onSuccess?.()
|
||||
} else {
|
||||
toast.error(response.message || i18next.t(ERROR_MESSAGES.UPDATE_FAILED))
|
||||
}
|
||||
} catch (_error) {
|
||||
toast.error(i18next.t(ERROR_MESSAGES.UPDATE_FAILED))
|
||||
@@ -92,6 +94,8 @@ export async function handleDisableChannel(
|
||||
toast.success(i18next.t(SUCCESS_MESSAGES.DISABLED))
|
||||
queryClient?.invalidateQueries({ queryKey: channelsQueryKeys.lists() })
|
||||
onSuccess?.()
|
||||
} else {
|
||||
toast.error(response.message || i18next.t(ERROR_MESSAGES.UPDATE_FAILED))
|
||||
}
|
||||
} catch (_error) {
|
||||
toast.error(i18next.t(ERROR_MESSAGES.UPDATE_FAILED))
|
||||
@@ -128,6 +132,8 @@ export async function handleDeleteChannel(
|
||||
toast.success(i18next.t(SUCCESS_MESSAGES.DELETED))
|
||||
queryClient?.invalidateQueries({ queryKey: channelsQueryKeys.lists() })
|
||||
onSuccess?.()
|
||||
} else {
|
||||
toast.error(response.message || i18next.t(ERROR_MESSAGES.DELETE_FAILED))
|
||||
}
|
||||
} catch (_error) {
|
||||
toast.error(i18next.t(ERROR_MESSAGES.DELETE_FAILED))
|
||||
@@ -338,6 +344,8 @@ export async function handleBatchDelete(
|
||||
)
|
||||
queryClient?.invalidateQueries({ queryKey: channelsQueryKeys.lists() })
|
||||
onSuccess?.(response.data || ids.length)
|
||||
} else {
|
||||
toast.error(response.message || i18next.t(ERROR_MESSAGES.DELETE_FAILED))
|
||||
}
|
||||
} catch (_error) {
|
||||
toast.error(i18next.t(ERROR_MESSAGES.DELETE_FAILED))
|
||||
@@ -364,8 +372,10 @@ export async function handleBatchEnable(
|
||||
)
|
||||
const results = await Promise.allSettled(promises)
|
||||
|
||||
const successCount = results.filter((r) => r.status === 'fulfilled').length
|
||||
const failCount = results.filter((r) => r.status === 'rejected').length
|
||||
const successCount = results.filter(
|
||||
(r) => r.status === 'fulfilled' && r.value.success
|
||||
).length
|
||||
const failCount = results.length - successCount
|
||||
|
||||
if (successCount > 0) {
|
||||
toast.success(
|
||||
@@ -405,8 +415,10 @@ export async function handleBatchDisable(
|
||||
)
|
||||
const results = await Promise.allSettled(promises)
|
||||
|
||||
const successCount = results.filter((r) => r.status === 'fulfilled').length
|
||||
const failCount = results.filter((r) => r.status === 'rejected').length
|
||||
const successCount = results.filter(
|
||||
(r) => r.status === 'fulfilled' && r.value.success
|
||||
).length
|
||||
const failCount = results.length - successCount
|
||||
|
||||
if (successCount > 0) {
|
||||
toast.success(
|
||||
@@ -448,6 +460,8 @@ export async function handleBatchSetTag(
|
||||
toast.success(i18next.t(SUCCESS_MESSAGES.TAG_SET))
|
||||
queryClient?.invalidateQueries({ queryKey: channelsQueryKeys.lists() })
|
||||
onSuccess?.()
|
||||
} else {
|
||||
toast.error(response.message || i18next.t('Failed to set tag'))
|
||||
}
|
||||
} catch (_error) {
|
||||
toast.error(i18next.t('Failed to set tag'))
|
||||
@@ -474,6 +488,10 @@ export async function handleEnableTagChannels(
|
||||
)
|
||||
queryClient?.invalidateQueries({ queryKey: channelsQueryKeys.lists() })
|
||||
onSuccess?.()
|
||||
} else {
|
||||
toast.error(
|
||||
response.message || i18next.t('Failed to enable tag channels')
|
||||
)
|
||||
}
|
||||
} catch (_error) {
|
||||
toast.error(i18next.t('Failed to enable tag channels'))
|
||||
@@ -496,6 +514,10 @@ export async function handleDisableTagChannels(
|
||||
)
|
||||
queryClient?.invalidateQueries({ queryKey: channelsQueryKeys.lists() })
|
||||
onSuccess?.()
|
||||
} else {
|
||||
toast.error(
|
||||
response.message || i18next.t('Failed to disable tag channels')
|
||||
)
|
||||
}
|
||||
} catch (_error) {
|
||||
toast.error(i18next.t('Failed to disable tag channels'))
|
||||
@@ -523,6 +545,10 @@ export async function handleDeleteAllDisabled(
|
||||
)
|
||||
queryClient?.invalidateQueries({ queryKey: channelsQueryKeys.lists() })
|
||||
onSuccess?.(response.data || 0)
|
||||
} else {
|
||||
toast.error(
|
||||
response.message || i18next.t('Failed to delete disabled channels')
|
||||
)
|
||||
}
|
||||
} catch (_error) {
|
||||
toast.error(i18next.t('Failed to delete disabled channels'))
|
||||
@@ -547,6 +573,8 @@ export async function handleFixAbilities(
|
||||
)
|
||||
queryClient?.invalidateQueries({ queryKey: channelsQueryKeys.lists() })
|
||||
onSuccess?.(response.data)
|
||||
} else {
|
||||
toast.error(response.message || i18next.t('Failed to fix abilities'))
|
||||
}
|
||||
} catch (_error) {
|
||||
toast.error(i18next.t('Failed to fix abilities'))
|
||||
|
||||
Reference in New Issue
Block a user