The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Implement consent toast
Joshen Lime530d9aee511
diff --git a/studio/components/interfaces/App/PortalToast.tsx b/studio/components/interfaces/App/PortalToast.tsxindex 61a546d49d5..946855ee17e 100644--- a/studio/components/interfaces/App/PortalToast.tsx+++ b/studio/components/interfaces/App/PortalToast.tsx@@ -14,7 +14,7 @@ const PortalToast = () => (<Toasterposition="top-right"toastOptions={{- className: '!bg-scale-200 !text-scale-1200 border dark:border-dark !max-w-[380px]',+ className: '!bg-scale-200 !text-scale-1200 border dark:border-dark !max-w-[600px]',style: {padding: '8px',paddingLeft: '16px',@@ -28,35 +28,42 @@ const PortalToast = () => (>{(t) => (<ToastBar toast={t} style={t.style}>- {({ icon, message }) => (- <>- {icon}- <div className="flex items-center">- <div- className={`toast-message w-full ${- t.type === 'loading' ? 'max-w-[350px]' : 'max-w-[260px]'- }`}- >- {message}- </div>- {t.type !== 'loading' && (- <div className="ml-4">- <Button- className="!p-1"- type="text"- onClick={(event) => {- event.preventDefault()- event.stopPropagation()- toast.dismiss(t.id)- }}- >- <IconX size={14} strokeWidth={2} />- </Button>+ {({ icon, message }) => {+ const isConsentToast = t.id === 'consent-toast'+ return (+ <>+ {icon}+ <div className="flex items-center">+ <div+ className={`toast-message w-full ${+ t.type === 'loading'+ ? 'max-w-[380px]'+ : isConsentToast+ ? 'max-w-[800px]'+ : 'max-w-[260px]'+ }`}+ >+ {message}</div>- )}- </div>- </>- )}+ {t.type !== 'loading' && !isConsentToast && (+ <div className="ml-4">+ <Button+ className="!p-1"+ type="text"+ onClick={(event) => {+ event.preventDefault()+ event.stopPropagation()+ toast.dismiss(t.id)+ }}+ >+ <IconX size={14} strokeWidth={2} />+ </Button>+ </div>+ )}+ </div>+ </>+ )+ }}</ToastBar>)}</Toaster>diff --git a/studio/components/ui/ConsentToast.tsx b/studio/components/ui/ConsentToast.tsxnew file mode 100644index 00000000000..3e5f0394a9f--- /dev/null+++ b/studio/components/ui/ConsentToast.tsx@@ -0,0 +1,36 @@+import { noop } from 'lodash'+import Link from 'next/link'+import { Button } from 'ui'++interface ConsentToastProps {+ onAccept: () => void+ onOptOut: () => void+}++const ConsentToast = ({ onAccept = noop, onOptOut = noop }: ConsentToastProps) => {+ return (+ <div className="space-y-3">+ <div className="text-sm">+ <p>+ This site <span className="underline font-medium">does not</span> use cookies 🍪+ </p>+ <p>We use friendly server side analytics to measure and improve your experience</p>+ </div>+ <div className="flex items-center space-x-2">+ <Button type="default" onClick={onAccept}>+ Accept+ </Button>+ <Button type="text" onClick={onOptOut}>+ Opt out+ </Button>+ <Link href="/">+ <a target="_blank" rel="noreferrer">+ <Button type="text">Learn more</Button>+ </a>+ </Link>+ </div>+ </div>+ )+}++export default ConsentToastdiff --git a/studio/components/ui/PageTelemetry.tsx b/studio/components/ui/PageTelemetry.tsxindex 81103f87293..0cf97ebfb44 100644--- a/studio/components/ui/PageTelemetry.tsx+++ b/studio/components/ui/PageTelemetry.tsx@@ -4,9 +4,9 @@ import { post } from 'lib/common/fetch'import { API_URL, IS_PLATFORM } from 'lib/constants'import { observer } from 'mobx-react-lite'import { useRouter } from 'next/router'-import { FC, useEffect } from 'react'+import { PropsWithChildren, useEffect } from 'react'-const PageTelemetry: FC = ({ children }) => {+const PageTelemetry = ({ children }: PropsWithChildren<{}>) => {const router = useRouter()const { ref } = useParams()const telemetryProps = useTelemetryProps()diff --git a/studio/lib/constants/index.ts b/studio/lib/constants/index.tsindex 24743c4904f..0e42a8cb7a9 100644--- a/studio/lib/constants/index.ts+++ b/studio/lib/constants/index.ts@@ -85,3 +85,8 @@ export const STRIPE_PUBLIC_KEY =process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY || 'pk_test_XVwg5IZH3I9Gti98hZw6KRzd00v5858heG'export const USAGE_APPROACHING_THRESHOLD = 0.75++export const LOCAL_STORAGE_KEYS = {+ RECENTLY_VISITED_ORGANIZATION: 'supabase-organization',+ TELEMETRY_CONSENT: 'supabase-consent',+}diff --git a/studio/pages/_app.tsx b/studio/pages/_app.tsxindex 6051ab68387..971c741be89 100644--- a/studio/pages/_app.tsx+++ b/studio/pages/_app.tsx@@ -1,68 +1,69 @@-import '../../packages/ui/build/css/themes/light.css'import '../../packages/ui/build/css/themes/dark.css'+import '../../packages/ui/build/css/themes/light.css'-import 'styles/main.scss'-import 'styles/editor.scss'-import 'styles/ui.scss'-import 'styles/storage.scss'-import 'styles/stripe.scss'-import 'styles/toast.scss'import 'styles/code.scss'-import 'styles/monaco.scss'import 'styles/contextMenu.scss'-import 'styles/react-data-grid-logs.scss'import 'styles/date-picker.scss'-import 'styles/grid.scss'+import 'styles/editor.scss'import 'styles/graphiql-base.scss'+import 'styles/grid.scss'+import 'styles/main.scss'+import 'styles/monaco.scss'+import 'styles/react-data-grid-logs.scss'+import 'styles/storage.scss'+import 'styles/stripe.scss'+import 'styles/toast.scss'+import 'styles/ui.scss'import dayjs from 'dayjs'import customParseFormat from 'dayjs/plugin/customParseFormat'+import relativeTime from 'dayjs/plugin/relativeTime'import timezone from 'dayjs/plugin/timezone'import utc from 'dayjs/plugin/utc'-import relativeTime from 'dayjs/plugin/relativeTime'// @ts-ignoreimport Prism from 'prism-react-renderer/prism'-import Head from 'next/head'-import { AppPropsWithLayout } from 'types'-import { ThemeProvider } from 'common'-import { useEffect, useMemo, useState } from 'react'import { Hydrate, QueryClientProvider } from '@tanstack/react-query'import { ReactQueryDevtools } from '@tanstack/react-query-devtools'-import { RootStore } from 'stores'-import HCaptchaLoadedStore from 'stores/hcaptcha-loaded-store'+import { ThemeProvider } from 'common'+import { useRootQueryClient } from 'data/query-client'import { StoreProvider } from 'hooks'import { AuthProvider } from 'lib/auth'-import { ProfileProvider } from 'lib/profile'import { dart } from 'lib/constants/prism'-import { useRootQueryClient } from 'data/query-client'+import { ProfileProvider } from 'lib/profile'+import { useEffect, useMemo, useRef, useState } from 'react'+import { RootStore } from 'stores'+import HCaptchaLoadedStore from 'stores/hcaptcha-loaded-store'+import { AppPropsWithLayout } from 'types'import {- PortalToast,- RouteValidationWrapper,AppBannerWrapper,CommandMenuWrapper,+ PortalToast,+ RouteValidationWrapper,} from 'components/interfaces/App'-import PageTelemetry from 'components/ui/PageTelemetry'import FlagProvider from 'components/ui/Flag/FlagProvider'+import PageTelemetry from 'components/ui/PageTelemetry'import useAutoAuthRedirect from 'hooks/misc/useAutoAuthRedirect'import { TooltipProvider } from '@radix-ui/react-tooltip'-import Favicons from 'components/head/Favicons'-import { IS_PLATFORM } from 'lib/constants'import { SessionContextProvider } from '@supabase/auth-helpers-react'import { createClient } from '@supabase/supabase-js'+import Favicons from 'components/head/Favicons'+import ConsentToast from 'components/ui/ConsentToast'+import { IS_PLATFORM, LOCAL_STORAGE_KEYS } from 'lib/constants'+import { toast } from 'react-hot-toast'dayjs.extend(customParseFormat)dayjs.extend(utc)dayjs.extend(timezone)dayjs.extend(relativeTime)-dart(Prism)function CustomApp({ Component, pageProps }: AppPropsWithLayout) {+ const consentToastId = useRef<string>()const queryClient = useRootQueryClient()const [rootStore] = useState(() => new RootStore())@@ -78,32 +79,51 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {const getSavingState = () => rootStore.content.savingState- // prompt the user if they try and leave with unsaved content store changes+ const onAcceptConsent = () => {+ if (typeof window !== 'undefined')+ localStorage.setItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT, 'true')+ if (consentToastId.current) toast.dismiss(consentToastId.current)+ }+ const onOptOut = () => {+ if (typeof window !== 'undefined')+ localStorage.setItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT, 'false')+ if (consentToastId.current) toast.dismiss(consentToastId.current)+ }+useEffect(() => {+ // Check for telemetry consent+ if (typeof window !== 'undefined') {+ const hasAcknowledgedConsent = localStorage.getItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT)+ if (hasAcknowledgedConsent === null) {+ consentToastId.current = toast(+ <ConsentToast onAccept={onAcceptConsent} onOptOut={onOptOut} />,+ {+ id: 'consent-toast',+ position: 'bottom-right',+ duration: Infinity,+ }+ )+ }+ }++ // prompt the user if they try and leave with unsaved content store changesconst warningText = 'You have unsaved changes - are you sure you wish to leave this page?'const handleWindowClose = (e: BeforeUnloadEvent) => {const savingState = getSavingState()-const unsavedChanges =savingState === 'UPDATING_REQUIRED' ||savingState === 'UPDATING' ||savingState === 'UPDATING_FAILED'- if (!unsavedChanges) {- return- }-+ if (!unsavedChanges) returne.preventDefault()-return (e.returnValue = warningText)}window.addEventListener('beforeunload', handleWindowClose)- return () => {- window.removeEventListener('beforeunload', handleWindowClose)- }+ return () => window.removeEventListener('beforeunload', handleWindowClose)// eslint-disable-next-line react-hooks/exhaustive-deps}, [])@@ -112,6 +132,7 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {const getLayout = Component.getLayout ?? ((page) => page)const AuthContainer = useMemo(+ // eslint-disable-next-line react/display-name() => (props: any) => {return IS_PLATFORM ? (<SessionContextProvider supabaseClient={supabase as any}>diff --git a/studio/pages/account/me.tsx b/studio/pages/account/me.tsxindex 552600090b7..8159535f08c 100644--- a/studio/pages/account/me.tsx+++ b/studio/pages/account/me.tsx@@ -109,6 +109,10 @@ const ProfileCard = observer(() => {<section><ThemeSettings /></section>++ <section>+ <AnalyticsSettings />+ </section></article>)})@@ -192,3 +196,11 @@ const ThemeSettings = observer(() => {</Panel>)})++const AnalyticsSettings = observer(() => {+ return (+ <Panel title={<h5 key="panel-title">Analytics</h5>}>+ <Panel.Content>Something</Panel.Content>+ </Panel>+ )+})