Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Added additional logic for handling website transfers.
Mike Caoa3f73826738b
diff --git a/src/app/(main)/settings/websites/[websiteId]/WebsiteData.tsx b/src/app/(main)/settings/websites/[websiteId]/WebsiteData.tsxindex 410f17830..c43b29bfc 100644--- a/src/app/(main)/settings/websites/[websiteId]/WebsiteData.tsx+++ b/src/app/(main)/settings/websites/[websiteId]/WebsiteData.tsx@@ -1,53 +1,54 @@-import { Button, Modal, ModalTrigger, ActionForm, useToasts } from 'react-basics';+import { Button, Modal, ModalTrigger, ActionForm } from 'react-basics';import { useRouter } from 'next/navigation';-import { useMessages, useModified, useTeamUrl } from 'components/hooks';+import { useLogin, useMessages, useModified, useTeamUrl } from 'components/hooks';import WebsiteDeleteForm from './WebsiteDeleteForm';import WebsiteResetForm from './WebsiteResetForm';import WebsiteTransferForm from './WebsiteTransferForm';+import { ROLES } from 'lib/constants';export function WebsiteData({ websiteId, onSave }: { websiteId: string; onSave?: () => void }) {const { formatMessage, labels, messages } = useMessages();- const router = useRouter();- const { showToast } = useToasts();+ const { user } = useLogin();const { touch } = useModified();const { teamId, renderTeamUrl } = useTeamUrl();+ const router = useRouter();+ const hasTeams = user?.teams?.length > 0;+ const isTeamOwner =+ (!teamId && hasTeams) ||+ (hasTeams &&+ user?.teams+ ?.find(({ id }) => id === teamId)+ ?.teamUser.find(({ role, userId }) => role === ROLES.teamOwner && userId === user.id));- const handleTransfer = () => {+ const handleSave = () => {touch('websites');-+ onSave?.();router.push(renderTeamUrl(`/settings/websites`));};const handleReset = async () => {- showToast({ message: formatMessage(messages.saved), variant: 'success' });onSave?.();};- const handleDelete = async () => {- touch('websites');-- if (teamId) {- router.push(renderTeamUrl('/settings/websites'));- } else {- router.push('/settings/websites');- }- };-return (<>- <ActionForm- label={formatMessage(labels.transferWebsite)}- description={formatMessage(messages.transferWebsite)}- >- <ModalTrigger>- <Button variant="secondary">{formatMessage(labels.transfer)}</Button>- <Modal title={formatMessage(labels.transferWebsite)}>- {(close: () => void) => (- <WebsiteTransferForm websiteId={websiteId} onSave={handleTransfer} onClose={close} />- )}- </Modal>- </ModalTrigger>- </ActionForm>+ {process.env.cloudMode && (+ <ActionForm+ label={formatMessage(labels.transferWebsite)}+ description={formatMessage(messages.transferWebsite)}+ >+ <ModalTrigger disabled={!isTeamOwner}>+ <Button variant="secondary" disabled={!isTeamOwner}>+ {formatMessage(labels.transfer)}+ </Button>+ <Modal title={formatMessage(labels.transferWebsite)}>+ {(close: () => void) => (+ <WebsiteTransferForm websiteId={websiteId} onSave={handleSave} onClose={close} />+ )}+ </Modal>+ </ModalTrigger>+ </ActionForm>+ )}<ActionFormlabel={formatMessage(labels.resetWebsite)}description={formatMessage(messages.resetWebsiteWarning)}@@ -69,7 +70,7 @@ export function WebsiteData({ websiteId, onSave }: { websiteId: string; onSave?:<Button variant="danger">{formatMessage(labels.delete)}</Button><Modal title={formatMessage(labels.deleteWebsite)}>{(close: () => void) => (- <WebsiteDeleteForm websiteId={websiteId} onSave={handleDelete} onClose={close} />+ <WebsiteDeleteForm websiteId={websiteId} onSave={handleSave} onClose={close} />)}</Modal></ModalTrigger>diff --git a/src/app/(main)/settings/websites/[websiteId]/WebsiteSettings.tsx b/src/app/(main)/settings/websites/[websiteId]/WebsiteSettings.tsxindex 24bf3d025..af7723aee 100644--- a/src/app/(main)/settings/websites/[websiteId]/WebsiteSettings.tsx+++ b/src/app/(main)/settings/websites/[websiteId]/WebsiteSettings.tsx@@ -1,5 +1,5 @@import { useState, Key, useContext } from 'react';-import { Item, Tabs, Button, Text, Icon } from 'react-basics';+import { Item, Tabs, Button, Text, Icon, useToasts } from 'react-basics';import Link from 'next/link';import Icons from 'components/icons';import PageHeader from 'components/layout/PageHeader';@@ -12,8 +12,13 @@ import { WebsiteContext } from 'app/(main)/websites/[websiteId]/WebsiteProvider'export function WebsiteSettings({ websiteId, openExternal = false }) {const website = useContext(WebsiteContext);- const { formatMessage, labels } = useMessages();+ const { formatMessage, labels, messages } = useMessages();const [tab, setTab] = useState<Key>('details');+ const { showToast } = useToasts();++ const handleSave = () => {+ showToast({ message: formatMessage(messages.saved), variant: 'success' });+ };return (<>@@ -36,7 +41,7 @@ export function WebsiteSettings({ websiteId, openExternal = false }) {{tab === 'details' && <WebsiteEditForm websiteId={websiteId} />}{tab === 'tracking' && <TrackingCode websiteId={websiteId} />}{tab === 'share' && <ShareUrl websiteId={websiteId} />}- {tab === 'data' && <WebsiteData websiteId={websiteId} />}+ {tab === 'data' && <WebsiteData websiteId={websiteId} onSave={handleSave} />}</>);}diff --git a/src/components/messages.ts b/src/components/messages.tsindex f9d518edd..2710e99d1 100644--- a/src/components/messages.ts+++ b/src/components/messages.ts@@ -330,14 +330,14 @@ export const messages = defineMessages({},transferWebsite: {id: 'message.transfer-website',- defaultMessage: 'Transfer website ownership to another user or team.',+ defaultMessage: 'Transfer website ownership to your account or another team.',},transferTeamWebsiteToUser: {id: 'message.transfer-team-website-to-user',- defaultMessage: 'Do you want to transfer this website to your account?',+ defaultMessage: 'Transfer this website to your account?',},transferUserWebsiteToTeam: {id: 'message.transfer-user-website-to-team',- defaultMessage: 'Which team do you want to transfer this website to?',+ defaultMessage: 'Select the team to transfer this website to.',},});diff --git a/src/lib/auth.ts b/src/lib/auth.tsindex ee3defeaf..92ec23bb7 100644--- a/src/lib/auth.ts+++ b/src/lib/auth.ts@@ -102,10 +102,6 @@ export async function canUpdateWebsite({ user }: Auth, websiteId: string) {}export async function canTransferWebsiteToUser({ user }: Auth, websiteId: string, userId: string) {- if (user.isAdmin) {- return true;- }-const website = await loadWebsite(websiteId);if (website.teamId && user.id === userId) {@@ -118,10 +114,6 @@ export async function canTransferWebsiteToUser({ user }: Auth, websiteId: string}export async function canTransferWebsiteToTeam({ user }: Auth, websiteId: string, teamId: string) {- if (user.isAdmin) {- return true;- }-const website = await loadWebsite(websiteId);if (website.userId === user.id) {