mirror of
https://github.com/umami-software/umami.git
synced 2026-02-14 09:35:36 +01:00
Removed SettingsContext. Added hostUrl prop.
This commit is contained in:
parent
fec81695e8
commit
1a70350936
6 changed files with 23 additions and 48 deletions
|
|
@ -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>`;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue