fix: i18n for share page (#370)

This commit is contained in:
SkyHuang 2024-02-22 19:22:59 +08:00 committed by GitHub
parent 2991d861eb
commit d2d6e3c958
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 8 deletions

View File

@ -2,9 +2,9 @@ import type { I18nActiveNamespaces } from '@/lib/i18n';
export interface IShareConfig {
// Define namespaces in use in both the type and the config.
i18nNamespaces: I18nActiveNamespaces<'share' | 'sdk'>;
i18nNamespaces: I18nActiveNamespaces<'share' | 'common' | 'table' | 'sdk'>;
}
export const shareConfig: IShareConfig = {
i18nNamespaces: ['share', 'sdk'],
i18nNamespaces: ['share', 'common', 'table', 'sdk'],
};

View File

@ -4,19 +4,23 @@ import type { GetServerSideProps } from 'next';
import { ssrApi } from '@/backend/api/rest/table.ssr';
import type { IShareViewPageProps } from '@/features/app/blocks/share/view/ShareViewPage';
import { ShareViewPage } from '@/features/app/blocks/share/view/ShareViewPage';
import { shareConfig } from '@/features/i18n/share.config';
import { getTranslationsProps } from '@/lib/i18n';
export const getServerSideProps: GetServerSideProps<IShareViewPageProps> = async ({
res,
req,
query,
}) => {
export const getServerSideProps: GetServerSideProps<IShareViewPageProps> = async (context) => {
const { res, req, query } = context;
const { shareId } = query;
const { i18nNamespaces } = shareConfig;
try {
res.setHeader('Content-Security-Policy', "frame-ancestors 'self' *;");
ssrApi.axios.defaults.headers['cookie'] = req.headers.cookie || '';
const shareViewData = await ssrApi.getShareView(shareId as string);
return {
props: { shareViewData },
props: {
shareViewData,
...(await getTranslationsProps(context, i18nNamespaces)),
},
};
} catch (e) {
const error = e as IHttpError;