refactor: add isDemo function
This commit is contained in:
parent
fbb9a1b053
commit
46fd529390
@ -2,6 +2,7 @@
|
||||
|
||||
import { getDb } from '@/db';
|
||||
import { user } from '@/db/schema';
|
||||
import { isDemoWebsite } from '@/lib/demo';
|
||||
import { asc, desc, ilike, or, sql } from 'drizzle-orm';
|
||||
import { createSafeActionClient } from 'next-safe-action';
|
||||
import { z } from 'zod';
|
||||
@ -75,7 +76,8 @@ export const getUsersAction = actionClient
|
||||
]);
|
||||
|
||||
// hide user data in demo website
|
||||
if (process.env.NEXT_PUBLIC_DEMO_WEBSITE === 'true') {
|
||||
const isDemo = isDemoWebsite();
|
||||
if (isDemo) {
|
||||
items = items.map((item) => ({
|
||||
...item,
|
||||
name: 'Demo User',
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { DashboardHeader } from '@/components/dashboard/dashboard-header';
|
||||
import { isDemoWebsite } from '@/lib/demo';
|
||||
import { getSession } from '@/lib/server';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
import { notFound } from 'next/navigation';
|
||||
@ -9,7 +10,7 @@ interface UsersLayoutProps {
|
||||
|
||||
export default async function UsersLayout({ children }: UsersLayoutProps) {
|
||||
// if is demo website, allow user to access admin and user pages, but data is fake
|
||||
const isDemo = process.env.NEXT_PUBLIC_DEMO_WEBSITE === 'true';
|
||||
const isDemo = isDemoWebsite();
|
||||
// Check if user is admin
|
||||
const session = await getSession();
|
||||
if (!session || (session.user.role !== 'admin' && !isDemo)) {
|
||||
|
@ -23,6 +23,7 @@ import { Textarea } from '@/components/ui/textarea';
|
||||
import { useIsMobile } from '@/hooks/use-mobile';
|
||||
import { authClient } from '@/lib/auth-client';
|
||||
import type { User } from '@/lib/auth-types';
|
||||
import { isDemoWebsite } from '@/lib/demo';
|
||||
import { formatDate } from '@/lib/formatter';
|
||||
import { getStripeDashboardCustomerUrl } from '@/lib/urls/urls';
|
||||
import { cn } from '@/lib/utils';
|
||||
@ -53,7 +54,7 @@ export function UserDetailViewer({ user }: UserDetailViewerProps) {
|
||||
const triggerRefresh = useUsersStore((state) => state.triggerRefresh);
|
||||
|
||||
// show fake data in demo website
|
||||
const isDemo = process.env.NEXT_PUBLIC_DEMO_WEBSITE === 'true';
|
||||
const isDemo = isDemoWebsite();
|
||||
|
||||
const handleBan = async () => {
|
||||
if (!banReason) {
|
||||
|
@ -27,6 +27,7 @@ import {
|
||||
TableRow,
|
||||
} from '@/components/ui/table';
|
||||
import type { User } from '@/lib/auth-types';
|
||||
import { isDemoWebsite } from '@/lib/demo';
|
||||
import { formatDate } from '@/lib/formatter';
|
||||
import { getStripeDashboardCustomerUrl } from '@/lib/urls/urls';
|
||||
import { IconCaretDownFilled, IconCaretUpFilled } from '@tabler/icons-react';
|
||||
@ -152,7 +153,7 @@ export function UsersTable({
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
|
||||
// show fake data in demo website
|
||||
const isDemo = process.env.NEXT_PUBLIC_DEMO_WEBSITE === 'true';
|
||||
const isDemo = isDemoWebsite();
|
||||
|
||||
// Map column IDs to translation keys
|
||||
const columnIdToTranslationKey = {
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
} from '@/components/ui/breadcrumb';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { SidebarTrigger } from '@/components/ui/sidebar';
|
||||
import { isDemoWebsite } from '@/lib/demo';
|
||||
import React, { type ReactNode } from 'react';
|
||||
import { CreditsBalanceButton } from '../layout/credits-balance-button';
|
||||
import LocaleSwitcher from '../layout/locale-switcher';
|
||||
@ -30,8 +31,7 @@ export function DashboardHeader({
|
||||
breadcrumbs,
|
||||
actions,
|
||||
}: DashboardHeaderProps) {
|
||||
// if is demo website, allow user to access admin and user pages, but data is fake
|
||||
const isDemo = process.env.NEXT_PUBLIC_DEMO_WEBSITE === 'true';
|
||||
const isDemo = isDemoWebsite();
|
||||
|
||||
return (
|
||||
<header className="flex h-(--header-height) shrink-0 items-center gap-2 border-b transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-(--header-height)">
|
||||
|
@ -10,7 +10,6 @@ import { LocaleLink } from '@/i18n/navigation';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import type React from 'react';
|
||||
import { ThemeSelector } from './theme-selector';
|
||||
|
||||
export function Footer({ className }: React.HTMLAttributes<HTMLElement>) {
|
||||
const t = useTranslations();
|
||||
@ -46,7 +45,7 @@ export function Footer({ className }: React.HTMLAttributes<HTMLElement>) {
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
aria-label={link.title}
|
||||
className="border border-border inline-flex h-8 w-8 items-center
|
||||
className="border border-border inline-flex h-8 w-8 items-center
|
||||
justify-center rounded-full hover:bg-accent hover:text-accent-foreground"
|
||||
>
|
||||
<span className="sr-only">{link.title}</span>
|
||||
@ -99,7 +98,6 @@ export function Footer({ className }: React.HTMLAttributes<HTMLElement>) {
|
||||
</span>
|
||||
|
||||
<div className="flex items-center gap-x-4">
|
||||
{/* <ThemeSelector /> */}
|
||||
<ModeSwitcherHorizontal />
|
||||
</div>
|
||||
</Container>
|
||||
|
@ -1,5 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { isDemoWebsite } from '@/lib/demo';
|
||||
import { Routes } from '@/routes';
|
||||
import type { NestedMenuItem } from '@/types';
|
||||
import {
|
||||
@ -30,7 +31,7 @@ export function getSidebarLinks(): NestedMenuItem[] {
|
||||
const t = useTranslations('Dashboard');
|
||||
|
||||
// if is demo website, allow user to access admin and user pages, but data is fake
|
||||
const isDemo = process.env.NEXT_PUBLIC_DEMO_WEBSITE === 'true';
|
||||
const isDemo = isDemoWebsite();
|
||||
|
||||
return [
|
||||
{
|
||||
|
6
src/lib/demo.ts
Normal file
6
src/lib/demo.ts
Normal file
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* check if the website is a demo website
|
||||
*/
|
||||
export function isDemoWebsite() {
|
||||
return process.env.NEXT_PUBLIC_DEMO_WEBSITE === 'true';
|
||||
}
|
Loading…
Reference in New Issue
Block a user