Admin-teksten en merklogo: Weergavenaam, Wachtwoord wijzigen, Eerste account aanmaken, logo per thema
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import { renderWithProviders } from '@/test/utils';
|
||||
import { BrandLogo } from '@/components/layout/BrandLogo';
|
||||
|
||||
describe('BrandLogo', () => {
|
||||
it('falls back to the application name with its dot when the site has no logo', () => {
|
||||
renderWithProviders(<BrandLogo logo={null} />);
|
||||
|
||||
expect(screen.getByTestId('brand-fallback')).toHaveTextContent('SlpModularCms');
|
||||
expect(screen.queryByTestId('brand-logo')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the default (unthemed) admin the same way', () => {
|
||||
renderWithProviders(<BrandLogo />);
|
||||
|
||||
expect(screen.getByTestId('brand-fallback')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('draws the logo for both colour modes, named for screen readers', () => {
|
||||
renderWithProviders(<BrandLogo logo={{ onLight: '/admin/l.png', onDark: '/admin/d.png' }} />);
|
||||
|
||||
const images = screen.getAllByRole('img', { hidden: true });
|
||||
expect(images).toHaveLength(2);
|
||||
expect(images.map((i) => i.getAttribute('src'))).toEqual(['/admin/l.png', '/admin/d.png']);
|
||||
images.forEach((i) => expect(i).toHaveAttribute('alt', 'SlpModularCms'));
|
||||
expect(screen.queryByTestId('brand-fallback')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { getBrand } from '@/lib/brand';
|
||||
import type { BrandLogo as BrandLogoFiles } from '@/lib/brand';
|
||||
|
||||
interface BrandLogoProps {
|
||||
/** Overrides the site brand; mainly for tests and, later, a logo loaded from site settings. */
|
||||
logo?: BrandLogoFiles | null;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The site's logo, or, when it has none, the application name with its dot (what the admin always
|
||||
* showed). The single place the admin draws the brand: do not hardcode it elsewhere.
|
||||
*/
|
||||
export function BrandLogo({ logo, className }: BrandLogoProps) {
|
||||
const { t } = useTranslation();
|
||||
const resolved = logo === undefined ? getBrand().logo : logo;
|
||||
const name = t('common.appName');
|
||||
|
||||
if (resolved === null) {
|
||||
return (
|
||||
<div className={cn('flex items-center gap-2', className)} data-testid="brand-fallback">
|
||||
<span className="h-3 w-3 rounded-full bg-primary" aria-hidden="true" />
|
||||
<span className="text-lg font-semibold">{name}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn('flex items-center', className)} data-testid="brand-logo">
|
||||
<img src={resolved.onLight} alt={name} className="h-10 w-auto dark:hidden" />
|
||||
<img src={resolved.onDark} alt={name} className="hidden h-10 w-auto dark:block" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Menu } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { BrandLogo } from './BrandLogo';
|
||||
|
||||
interface MobileBarProps {
|
||||
onMenuOpen: () => void;
|
||||
@@ -22,7 +23,7 @@ export function MobileBar({ onMenuOpen }: MobileBarProps) {
|
||||
>
|
||||
<Menu className="size-5" />
|
||||
</button>
|
||||
<span className="font-semibold">{t('common.appName')}</span>
|
||||
<BrandLogo className="[&_img]:h-8 [&_span]:text-base" />
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,6 +81,28 @@ describe('InviteUserDialog', () => {
|
||||
expect(await screen.findByTestId('form-error-banner')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the specific conflict message instead of a generic error', async () => {
|
||||
server.use(
|
||||
http.post(`${API_BASE}/api/v1/Users/invite`, () =>
|
||||
HttpResponse.json(
|
||||
{ status: 409, title: 'Conflict', detail: 'Er staat al een openstaande uitnodiging voor dit e-mailadres.' },
|
||||
{ status: 409 },
|
||||
),
|
||||
),
|
||||
);
|
||||
await openDialog();
|
||||
|
||||
await userEvent.type(screen.getByTestId('invite-dialog-email'), 'dup@example.com');
|
||||
await userEvent.click(screen.getByTestId('invite-dialog-role'));
|
||||
const opts = await screen.findAllByRole('option');
|
||||
await userEvent.click(opts.find((o) => o.textContent === 'User')!);
|
||||
await userEvent.click(screen.getByTestId('invite-dialog-submit'));
|
||||
|
||||
expect(await screen.findByTestId('form-error-banner')).toHaveTextContent(
|
||||
'Er staat al een openstaande uitnodiging voor dit e-mailadres.',
|
||||
);
|
||||
});
|
||||
|
||||
it('resets to step 1 when dialog is closed and reopened', async () => {
|
||||
await openDialog();
|
||||
await userEvent.type(screen.getByTestId('invite-dialog-email'), 'test@example.com');
|
||||
|
||||
@@ -24,7 +24,7 @@ import { FormErrorBanner } from '@/components/ui/FormErrorBanner';
|
||||
import { FieldError } from '@/components/ui/FieldError';
|
||||
import { useInviteUser } from '@/features/users/services/useUsers';
|
||||
import { inviteUserSchema, type InviteUserFormData } from '@/features/users/schemas/users';
|
||||
import { NetworkError } from '@/lib/api-client';
|
||||
import { NetworkError, ProblemDetailsError } from '@/lib/api-client';
|
||||
|
||||
interface InviteUserDialogProps {
|
||||
open: boolean;
|
||||
@@ -40,6 +40,9 @@ export function InviteUserDialog({ open, onOpenChange }: InviteUserDialogProps)
|
||||
onError: (err) => {
|
||||
if (err instanceof NetworkError) {
|
||||
setServerError(t('errors.network'));
|
||||
} else if (err instanceof ProblemDetailsError && err.status === 409 && err.problem.detail) {
|
||||
// The server words the conflict (user exists / open invitation exists) in Dutch.
|
||||
setServerError(err.problem.detail);
|
||||
} else {
|
||||
setServerError(t('errors.generic'));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { renderApp, mockAuthenticated, mockGuest } from '@/test/utils';
|
||||
import { server } from '@/mocks/server';
|
||||
import { API_BASE } from '@/features/auth/mocks/fixtures';
|
||||
import { _resetSetupStatusCache } from '@/router';
|
||||
import i18n from '@/i18n/config';
|
||||
|
||||
beforeEach(() => {
|
||||
_resetSetupStatusCache();
|
||||
@@ -22,6 +23,23 @@ describe('ProfilePage', () => {
|
||||
expect(screen.getByTestId('profile-role-badge')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('titles the password card with what it does, not "Security"', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/profile');
|
||||
|
||||
const title = await screen.findByTestId('profile-security-title', {}, { timeout: 10000 });
|
||||
expect(title).toHaveTextContent(i18n.t('profile.securityTitle'));
|
||||
expect(title).not.toHaveTextContent('Security');
|
||||
expect(i18n.t('profile.securityTitle', { lng: 'nl' })).toBe('Wachtwoord wijzigen');
|
||||
});
|
||||
|
||||
it('labels the name field "Weergavenaam" in Dutch', () => {
|
||||
expect(i18n.t('profile.name', { lng: 'nl' })).toBe('Weergavenaam');
|
||||
expect(i18n.t('inviteComplete.nameLabel', { lng: 'nl' })).toBe('Weergavenaam');
|
||||
expect(i18n.t('setup.nameLabel', { lng: 'nl' })).toBe('Weergavenaam');
|
||||
expect(i18n.t('setup.title', { lng: 'nl' })).toBe('Eerste account aanmaken');
|
||||
});
|
||||
|
||||
it('pre-fills name and email from authenticated user', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/profile');
|
||||
|
||||
@@ -265,7 +265,9 @@ export function ProfilePage() {
|
||||
{/* Security card */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Security</CardTitle>
|
||||
<CardTitle className="text-base" data-testid="profile-security-title">
|
||||
{t('profile.securityTitle')}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import { renderWithProviders } from '@/test/utils';
|
||||
import { DeleteUserDialog } from '@/features/users/components/DeleteUserDialog';
|
||||
import type { UserListItem } from '@/features/users/services/types';
|
||||
|
||||
function userItem(overrides: Partial<UserListItem>): UserListItem {
|
||||
return {
|
||||
id: '22222222-2222-2222-2222-222222222222',
|
||||
email: 'info@x.nl',
|
||||
name: 'Bryan',
|
||||
role: 'User',
|
||||
isActive: true,
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
invitationPending: false,
|
||||
inviteLink: null,
|
||||
...overrides,
|
||||
} as UserListItem;
|
||||
}
|
||||
|
||||
function renderDialog(user: UserListItem) {
|
||||
return renderWithProviders(
|
||||
<DeleteUserDialog user={user} open onOpenChange={vi.fn()} onConfirm={vi.fn()} isPending={false} />,
|
||||
);
|
||||
}
|
||||
|
||||
describe('DeleteUserDialog', () => {
|
||||
it('names the person and their e-mail address', async () => {
|
||||
renderDialog(userItem({}));
|
||||
expect(await screen.findByTestId('delete-user-dialog')).toHaveTextContent('Bryan (info@x.nl)');
|
||||
});
|
||||
|
||||
it('does not repeat the address when the account has no display name', async () => {
|
||||
renderDialog(userItem({ name: 'info@x.nl' }));
|
||||
const text = (await screen.findByTestId('delete-user-dialog')).textContent ?? '';
|
||||
expect(text).toContain('info@x.nl');
|
||||
expect(text).not.toContain('info@x.nl (info@x.nl)');
|
||||
});
|
||||
});
|
||||
@@ -28,6 +28,9 @@ export function DeleteUserDialog({
|
||||
const { t } = useTranslation();
|
||||
if (!user) return null;
|
||||
|
||||
// Accounts without a display name come back with the e-mail address as their name; "a@b (a@b)" is noise.
|
||||
const hasName = user.name.trim() !== '' && user.name.toLowerCase() !== user.email.toLowerCase();
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md" data-testid="delete-user-dialog">
|
||||
@@ -36,7 +39,9 @@ export function DeleteUserDialog({
|
||||
<DialogDescription>
|
||||
{user.invitationPending
|
||||
? t('users.delete.descriptionPending', { email: user.email })
|
||||
: t('users.delete.description', { name: user.name, email: user.email })}
|
||||
: hasName
|
||||
? t('users.delete.description', { name: user.name, email: user.email })
|
||||
: t('users.delete.descriptionNoName', { email: user.email })}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter className="gap-2">
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
}
|
||||
},
|
||||
"setup": {
|
||||
"title": "System Setup",
|
||||
"nameLabel": "Full name",
|
||||
"title": "Create first account",
|
||||
"nameLabel": "Display name",
|
||||
"emailLabel": "Email",
|
||||
"passwordLabel": "Password",
|
||||
"confirmPasswordLabel": "Confirm password",
|
||||
@@ -53,7 +53,7 @@
|
||||
"inviteComplete": {
|
||||
"title": "Complete your account",
|
||||
"emailLabel": "Email",
|
||||
"nameLabel": "Full name",
|
||||
"nameLabel": "Display name",
|
||||
"passwordLabel": "Password",
|
||||
"confirmPasswordLabel": "Confirm password",
|
||||
"submitButton": "Complete setup",
|
||||
@@ -113,6 +113,7 @@
|
||||
"delete": {
|
||||
"title": "Delete user",
|
||||
"description": "Are you sure you want to delete {{name}} ({{email}})? This action cannot be undone.",
|
||||
"descriptionNoName": "Are you sure you want to delete {{email}}? This action cannot be undone.",
|
||||
"descriptionPending": "Are you sure you want to delete the pending invitation for {{email}}? This action cannot be undone.",
|
||||
"confirmButton": "Delete",
|
||||
"success": "{{name}} has been deleted."
|
||||
@@ -151,12 +152,13 @@
|
||||
},
|
||||
"profile": {
|
||||
"title": "My Profile",
|
||||
"name": "Full name",
|
||||
"name": "Display name",
|
||||
"email": "Email address",
|
||||
"role": "Role",
|
||||
"save": "Save changes",
|
||||
"saving": "Saving…",
|
||||
"saveSuccess": "Profile updated successfully",
|
||||
"securityTitle": "Change password",
|
||||
"changePassword": "Change password",
|
||||
"changePasswordDialog": {
|
||||
"title": "Change Password",
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
}
|
||||
},
|
||||
"setup": {
|
||||
"title": "Systeeminstallatie",
|
||||
"nameLabel": "Volledige naam",
|
||||
"title": "Eerste account aanmaken",
|
||||
"nameLabel": "Weergavenaam",
|
||||
"emailLabel": "E-mail",
|
||||
"passwordLabel": "Wachtwoord",
|
||||
"confirmPasswordLabel": "Wachtwoord bevestigen",
|
||||
@@ -53,7 +53,7 @@
|
||||
"inviteComplete": {
|
||||
"title": "Account voltooien",
|
||||
"emailLabel": "E-mail",
|
||||
"nameLabel": "Volledige naam",
|
||||
"nameLabel": "Weergavenaam",
|
||||
"passwordLabel": "Wachtwoord",
|
||||
"confirmPasswordLabel": "Wachtwoord bevestigen",
|
||||
"submitButton": "Setup voltooien",
|
||||
@@ -113,6 +113,7 @@
|
||||
"delete": {
|
||||
"title": "Gebruiker verwijderen",
|
||||
"description": "Weet je zeker dat je {{name}} ({{email}}) wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.",
|
||||
"descriptionNoName": "Weet je zeker dat je {{email}} wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.",
|
||||
"descriptionPending": "Weet je zeker dat je de openstaande uitnodiging voor {{email}} wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.",
|
||||
"confirmButton": "Verwijderen",
|
||||
"success": "{{name}} is verwijderd."
|
||||
@@ -151,12 +152,13 @@
|
||||
},
|
||||
"profile": {
|
||||
"title": "Mijn profiel",
|
||||
"name": "Volledige naam",
|
||||
"name": "Weergavenaam",
|
||||
"email": "E-mailadres",
|
||||
"role": "Rol",
|
||||
"save": "Wijzigingen opslaan",
|
||||
"saving": "Opslaan…",
|
||||
"saveSuccess": "Profiel succesvol bijgewerkt",
|
||||
"securityTitle": "Wachtwoord wijzigen",
|
||||
"changePassword": "Wachtwoord wijzigen",
|
||||
"changePasswordDialog": {
|
||||
"title": "Wachtwoord wijzigen",
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getBrand, themeLogo } from '@/lib/brand';
|
||||
|
||||
describe('themeLogo', () => {
|
||||
it('points at the emitted logo files under the app base path', () => {
|
||||
expect(themeLogo(true, '/admin/')).toEqual({
|
||||
onLight: '/admin/brand-logo-on-light.png',
|
||||
onDark: '/admin/brand-logo-on-dark.png',
|
||||
});
|
||||
});
|
||||
|
||||
it('tolerates a base without trailing slash and the dev root', () => {
|
||||
expect(themeLogo(true, '/admin')?.onLight).toBe('/admin/brand-logo-on-light.png');
|
||||
expect(themeLogo(true, '/')?.onDark).toBe('/brand-logo-on-dark.png');
|
||||
});
|
||||
|
||||
it('has no logo when the theme ships none', () => {
|
||||
expect(themeLogo(false)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBrand', () => {
|
||||
it('has no logo without a theme (the default admin is unchanged)', () => {
|
||||
expect(getBrand().logo).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* The site's brand as the admin shows it: one place, so where it comes from can change later
|
||||
* without touching the components that draw it.
|
||||
*
|
||||
* Today the logo is a build-time theme asset (themes/<VITE_THEME>/logo-on-*.png, emitted by
|
||||
* vite.config.ts). When brand settings become editable (site settings), only getBrand() changes:
|
||||
* it would return the stored logo URLs instead, and BrandLogo keeps working as is.
|
||||
*/
|
||||
export interface BrandLogo {
|
||||
/** For light backgrounds (dark ink). */
|
||||
onLight: string;
|
||||
/** For dark backgrounds (light ink). */
|
||||
onDark: string;
|
||||
}
|
||||
|
||||
export interface Brand {
|
||||
/** Absent when the site has no logo: callers fall back to the application name. */
|
||||
logo: BrandLogo | null;
|
||||
}
|
||||
|
||||
declare const __THEME_HAS_LOGO__: boolean | undefined;
|
||||
|
||||
export function themeLogo(hasLogo: boolean, base: string = import.meta.env.BASE_URL): BrandLogo | null {
|
||||
if (!hasLogo) return null;
|
||||
const prefix = base.endsWith('/') ? base : `${base}/`;
|
||||
return { onLight: `${prefix}brand-logo-on-light.png`, onDark: `${prefix}brand-logo-on-dark.png` };
|
||||
}
|
||||
|
||||
export function getBrand(): Brand {
|
||||
// Defined by vite.config.ts; absent where that config does not run.
|
||||
const hasLogo = typeof __THEME_HAS_LOGO__ !== 'undefined' && __THEME_HAS_LOGO__;
|
||||
return { logo: themeLogo(hasLogo) };
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@@ -10,6 +10,7 @@ describe('resolveTheme', () => {
|
||||
|
||||
expect(path.basename(theme.css)).toBe('none.css');
|
||||
expect(theme.favicon).toBeNull();
|
||||
expect(theme.logo).toBeNull();
|
||||
expect(fs.readFileSync(theme.css, 'utf-8')).not.toMatch(/--[a-z-]+\s*:/);
|
||||
});
|
||||
|
||||
@@ -21,6 +22,25 @@ describe('resolveTheme', () => {
|
||||
expect(theme.favicon !== null && fs.existsSync(theme.favicon)).toBe(true);
|
||||
});
|
||||
|
||||
it('ships the asf brand logo for both colour modes', () => {
|
||||
const { logo } = resolveTheme('asf');
|
||||
|
||||
expect(logo).not.toBeNull();
|
||||
expect(fs.existsSync(logo!.onLight) && fs.existsSync(logo!.onDark)).toBe(true);
|
||||
});
|
||||
|
||||
it('treats a theme with only one logo variant as having no logo', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'themes-'));
|
||||
try {
|
||||
fs.mkdirSync(path.join(dir, 'half'));
|
||||
fs.writeFileSync(path.join(dir, 'half', 'theme.css'), '');
|
||||
fs.writeFileSync(path.join(dir, 'half', 'logo-on-light.png'), '');
|
||||
expect(resolveTheme('half', dir).logo).toBeNull();
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('lists the available themes', () => {
|
||||
expect(availableThemes()).toContain('asf');
|
||||
});
|
||||
|
||||
@@ -6,6 +6,12 @@ export interface ResolvedTheme {
|
||||
css: string;
|
||||
/** Absolute path of the theme favicon, or null when there is no theme or it ships none. */
|
||||
favicon: string | null;
|
||||
/**
|
||||
* Brand logo files: one for light backgrounds (dark ink) and one for dark backgrounds (light
|
||||
* ink), or null when the theme ships none. Both or neither: a logo that is invisible in one
|
||||
* colour mode is worse than none.
|
||||
*/
|
||||
logo: { onLight: string; onDark: string } | null;
|
||||
}
|
||||
|
||||
const THEMES_DIR = import.meta.dirname;
|
||||
@@ -27,7 +33,7 @@ export function availableThemes(dir: string = THEMES_DIR): string[] {
|
||||
export function resolveTheme(name: string | undefined, dir: string = THEMES_DIR): ResolvedTheme {
|
||||
const trimmed = (name ?? '').trim();
|
||||
if (trimmed === '') {
|
||||
return { css: path.join(dir, 'none.css'), favicon: null };
|
||||
return { css: path.join(dir, 'none.css'), favicon: null, logo: null };
|
||||
}
|
||||
|
||||
// The name becomes a path segment: only known theme folders are accepted.
|
||||
@@ -39,8 +45,11 @@ export function resolveTheme(name: string | undefined, dir: string = THEMES_DIR)
|
||||
}
|
||||
|
||||
const favicon = path.join(dir, trimmed, 'favicon.png');
|
||||
const onLight = path.join(dir, trimmed, 'logo-on-light.png');
|
||||
const onDark = path.join(dir, trimmed, 'logo-on-dark.png');
|
||||
return {
|
||||
css: path.join(dir, trimmed, 'theme.css'),
|
||||
favicon: fs.existsSync(favicon) ? favicon : null,
|
||||
logo: fs.existsSync(onLight) && fs.existsSync(onDark) ? { onLight, onDark } : null,
|
||||
};
|
||||
}
|
||||
|
||||
+18
-2
@@ -16,8 +16,13 @@ function themeFor(mode: string) {
|
||||
* Per-site favicon (VITE_THEME): the page links the theme favicon instead of the default one.
|
||||
* Build emits it as an asset; the dev server serves it from the theme folder.
|
||||
*/
|
||||
function themeFavicon(faviconPath: string | null): Plugin {
|
||||
function themeFavicon(faviconPath: string | null, logo: { onLight: string; onDark: string } | null): Plugin {
|
||||
const publicName = 'favicon-theme.png';
|
||||
// Brand logo files, served/emitted next to the favicon (see src/lib/brand.ts for the names' consumer).
|
||||
const logoFiles: Record<string, string> = logo === null ? {} : {
|
||||
'brand-logo-on-light.png': logo.onLight,
|
||||
'brand-logo-on-dark.png': logo.onDark,
|
||||
};
|
||||
return {
|
||||
name: 'cms-theme-favicon',
|
||||
// 'post': Vite has already prefixed the base path (/admin/) by then, so match any prefix.
|
||||
@@ -29,6 +34,12 @@ function themeFavicon(faviconPath: string | null): Plugin {
|
||||
},
|
||||
},
|
||||
configureServer(server) {
|
||||
for (const [name, file] of Object.entries(logoFiles)) {
|
||||
server.middlewares.use(`/${name}`, (_req, res) => {
|
||||
res.setHeader('Content-Type', 'image/png');
|
||||
res.end(fs.readFileSync(file));
|
||||
});
|
||||
}
|
||||
if (faviconPath === null) return;
|
||||
server.middlewares.use(`/${publicName}`, (_req, res) => {
|
||||
res.setHeader('Content-Type', 'image/png');
|
||||
@@ -36,6 +47,9 @@ function themeFavicon(faviconPath: string | null): Plugin {
|
||||
});
|
||||
},
|
||||
generateBundle() {
|
||||
for (const [name, file] of Object.entries(logoFiles)) {
|
||||
this.emitFile({ type: 'asset', fileName: name, source: fs.readFileSync(file) });
|
||||
}
|
||||
if (faviconPath === null) return;
|
||||
this.emitFile({ type: 'asset', fileName: publicName, source: fs.readFileSync(faviconPath) });
|
||||
},
|
||||
@@ -46,10 +60,12 @@ function themeFavicon(faviconPath: string | null): Plugin {
|
||||
export default defineConfig(({ command, mode }) => ({
|
||||
// Production builds are deployed under /admin (see Program.cs); the dev server keeps serving from '/'.
|
||||
base: command === 'build' ? '/admin/' : '/',
|
||||
plugins: [react(), tailwindcss(), themeFavicon(themeFor(mode).favicon)],
|
||||
plugins: [react(), tailwindcss(), themeFavicon(themeFor(mode).favicon, themeFor(mode).logo)],
|
||||
define: {
|
||||
// Injected at build time, used as the Sentry `release` tag (see src/lib/sentry.ts).
|
||||
__APP_VERSION__: JSON.stringify(version),
|
||||
// Whether the selected theme ships a brand logo (consumed by src/lib/brand.ts).
|
||||
__THEME_HAS_LOGO__: JSON.stringify(themeFor(mode).logo !== null),
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
|
||||
Reference in New Issue
Block a user