diff --git a/packages/ui/src/blocks/notification-hub/notification-hub.tsx b/packages/ui/src/blocks/notification-hub/notification-hub.tsx index 25bba7916..591d972eb 100644 --- a/packages/ui/src/blocks/notification-hub/notification-hub.tsx +++ b/packages/ui/src/blocks/notification-hub/notification-hub.tsx @@ -63,7 +63,6 @@ export function NotificationHub(): JSX.Element { await refechMessages(); }} onClickDelete={async (messageId) => { - console.log('Clicking delete'); await deleteNotificationMessage({ messageId }); refechMessages(); }} diff --git a/packages/ui/src/pages/dashboard/create-project-button.tsx b/packages/ui/src/pages/dashboard/create-project-button.tsx new file mode 100644 index 000000000..58bf6317c --- /dev/null +++ b/packages/ui/src/pages/dashboard/create-project-button.tsx @@ -0,0 +1,96 @@ +import { isENVProd } from '@chirpy-dev/utils'; +import * as React from 'react'; + +import { + Button, + Heading, + IconPlusCircle, + Popover, + Text, +} from '../../components'; +import { useCurrentUser } from '../../contexts'; + +export type CreateProjectButtonProps = { + projectCount?: number; + onCreateProject: () => void; +}; + +export function CreateProjectButton( + props: CreateProjectButtonProps, +): JSX.Element { + const { data } = useCurrentUser(); + // let disabledType: DisabledType | undefined = 'maintenanceMode'; + let disabledType: DisabledType | undefined; + if (isENVProd && (props.projectCount || 0) > 0) { + disabledType = 'projectLimit'; + } else if (!data.email) { + disabledType = 'anonymous'; + } else if (process.env.NEXT_PUBLIC_MAINTENANCE_MODE) { + disabledType = 'maintenanceMode'; + } + const createButtonProps = { + variant: 'solid', + color: 'primary', + className: 'space-x-1', + } as const; + const createButtonChildren = ( + <> + + Create project + + ); + return ( + <> + {disabledType ? ( + + + {createButtonChildren} + + + {DISABLED_MESSAGE_MAP[disabledType]} + + + ) : ( + + )} + + ); +} + +type DisabledType = 'anonymous' | 'projectLimit' | 'maintenanceMode'; +const DISABLED_MESSAGE_MAP: Record = { + anonymous: ( +
+ + Connect an email with your account + + + Otherwise, you may lose access to your project after creation. You can + re-sign in with your email or social media account. + +
+ ), + projectLimit: ( +
+ + Reached the maximum number of projects + + + You can delete an existing project to create a new one. + +
+ ), + maintenanceMode: ( +
+ + System maintenance mode + + + All editing actions are disabled during this period, Please check back + in a little while and try again. + +
+ ), +}; diff --git a/packages/ui/src/pages/dashboard/index.tsx b/packages/ui/src/pages/dashboard/index.tsx index dfdd81a8e..9da91c0ed 100644 --- a/packages/ui/src/pages/dashboard/index.tsx +++ b/packages/ui/src/pages/dashboard/index.tsx @@ -15,11 +15,13 @@ import { Spinner, TextField, Text, + Heading, } from '../../components'; import { useCurrentUser } from '../../contexts'; import { useForm } from '../../hooks'; import { isValidDomain } from '../../utilities'; import { trpcClient } from '../../utilities/trpc-client'; +import { CreateProjectButton } from './create-project-button'; type FormFields = { name: string; @@ -71,41 +73,16 @@ export function Dashboard(): JSX.Element { fetchUserProjects(); }, ); - const disableCreation = isENVProd && (projects?.length || 0) > 0; - const isAnonymousUser = !!data.email; return (
Dashboard - - - - Create project - - - {isAnonymousUser && ( -
- - Sorry, you need an email with your account to create a - project. Otherwise, you may lose access to your project. - - - You can re-sign in with your email or social media account - -
- )} -
-
+
{projects?.length ? (