Skip to content

Commit

Permalink
feat: custom logo
Browse files Browse the repository at this point in the history
  • Loading branch information
asabotovich committed Feb 26, 2024
1 parent cb2c38d commit cc93506
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 19 deletions.
7 changes: 7 additions & 0 deletions prisma/migrations/20240221092641_app_config/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- CreateTable
CREATE TABLE "AppConfig" (
"id" TEXT NOT NULL,
"logo" TEXT,

CONSTRAINT "AppConfig_pkey" PRIMARY KEY ("id")
);
5 changes: 5 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,8 @@ model Team {
externalTeamId String @unique
projects Project[] @relation("projects")
}

model AppConfig {
id String @id @default(cuid())
logo String?
}
1 change: 1 addition & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const userPassword = 'taskany';
},
},
}),
prisma.appConfig.create({}),
createSheep(),
createCronJob('goalPing', '0 0 0 1 * *'),
]);
Expand Down
5 changes: 4 additions & 1 deletion src/components/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { PageFooter } from '../PageFooter/PageFooter';
import { ModalContext } from '../ModalOnEvent';
import { useGoalPreview } from '../GoalPreview/GoalPreviewProvider';
import { OfflineBanner } from '../OfflineBanner/OfflineBanner';
import { Config } from '../../utils/db';

import s from './Page.module.css';

Expand All @@ -38,11 +39,12 @@ interface PageProps extends React.HTMLAttributes<HTMLDivElement> {
ssrTime: number;
title?: string;
children?: React.ReactNode;
config?: Config;
}

const mapThemeOnId = { light: 0, dark: 1 } as const;

export const Page: React.FC<PageProps> = ({ user, ssrTime, title = 'Untitled', children, ...attrs }) => {
export const Page: React.FC<PageProps> = ({ user, ssrTime, title = 'Untitled', children, config, ...attrs }) => {
const { setPreview } = useGoalPreview();
const { data: userSettings = user?.settings } = trpc.user.settings.useQuery();

Expand All @@ -62,6 +64,7 @@ export const Page: React.FC<PageProps> = ({ user, ssrTime, title = 'Untitled', c
return (
<pageContext.Provider value={{ user, theme, themeId: mapThemeOnId[theme], ssrTime }}>
<Head>
<link rel="icon" href={config?.logo || '/favicon.png'} />
<title>{title}</title>
<link rel="stylesheet" id="themeVariables" href={`/theme/${theme}.css`} />
</Head>
Expand Down
29 changes: 11 additions & 18 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { AppProps, NextWebVitalsMetric } from 'next/app';
import '../utils/wdyr';
import '@taskany/bricks/harmony/style.css';
import { PageLoadProgress } from '@taskany/bricks';
import Head from 'next/head';
import { SessionProvider } from 'next-auth/react';
import { ThemeProvider } from 'next-themes';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
Expand Down Expand Up @@ -35,23 +34,17 @@ const App = ({ Component, pageProps, router }: AppProps) => {
useWebTelemetryMonitoringInit();

return (
<>
<Head>
<link rel="icon" href="/favicon.png" />
</Head>

<SessionProvider session={pageProps.session} refetchOnWindowFocus={true}>
<ThemeProvider themes={defaultThemes}>
<ThemeSetter>
<GoalPreviewProvider>
<PageLoadProgress height={2} ref={pageLoadRef} />
<Component {...pageProps} />
<ReactQueryDevtools />
</GoalPreviewProvider>
</ThemeSetter>
</ThemeProvider>
</SessionProvider>
</>
<SessionProvider session={pageProps.session} refetchOnWindowFocus={true}>
<ThemeProvider themes={defaultThemes}>
<ThemeSetter>
<GoalPreviewProvider>
<PageLoadProgress height={2} ref={pageLoadRef} />
<Component {...pageProps} />
<ReactQueryDevtools />
</GoalPreviewProvider>
</ThemeSetter>
</ThemeProvider>
</SessionProvider>
);
};

Expand Down
10 changes: 10 additions & 0 deletions src/utils/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,13 @@ export const updateLinkedGoalsByProject = async (projectId: string, activityId:
}
}
};

export const fetchConfig = async () => {
try {
return await prisma.appConfig.findFirst();
} catch (e) {
return null;
}
};

export type Config = Awaited<ReturnType<typeof fetchConfig>>;
5 changes: 5 additions & 0 deletions src/utils/declareSsrProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { routes } from '../hooks/router';
import { trpcRouter } from '../../trpc/router';
import type { TrpcRouter } from '../../trpc/router';

import { Config, fetchConfig } from './db';
import { transformer } from './transformer';

export interface SSRProps<P = { [key: string]: string }> {
Expand All @@ -16,6 +17,7 @@ export interface SSRProps<P = { [key: string]: string }> {
query: Record<string, string | string[] | undefined>;
ssrTime: number;
ssrHelpers: DecoratedProcedureSSGRecord<TrpcRouter>;
config?: Config;
}

export interface ExternalPageProps<P = { [key: string]: string }> extends SSRProps<P> {
Expand All @@ -30,6 +32,7 @@ export function declareSsrProps<T = ExternalPageProps>(
return async ({ locale, req, params = {}, query }: GetServerSidePropsContext) => {
// FIXME: getServerSession. Problem with serialazing createdAt, updatedAt
const session = await getSession({ req });
const config = await fetchConfig();

if (options?.private && !session) {
return {
Expand Down Expand Up @@ -61,6 +64,7 @@ export function declareSsrProps<T = ExternalPageProps>(
query,
ssrTime,
ssrHelpers,
config,
})
: {};

Expand All @@ -78,6 +82,7 @@ export function declareSsrProps<T = ExternalPageProps>(
user: session ? session.user : null,
ssrTime,
trpcState: ssrHelpers.dehydrate(),
config,
},
};
};
Expand Down

0 comments on commit cc93506

Please sign in to comment.