mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Removed SettingsContext. Added hostUrl prop.
This commit is contained in:
parent
fec81695e8
commit
1a70350936
@ -1,6 +0,0 @@
|
||||
'use client';
|
||||
import { createContext } from 'react';
|
||||
|
||||
export const SettingsContext = createContext(null);
|
||||
|
||||
export default SettingsContext;
|
@ -1,7 +1,7 @@
|
||||
import { Button, Icon, Text, Modal, Icons, ModalTrigger, useToasts } from 'react-basics';
|
||||
import UserAddForm from './UserAddForm';
|
||||
import { useMessages } from 'components/hooks';
|
||||
import { setValue } from 'store/cache';
|
||||
import { touch } from 'store/cache';
|
||||
|
||||
export function UserAddButton({ onSave }: { onSave?: () => void }) {
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
@ -9,7 +9,7 @@ export function UserAddButton({ onSave }: { onSave?: () => void }) {
|
||||
|
||||
const handleSave = () => {
|
||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||
setValue('users', Date.now());
|
||||
touch('users');
|
||||
onSave?.();
|
||||
};
|
||||
|
||||
|
@ -10,16 +10,22 @@ import {
|
||||
LoadingButton,
|
||||
useToasts,
|
||||
} from 'react-basics';
|
||||
import { useContext, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { getRandomChars } from 'next-basics';
|
||||
import { useApi, useMessages } from 'components/hooks';
|
||||
import SettingsContext from 'app/(main)/settings/SettingsContext';
|
||||
|
||||
const generateId = () => getRandomChars(16);
|
||||
|
||||
export function ShareUrl({ website, onSave }: { website: Website; onSave?: () => void }) {
|
||||
export function ShareUrl({
|
||||
website,
|
||||
hostUrl,
|
||||
onSave,
|
||||
}: {
|
||||
website: Website;
|
||||
hostUrl?: string;
|
||||
onSave?: () => void;
|
||||
}) {
|
||||
const { domain, shareId } = website;
|
||||
const { hostUrl } = useContext(SettingsContext);
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
const [id, setId] = useState(shareId);
|
||||
const { showToast } = useToasts();
|
||||
@ -28,7 +34,7 @@ export function ShareUrl({ website, onSave }: { website: Website; onSave?: () =>
|
||||
mutationFn: (data: any) => post(`/websites/${website.id}`, data),
|
||||
});
|
||||
|
||||
const url = `${hostUrl || location.origin}${
|
||||
const url = `${hostUrl || process.env.hostUrl || window?.location.origin}${
|
||||
process.env.basePath
|
||||
}/share/${id}/${encodeURIComponent(domain)}`;
|
||||
|
||||
|
@ -1,19 +1,18 @@
|
||||
import { TextArea } from 'react-basics';
|
||||
import { useMessages, useConfig } from 'components/hooks';
|
||||
import { useContext } from 'react';
|
||||
import SettingsContext from '../../SettingsContext';
|
||||
|
||||
export function TrackingCode({ websiteId }: { websiteId: string }) {
|
||||
export function TrackingCode({ websiteId, hostUrl }: { websiteId: string; hostUrl?: string }) {
|
||||
const { formatMessage, messages } = useMessages();
|
||||
const config = useConfig();
|
||||
const { trackingCodeUrl } = useContext(SettingsContext);
|
||||
|
||||
const trackerScriptName =
|
||||
config?.trackerScriptName?.split(',')?.map(n => n.trim())?.[0] || 'script.js';
|
||||
config?.trackerScriptName?.split(',')?.map((n: string) => n.trim())?.[0] || 'script.js';
|
||||
|
||||
const url = trackerScriptName?.startsWith('http')
|
||||
? trackerScriptName
|
||||
: `${trackingCodeUrl}${process.env.basePath}/${trackerScriptName}`;
|
||||
: `${hostUrl || process.env.hostUrl || window?.location.origin}${
|
||||
process.env.basePath
|
||||
}/${trackerScriptName}`;
|
||||
|
||||
const code = `<script defer src="${url}" data-website-id="${websiteId}"></script>`;
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
'use client';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { IntlProvider } from 'react-intl';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { ReactBasicsProvider } from 'react-basics';
|
||||
import ErrorBoundary from 'components/common/ErrorBoundary';
|
||||
import SettingsContext from 'app/(main)/settings/SettingsContext';
|
||||
import { useLocale } from 'components/hooks';
|
||||
import 'chartjs-adapter-date-fns';
|
||||
|
||||
@ -26,34 +24,14 @@ function MessagesProvider({ children }) {
|
||||
);
|
||||
}
|
||||
|
||||
function SettingsProvider({ children }) {
|
||||
const [config, setConfig] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
const hostUrl = process.env.hostUrl || window?.location.origin;
|
||||
|
||||
setConfig({
|
||||
shareUrl: hostUrl,
|
||||
trackingCodeUrl: hostUrl,
|
||||
websitesUrl: '/websites',
|
||||
settingsPath: '/settings/websites',
|
||||
websitesPath: `/websites`,
|
||||
});
|
||||
}, []);
|
||||
|
||||
return <SettingsContext.Provider value={config}>{children}</SettingsContext.Provider>;
|
||||
}
|
||||
|
||||
export function Providers({ children }) {
|
||||
return (
|
||||
<MessagesProvider>
|
||||
<SettingsProvider>
|
||||
<QueryClientProvider client={client}>
|
||||
<ReactBasicsProvider>
|
||||
<ErrorBoundary>{children}</ErrorBoundary>
|
||||
</ReactBasicsProvider>
|
||||
</QueryClientProvider>
|
||||
</SettingsProvider>
|
||||
</MessagesProvider>
|
||||
);
|
||||
}
|
||||
|
@ -48,8 +48,6 @@ export * from 'app/(main)/settings/websites/WebsiteSettings';
|
||||
export * from 'app/(main)/settings/websites/WebsitesDataTable';
|
||||
export * from 'app/(main)/settings/websites/WebsitesTable';
|
||||
|
||||
export * from 'app/(main)/settings/SettingsContext';
|
||||
|
||||
export * from 'components/common/TypeConfirmationForm';
|
||||
export * from 'components/common/DataTable';
|
||||
export * from 'components/common/Empty';
|
||||
|
Loading…
Reference in New Issue
Block a user