Files
rogee ca2a3c2dee
Build and publish Docker images / Build and publish images (push) Successful in 2m35s
fix: localize API error messages
2026-09-14 14:40:49 +08:00

33 lines
918 B
JavaScript

import { emitter } from 'shared/helpers/mitt';
import { parseAPIErrorResponse } from 'dashboard/store/utils/api';
import analyticsHelper from 'dashboard/helper/AnalyticsHelper/index';
/**
* Custom hook to track events
*/
export const useTrack = (...args) => {
try {
return analyticsHelper.track(...args);
} catch (error) {
// Ignore this, tracking is not mission critical
}
return null;
};
/**
* Emits a toast message event using a global emitter.
* @param {string} message - The message to be displayed in the toast.
* @param {Object|null} action - Optional callback function or object to execute.
*/
export const useAlert = (message, action = null) => {
const normalizedMessage =
message === null || message === undefined || message === ''
? message
: parseAPIErrorResponse(message);
emitter.emit('newToastMessage', {
message: normalizedMessage,
action,
});
};