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