Removed SettingsContext. Added hostUrl prop.

This commit is contained in:
Mike Cao 2024-01-29 13:51:59 -08:00
parent fec81695e8
commit 1a70350936
6 changed files with 23 additions and 48 deletions

View file

@ -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)}`;