Add board share management UI
This commit is contained in:
1 parent
b429e7b24d
commit
c4226bc63d
30 files changed
+565
-56
No files matched your search
@@ -22,7 +22,7 @@ export interface BoardContextValue {
|
||||
export const BoardContext = createContext<BoardContextValue>(null);
|
||||
|
||||
const createDefaultBoard = (): Partial<Board> => ({
|
||||
type: BOARD_TYPES.open,
|
||||
type: BOARD_TYPES.mixed,
|
||||
name: '',
|
||||
description: '',
|
||||
parameters: {
|
||||
@@ -93,7 +93,7 @@ export function BoardProvider({
|
||||
}
|
||||
return post('/boards', {
|
||||
...boardData,
|
||||
type: boardData.type || BOARD_TYPES.open,
|
||||
type: boardData.type || BOARD_TYPES.mixed,
|
||||
slug: '',
|
||||
teamId,
|
||||
});
|
||||
|
||||
@@ -125,7 +125,7 @@ export function BoardEditForm() {
|
||||
>
|
||||
<Box width="100%" maxWidth="360px">
|
||||
<Select value={boardType} onChange={handleTypeChange} width="100%">
|
||||
<ListItem id={BOARD_TYPES.open}>{t(labels.open)}</ListItem>
|
||||
<ListItem id={BOARD_TYPES.mixed}>{t(labels.open)}</ListItem>
|
||||
<ListItem id={BOARD_TYPES.website}>{t(labels.website)}</ListItem>
|
||||
<ListItem id={BOARD_TYPES.pixel}>{t(labels.pixel)}</ListItem>
|
||||
<ListItem id={BOARD_TYPES.link}>{t(labels.link)}</ListItem>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Share } from '@/components/icons';
|
||||
import { useMessages } from '@/components/hooks';
|
||||
import { DialogButton } from '@/components/input/DialogButton';
|
||||
import { BoardShareDialog } from './BoardShareDialog';
|
||||
|
||||
export function BoardShareButton({ boardId }: { boardId: string }) {
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<DialogButton
|
||||
icon={<Share />}
|
||||
label={t(labels.share)}
|
||||
title={null}
|
||||
width="900px"
|
||||
>
|
||||
<BoardShareDialog boardId={boardId} />
|
||||
</DialogButton>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Button, Column, Form, FormField, FormSubmitButton, Row, TextField } from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { useApi, useMessages, useModified } from '@/components/hooks';
|
||||
|
||||
export function BoardShareCreateForm({
|
||||
boardId,
|
||||
onSave,
|
||||
onCancel,
|
||||
}: {
|
||||
boardId: string;
|
||||
onSave?: () => void;
|
||||
onCancel?: () => void;
|
||||
}) {
|
||||
const { post } = useApi();
|
||||
const { touch } = useModified();
|
||||
const { t, labels, getErrorMessage } = useMessages();
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const [error, setError] = useState<unknown>(null);
|
||||
|
||||
const handleSubmit = async (data: { name: string }) => {
|
||||
setIsPending(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await post(`/boards/${boardId}/shares`, {
|
||||
name: data.name,
|
||||
});
|
||||
|
||||
touch('shares');
|
||||
onSave?.();
|
||||
} catch (e) {
|
||||
setError(e);
|
||||
} finally {
|
||||
setIsPending(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Form onSubmit={handleSubmit} error={getErrorMessage(error)} defaultValues={{ name: '' }}>
|
||||
<Column gap="4">
|
||||
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
|
||||
<TextField autoComplete="off" autoFocus />
|
||||
</FormField>
|
||||
<Row justifyContent="flex-end" gap="3">
|
||||
{onCancel && (
|
||||
<Button isDisabled={isPending} onPress={onCancel}>
|
||||
{t(labels.cancel)}
|
||||
</Button>
|
||||
)}
|
||||
<FormSubmitButton variant="primary" isDisabled={isPending}>
|
||||
{t(labels.add)}
|
||||
</FormSubmitButton>
|
||||
</Row>
|
||||
</Column>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { Button, Column, Heading, Row, Text } from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { Plus } from '@/components/icons';
|
||||
import { LoadingPanel } from '@/components/common/LoadingPanel';
|
||||
import { IconLabel } from '@/components/common/IconLabel';
|
||||
import { useBoardSharesQuery, useMessages } from '@/components/hooks';
|
||||
import { BoardShareCreateForm } from './BoardShareCreateForm';
|
||||
import { BoardSharesTable } from './BoardSharesTable';
|
||||
|
||||
export function BoardShareDialog({ boardId }: { boardId: string }) {
|
||||
const { data, error, isLoading } = useBoardSharesQuery({ boardId });
|
||||
const shares = data?.data || [];
|
||||
const hasShares = shares.length > 0;
|
||||
|
||||
return (
|
||||
<LoadingPanel data={data} isLoading={isLoading} error={error}>
|
||||
<BoardShareDialogContent boardId={boardId} hasShares={hasShares} shares={shares} />
|
||||
</LoadingPanel>
|
||||
);
|
||||
}
|
||||
|
||||
function BoardShareDialogContent({
|
||||
boardId,
|
||||
hasShares,
|
||||
shares,
|
||||
}: {
|
||||
boardId: string;
|
||||
hasShares: boolean;
|
||||
shares: any[];
|
||||
}) {
|
||||
const { t, labels, messages } = useMessages();
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const showCreateForm = !hasShares || isCreating;
|
||||
|
||||
return (
|
||||
<Column gap="4">
|
||||
<Row justifyContent="space-between" alignItems="center">
|
||||
<Heading>{t(labels.share)}</Heading>
|
||||
{hasShares && !isCreating && (
|
||||
<Button variant="primary" onPress={() => setIsCreating(true)}>
|
||||
<IconLabel icon={<Plus size={16} />} label={t(labels.add)} />
|
||||
</Button>
|
||||
)}
|
||||
</Row>
|
||||
{showCreateForm && (
|
||||
<BoardShareCreateForm
|
||||
boardId={boardId}
|
||||
onSave={() => setIsCreating(false)}
|
||||
onCancel={hasShares ? () => setIsCreating(false) : undefined}
|
||||
/>
|
||||
)}
|
||||
{hasShares ? (
|
||||
<>
|
||||
<Text>{t(messages.shareUrl)}</Text>
|
||||
<BoardSharesTable data={shares} />
|
||||
</>
|
||||
) : (
|
||||
!showCreateForm && <Text color="muted">{t(messages.noDataAvailable)}</Text>
|
||||
)}
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { DataColumn, DataTable, type DataTableProps, Row } from '@umami/react-zen';
|
||||
import { CopyButton } from '@/components/common/CopyButton';
|
||||
import { DateDistance } from '@/components/common/DateDistance';
|
||||
import { ExternalLink } from '@/components/common/ExternalLink';
|
||||
import { useConfig, useMessages, useMobile } from '@/components/hooks';
|
||||
import { ShareDeleteButton } from '@/app/(main)/websites/[websiteId]/settings/ShareDeleteButton';
|
||||
|
||||
export function BoardSharesTable(props: DataTableProps) {
|
||||
const { t, labels } = useMessages();
|
||||
const { cloudMode } = useConfig();
|
||||
const { isMobile } = useMobile();
|
||||
|
||||
const getUrl = (slug: string) => {
|
||||
if (cloudMode) {
|
||||
return `${process.env.cloudUrl}/share/${slug}`;
|
||||
}
|
||||
|
||||
return `${window?.location.origin}${process.env.basePath || ''}/share/${slug}`;
|
||||
};
|
||||
|
||||
return (
|
||||
<DataTable {...props} displayMode={isMobile ? 'cards' : 'table'}>
|
||||
<DataColumn id="name" label={t(labels.name)}>
|
||||
{({ name }: any) => name}
|
||||
</DataColumn>
|
||||
<DataColumn id="slug" label={t(labels.shareUrl)} width="2fr">
|
||||
{({ slug }: any) => {
|
||||
const url = getUrl(slug);
|
||||
|
||||
return (
|
||||
<Row alignItems="center" gap="1" overflow="hidden">
|
||||
<ExternalLink href={url} prefetch={false}>
|
||||
{isMobile ? slug : url}
|
||||
</ExternalLink>
|
||||
<CopyButton value={url} label="Copy URL" />
|
||||
</Row>
|
||||
);
|
||||
}}
|
||||
</DataColumn>
|
||||
<DataColumn id="created" label={t(labels.created)}>
|
||||
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}
|
||||
</DataColumn>
|
||||
<DataColumn id="action" align="end" width="60px">
|
||||
{({ id, slug }: any) => (
|
||||
<Row>
|
||||
<ShareDeleteButton shareId={id} slug={slug} />
|
||||
</Row>
|
||||
)}
|
||||
</DataColumn>
|
||||
</DataTable>
|
||||
);
|
||||
}
|
||||
@@ -2,14 +2,14 @@ import { Column } from '@umami/react-zen';
|
||||
import { useBoard } from '@/components/hooks';
|
||||
import { BoardViewRow } from './BoardViewRow';
|
||||
|
||||
export function BoardViewBody() {
|
||||
export function BoardViewBody({ showEntityBadges = true }: { showEntityBadges?: boolean }) {
|
||||
const { board } = useBoard();
|
||||
const rows = board?.parameters?.rows ?? [];
|
||||
|
||||
return (
|
||||
<Column gap="3">
|
||||
{rows.map(row => (
|
||||
<BoardViewRow key={row.id} columns={row.columns} />
|
||||
<BoardViewRow key={row.id} columns={row.columns} showEntityBadges={showEntityBadges} />
|
||||
))}
|
||||
</Column>
|
||||
);
|
||||
|
||||
@@ -8,12 +8,18 @@ import { getComponentDefinition } from '../boardComponentRegistry';
|
||||
import { useBoardEntityBadgeProps } from '../useBoardEntityBadgeProps';
|
||||
import { BoardComponentRenderer } from './BoardComponentRenderer';
|
||||
|
||||
export function BoardViewColumn({ component }: { component?: BoardComponentConfig }) {
|
||||
export function BoardViewColumn({
|
||||
component,
|
||||
showEntityBadge = true,
|
||||
}: {
|
||||
component?: BoardComponentConfig;
|
||||
showEntityBadge?: boolean;
|
||||
}) {
|
||||
const { board } = useBoard();
|
||||
const boardType = getBoardType(board);
|
||||
const definition = component ? getComponentDefinition(component.type) : undefined;
|
||||
const { entityType, entityId } = getResolvedComponentEntity(board, component);
|
||||
const entityBadge = useBoardEntityBadgeProps(entityType, entityId);
|
||||
const entityBadge = useBoardEntityBadgeProps(entityType, entityId, showEntityBadge);
|
||||
|
||||
if (!component || (!entityId && definition?.requiresWebsite !== false)) {
|
||||
return null;
|
||||
@@ -24,7 +30,7 @@ export function BoardViewColumn({ component }: { component?: BoardComponentConfi
|
||||
|
||||
return (
|
||||
<Panel title={title} description={description} height="100%" position="relative">
|
||||
{isOpenBoardType(boardType) && entityBadge && (
|
||||
{showEntityBadge && isOpenBoardType(boardType) && entityBadge && (
|
||||
<Box position="absolute" top="12px" right="12px" zIndex={100}>
|
||||
<BoardEntityBadge {...entityBadge} />
|
||||
</Box>
|
||||
|
||||
@@ -7,21 +7,33 @@ import { getBoardEntity } from '@/lib/boards';
|
||||
import { Edit } from '@/components/icons';
|
||||
import { BoardEntityBadge } from '../BoardEntityBadge';
|
||||
import { useBoardEntityBadgeProps } from '../useBoardEntityBadgeProps';
|
||||
import { BoardShareButton } from './BoardShareButton';
|
||||
|
||||
export function BoardViewHeader() {
|
||||
export function BoardViewHeader({
|
||||
showActions = true,
|
||||
showEntityBadge = true,
|
||||
}: {
|
||||
showActions?: boolean;
|
||||
showEntityBadge?: boolean;
|
||||
}) {
|
||||
const { board } = useBoard();
|
||||
const { renderUrl } = useNavigation();
|
||||
const { t, labels } = useMessages();
|
||||
const { entityType, entityId } = getBoardEntity(board);
|
||||
const entityBadge = useBoardEntityBadgeProps(entityType, entityId);
|
||||
const entityBadge = useBoardEntityBadgeProps(entityType, entityId, showEntityBadge);
|
||||
|
||||
return (
|
||||
<PageHeader title={board?.name} description={board?.description}>
|
||||
<Row alignItems="center" gap>
|
||||
{entityBadge && <BoardEntityBadge {...entityBadge} />}
|
||||
<LinkButton href={renderUrl(`/boards/${board?.id}/edit`, false)}>
|
||||
<IconLabel icon={<Edit />}>{t(labels.edit)}</IconLabel>
|
||||
</LinkButton>
|
||||
{showEntityBadge && entityBadge && <BoardEntityBadge {...entityBadge} />}
|
||||
{showActions && board?.id && (
|
||||
<>
|
||||
<BoardShareButton boardId={board.id} />
|
||||
<LinkButton href={renderUrl(`/boards/${board.id}/edit`, false)}>
|
||||
<IconLabel icon={<Edit />}>{t(labels.edit)}</IconLabel>
|
||||
</LinkButton>
|
||||
</>
|
||||
)}
|
||||
</Row>
|
||||
</PageHeader>
|
||||
);
|
||||
|
||||
@@ -6,14 +6,24 @@ import { BoardControls } from './BoardControls';
|
||||
import { BoardViewBody } from './BoardViewBody';
|
||||
import { BoardViewHeader } from './BoardViewHeader';
|
||||
|
||||
export function BoardViewPage({ boardId }: { boardId: string }) {
|
||||
export function BoardViewPage({
|
||||
boardId,
|
||||
showActions = true,
|
||||
showControls = true,
|
||||
showEntityBadges = true,
|
||||
}: {
|
||||
boardId: string;
|
||||
showActions?: boolean;
|
||||
showControls?: boolean;
|
||||
showEntityBadges?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<BoardProvider boardId={boardId}>
|
||||
<PageBody>
|
||||
<Column>
|
||||
<BoardViewHeader />
|
||||
<BoardControls />
|
||||
<BoardViewBody />
|
||||
<BoardViewHeader showActions={showActions} showEntityBadge={showEntityBadges} />
|
||||
{showControls && <BoardControls />}
|
||||
<BoardViewBody showEntityBadges={showEntityBadges} />
|
||||
</Column>
|
||||
</PageBody>
|
||||
</BoardProvider>
|
||||
|
||||
@@ -3,7 +3,13 @@ import type { BoardColumn } from '@/lib/types';
|
||||
import { BoardViewColumn } from './BoardViewColumn';
|
||||
import { MIN_COLUMN_WIDTH } from './boardConstants';
|
||||
|
||||
export function BoardViewRow({ columns }: { columns: BoardColumn[] }) {
|
||||
export function BoardViewRow({
|
||||
columns,
|
||||
showEntityBadges = true,
|
||||
}: {
|
||||
columns: BoardColumn[];
|
||||
showEntityBadges?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<Row gap="3" width="100%" overflowX="auto">
|
||||
{columns.map(column => (
|
||||
@@ -14,7 +20,7 @@ export function BoardViewRow({ columns }: { columns: BoardColumn[] }) {
|
||||
flexBasis="0%"
|
||||
minWidth={`${MIN_COLUMN_WIDTH}px`}
|
||||
>
|
||||
<BoardViewColumn component={column.component} />
|
||||
<BoardViewColumn component={column.component} showEntityBadge={showEntityBadges} />
|
||||
</Box>
|
||||
))}
|
||||
</Row>
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { useLinkQuery, usePixelQuery, useWebsiteQuery } from '@/components/hooks';
|
||||
import type { BoardEntityType } from '@/lib/boards';
|
||||
|
||||
export function useBoardEntityBadgeProps(entityType?: BoardEntityType, entityId?: string) {
|
||||
const { data: website } = useWebsiteQuery(entityType === 'website' ? entityId : undefined);
|
||||
const { data: pixel } = usePixelQuery(entityType === 'pixel' ? entityId : undefined);
|
||||
const { data: link } = useLinkQuery(entityType === 'link' ? entityId : undefined);
|
||||
export function useBoardEntityBadgeProps(
|
||||
entityType?: BoardEntityType,
|
||||
entityId?: string,
|
||||
enabled = true,
|
||||
) {
|
||||
const { data: website } = useWebsiteQuery(
|
||||
enabled && entityType === 'website' ? entityId : undefined,
|
||||
);
|
||||
const { data: pixel } = usePixelQuery(enabled && entityType === 'pixel' ? entityId : undefined);
|
||||
const { data: link } = useLinkQuery(enabled && entityType === 'link' ? entityId : undefined);
|
||||
|
||||
if (entityType === 'website' && website?.name) {
|
||||
return { type: entityType, name: website.name };
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DataColumn, DataTable, type DataTableProps, Row } from '@umami/react-zen';
|
||||
import { CopyButton } from '@/components/common/CopyButton';
|
||||
import { DateDistance } from '@/components/common/DateDistance';
|
||||
import { ExternalLink } from '@/components/common/ExternalLink';
|
||||
import { useConfig, useMessages, useMobile } from '@/components/hooks';
|
||||
@@ -26,9 +27,12 @@ export function SharesTable(props: DataTableProps) {
|
||||
{({ slug }: any) => {
|
||||
const url = getUrl(slug);
|
||||
return (
|
||||
<ExternalLink href={url} prefetch={false}>
|
||||
{isMobile ? slug : url}
|
||||
</ExternalLink>
|
||||
<Row alignItems="center" gap="1" overflow="hidden">
|
||||
<ExternalLink href={url} prefetch={false}>
|
||||
{isMobile ? slug : url}
|
||||
</ExternalLink>
|
||||
<CopyButton value={url} label="Copy URL" />
|
||||
</Row>
|
||||
);
|
||||
}}
|
||||
</DataColumn>
|
||||
|
||||
Reference in new issue
Block a user