From 649d46ffe334377ba28efbc3013477e157681819 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Mon, 13 Dec 2021 16:13:04 +0700 Subject: [PATCH] Add dismiss button for all types of toast message except loading --- studio/hooks/misc/useStore.tsx | 10 +++++++--- studio/pages/_app.tsx | 26 +++++++++++++++++++++++--- studio/pages/project/[ref]/index.tsx | 28 ++++++++++++++++++++++++++++ studio/types/ui.ts | 5 +++-- 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/studio/hooks/misc/useStore.tsx b/studio/hooks/misc/useStore.tsx index d8d5b639762..ecbec86bad3 100644 --- a/studio/hooks/misc/useStore.tsx +++ b/studio/hooks/misc/useStore.tsx @@ -36,17 +36,21 @@ export const StoreProvider: FC = ({ children, rootStore }) => { autorun(() => { if (ui.notification) { - const { id, category, error, message } = ui.notification + const { id, category, error, message, progress } = ui.notification switch (category) { case 'info': return toast(message, { id }) case 'success': return toast.success(message, { id }) case 'error': - console.error('Notification', { error, message }) + console.error('Error:', { error, message }) return toast.error(message, { id }) case 'loading': - return toast.loading(message, { id }) + if (progress) { + return toast.loading(message, { id }) + } else { + return toast.loading(message, { id }) + } } } }) diff --git a/studio/pages/_app.tsx b/studio/pages/_app.tsx index 4d84e77d6a7..6e9b4fe3fd3 100644 --- a/studio/pages/_app.tsx +++ b/studio/pages/_app.tsx @@ -10,13 +10,15 @@ import 'styles/contextMenu.scss' import Head from 'next/head' import dynamic from 'next/dynamic' +import { useState } from 'react' import type { AppProps } from 'next/app' -import { Toaster } from 'react-hot-toast' +import { Toaster, ToastBar, toast } from 'react-hot-toast' +import { Button, IconX } from '@supabase/ui' + import { RootStore } from 'stores' import { StoreProvider } from 'hooks' import PageTelemetry from 'components/ui/PageTelemetry' import FlagProvider from 'components/ui/Flag/FlagProvider' -import { useState } from 'react' const PortalRootWithNoSSR = dynamic( // @ts-ignore @@ -42,7 +44,25 @@ const PortalToast = () => ( duration: 8000, }, }} - /> + > + {(t) => ( + + {({ icon, message }) => ( + <> + {icon} + {message} + {t.type !== 'loading' && ( +
+ +
+ )} + + )} +
+ )} + ) diff --git a/studio/pages/project/[ref]/index.tsx b/studio/pages/project/[ref]/index.tsx index cf6e38cecc5..aee6a5b3043 100644 --- a/studio/pages/project/[ref]/index.tsx +++ b/studio/pages/project/[ref]/index.tsx @@ -47,6 +47,34 @@ const Home: NextPage = () => { {projectName} + + + + {IS_PLATFORM && project && ( <> {isUndefined(usage) ? ( diff --git a/studio/types/ui.ts b/studio/types/ui.ts index 523e423cf9b..49a2057ff5f 100644 --- a/studio/types/ui.ts +++ b/studio/types/ui.ts @@ -1,6 +1,7 @@ export interface Notification { - id?: string category: 'info' | 'error' | 'success' | 'loading' message: string // Readable message for users to understand - error?: any // Any other errors that needs to be logged out in the console + id?: string + error?: any // Optional: Any other errors that needs to be logged out in the console + progress?: number // Optional: For loading messages to show a progress bar }