diff --git a/src/libs/Growl.js b/src/libs/Growl.js deleted file mode 100644 index 81994dd4c255..000000000000 --- a/src/libs/Growl.js +++ /dev/null @@ -1,51 +0,0 @@ -import React from 'react'; -import CONST from '../CONST'; - -const growlRef = React.createRef(); -let resolveIsReadyPromise; -const isReadyPromise = new Promise((resolve) => { - resolveIsReadyPromise = resolve; -}); - -function setIsReady() { - resolveIsReadyPromise(); -} - -/** - * Show the growl notification - * - * @param {String} bodyText - * @param {String} type - * @param {Number} [duration] - */ -function show(bodyText, type, duration = CONST.GROWL.DURATION) { - isReadyPromise.then(() => growlRef.current.show(bodyText, type, duration)); -} - -/** - * Show error growl - * - * @param {String} bodyText - * @param {Number} [duration] - */ -function error(bodyText, duration = CONST.GROWL.DURATION) { - show(bodyText, CONST.GROWL.ERROR, duration); -} - -/** - * Show success growl - * - * @param {String} bodyText - * @param {Number} [duration] - */ -function success(bodyText, duration = CONST.GROWL.DURATION) { - show(bodyText, CONST.GROWL.SUCCESS, duration); -} - -export default { - show, - error, - success, -}; - -export {growlRef, setIsReady}; diff --git a/src/libs/Growl.ts b/src/libs/Growl.ts new file mode 100644 index 000000000000..99c728f0a210 --- /dev/null +++ b/src/libs/Growl.ts @@ -0,0 +1,49 @@ +import React from 'react'; +import CONST from '../CONST'; + +type GrowlRef = { + show?: (bodyText: string, type: string, duration: number) => void; +}; + +const growlRef = React.createRef(); +let resolveIsReadyPromise: undefined | ((value?: unknown) => void); +const isReadyPromise = new Promise((resolve) => { + resolveIsReadyPromise = resolve; +}); + +function setIsReady() { + if (!resolveIsReadyPromise) return; + resolveIsReadyPromise(); +} + +/** + * Show the growl notification + */ +function show(bodyText: string, type: string, duration: number = CONST.GROWL.DURATION) { + isReadyPromise.then(() => { + if (!growlRef?.current?.show) return; + growlRef.current.show(bodyText, type, duration); + }); +} + +/** + * Show error growl + */ +function error(bodyText: string, duration: number = CONST.GROWL.DURATION) { + show(bodyText, CONST.GROWL.ERROR, duration); +} + +/** + * Show success growl + */ +function success(bodyText: string, duration: number = CONST.GROWL.DURATION) { + show(bodyText, CONST.GROWL.SUCCESS, duration); +} + +export default { + show, + error, + success, +}; + +export {growlRef, setIsReady};