1
0
Fork 0
freesewing/sites/org/hooks/useToast.mjs
2023-02-12 11:20:59 +01:00

35 lines
1.1 KiB
JavaScript

import { useTranslation } from 'next-i18next'
import toastMethod from 'react-hot-toast'
import { Toast } from 'site/components/toast/index.mjs'
/* Custom toast methods */
const toastMethods = (t) => ({
info: (children) => toastMethod.custom(<Toast type="info">{children}</Toast>),
warning: (children) => toastMethod.custom(<Toast type="warning">{children}</Toast>),
error: (children) => toastMethod.custom(<Toast type="error">{children}</Toast>),
accent: (children) => toastMethod.custom(<Toast type="accent">{children}</Toast>),
success: (children) => toastMethod.custom(<Toast type="success">{children}</Toast>),
for: {
settingsSaved: () =>
toastMethod.custom(
<Toast type="success">
<span>{t('settingsSaved')}</span>
</Toast>
),
backendError: () =>
toastMethod.custom(
<Toast type="error">
<span>{t('backendError')} ¯\_()_/¯</span>
</Toast>
),
},
})
/*
* The toast hook
*/
export function useToast() {
const { t } = useTranslation(['toast'])
return toastMethods(t)
}