index.ts
10 months ago
useModal.ts
10 months ago
useOverviewData.ts
10 months ago
useReachUrls.ts
10 months ago
useScrollLock.ts
9 months ago
useToast.ts
10 months ago
useToast.ts
50 lines
| 1 | import { useHToast } from '@hostinger/hcomponents'; |
| 2 | |
| 3 | let globalToastService: ReturnType<typeof useHToast> | null = null; |
| 4 | |
| 5 | export const useToast = () => { |
| 6 | if (!globalToastService) { |
| 7 | globalToastService = useHToast(); |
| 8 | } |
| 9 | |
| 10 | const showSuccess = (message: string, sticky = false) => { |
| 11 | globalToastService?.add({ |
| 12 | message, |
| 13 | severity: 'success', |
| 14 | sticky |
| 15 | }); |
| 16 | }; |
| 17 | |
| 18 | const showError = (message: string, sticky = false) => { |
| 19 | globalToastService?.add({ |
| 20 | message, |
| 21 | severity: 'failure', |
| 22 | sticky |
| 23 | }); |
| 24 | }; |
| 25 | |
| 26 | const showInfo = (message: string, sticky = false) => { |
| 27 | globalToastService?.add({ |
| 28 | message, |
| 29 | severity: 'info', |
| 30 | sticky |
| 31 | }); |
| 32 | }; |
| 33 | |
| 34 | const showWarning = (message: string, sticky = false) => { |
| 35 | globalToastService?.add({ |
| 36 | message, |
| 37 | severity: 'warning', |
| 38 | sticky |
| 39 | }); |
| 40 | }; |
| 41 | |
| 42 | return { |
| 43 | showSuccess, |
| 44 | showError, |
| 45 | showInfo, |
| 46 | showWarning, |
| 47 | toastService: globalToastService |
| 48 | }; |
| 49 | }; |
| 50 |