forked from storacha/console
-
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.
feat: add a toaster for notifications and other snacks (storacha#91)
Use `react-hot-toast` to introduce "toaster" style notifications: https://react-hot-toast.com/ These should be refined over time, but as an experiment I've introduced this on the "plan change" page and am using it to let the user know when something goes wrong: https://github.com/web3-storage/console/assets/1113/ffe3c1cf-5a42-4471-920c-649bfecb36a4 or when something goes right: https://github.com/web3-storage/console/assets/1113/af7f5bd2-cf20-482c-803c-22d5804ed86a If this seems like a good pattern to everyone I think we should start using it more broadly - no longer will our users be forced to watch a whole file upload just to get feedback about its success or failure!
- Loading branch information
Travis Vachon
authored
Apr 18, 2024
1 parent
a6d75ae
commit 1906d39
Showing
7 changed files
with
76 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,27 @@ | ||
'use client' | ||
|
||
import { Toaster, ToastIcon, resolveValue } from "react-hot-toast" | ||
import { Transition } from "@headlessui/react" | ||
|
||
export default function TailwindToaster () { | ||
return ( | ||
<Toaster position="top-right"> | ||
{(t) => ( | ||
<Transition | ||
appear | ||
show={t.visible} | ||
className="transform p-4 flex bg-white rounded shadow-lg" | ||
enter="transition-all duration-150" | ||
enterFrom="opacity-0 scale-50" | ||
enterTo="opacity-100 scale-100" | ||
leave="transition-all duration-150" | ||
leaveFrom="opacity-100 scale-100" | ||
leaveTo="opacity-0 scale-75" | ||
> | ||
<ToastIcon toast={t} /> | ||
<p className="px-2">{resolveValue(t.message, t)}</p> | ||
</Transition> | ||
)} | ||
</Toaster> | ||
) | ||
} |
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,13 @@ | ||
import { Result } from '@ucanto/interface' | ||
import { toast } from 'react-hot-toast' | ||
|
||
export const ucantoast = async (promise: Promise<Result>, options: any) => { | ||
return toast.promise((async () => { | ||
const result = await promise | ||
if (result.ok) { | ||
return result.ok | ||
} else { | ||
throw result.error | ||
} | ||
})(), options) | ||
} |