-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
327e22d
commit bda0e54
Showing
4 changed files
with
108 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { type ToastService, toastService } from './toast/toast.js'; |
92 changes: 92 additions & 0 deletions
92
frontend/src/bundles/common/services/toast/toast.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { type createStandaloneToast } from '@chakra-ui/react'; | ||
|
||
type Constructor = { | ||
toast: ReturnType<typeof createStandaloneToast>['toast']; | ||
}; | ||
|
||
class ToastService { | ||
private toast: ReturnType<typeof createStandaloneToast>['toast']; | ||
|
||
public constructor({ toast }: Constructor) { | ||
this.toast = toast; | ||
} | ||
|
||
public warn = (message: string, toastId: string, title: string): void => { | ||
this.toast({ | ||
id: toastId, | ||
title: title, | ||
description: message, | ||
status: 'warning', | ||
duration: 7000, | ||
isClosable: true, | ||
position: 'top-right', | ||
variant: 'solid', | ||
}); | ||
}; | ||
|
||
public loading = ( | ||
message: string, | ||
toastId: string, | ||
title: string, | ||
): void => { | ||
this.toast({ | ||
id: toastId, | ||
title: title, | ||
description: message, | ||
status: 'loading', | ||
duration: 7000, | ||
isClosable: true, | ||
position: 'top-right', | ||
variant: 'solid', | ||
}); | ||
}; | ||
|
||
public error = (message: string, toastId: string, title: string): void => { | ||
this.toast({ | ||
id: toastId, | ||
title: title, | ||
description: message, | ||
status: 'error', | ||
duration: 7000, | ||
isClosable: true, | ||
position: 'top-right', | ||
variant: 'solid', | ||
}); | ||
}; | ||
|
||
public success = ( | ||
message: string, | ||
toastId: string, | ||
title: string, | ||
): void => { | ||
this.toast({ | ||
id: toastId, | ||
title: title, | ||
description: message, | ||
status: 'success', | ||
duration: 7000, | ||
isClosable: true, | ||
position: 'top-right', | ||
variant: 'solid', | ||
}); | ||
}; | ||
|
||
public info = (message: string, toastId: string, title: string): void => { | ||
this.toast({ | ||
id: toastId, | ||
title: title, | ||
description: message, | ||
status: 'info', | ||
duration: 7000, | ||
isClosable: true, | ||
position: 'top-right', | ||
variant: 'solid', | ||
}); | ||
}; | ||
|
||
public isActive = (toastId: string): boolean => { | ||
return this.toast.isActive(toastId); | ||
}; | ||
} | ||
|
||
export { ToastService }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createStandaloneToast } from '@chakra-ui/react'; | ||
|
||
import { theme } from '~/framework/theme/theme.js'; | ||
|
||
import { ToastService } from './toast.service.js'; | ||
|
||
const { toast } = createStandaloneToast({ theme: theme }); | ||
|
||
const toastService = new ToastService({ toast }); | ||
|
||
export { ToastService } from './toast.service.js'; | ||
export { toastService }; |