Add board share management UI

This commit is contained in:
Mike Cao committed 2026-03-08 22:24:24 -07:00
1 parent b429e7b24d
commit c4226bc63d
30 files changed
+565 -56

No files matched your search

+46 -5
View File
@@ -2,7 +2,7 @@ import type { Board, BoardComponentConfig, BoardParameters } from './types';
export const BOARD_TYPES = {
dashboard: 'dashboard',
open: 'open',
mixed: 'mixed',
website: 'website',
pixel: 'pixel',
link: 'link',
@@ -32,7 +32,19 @@ export function getLegacyBoardType(parameters?: BoardParameters): BoardType {
return BOARD_TYPES.website;
}
return BOARD_TYPES.open;
return BOARD_TYPES.mixed;
}
export function normalizeBoardType(type?: string): BoardType | undefined {
if (type === 'open') {
return BOARD_TYPES.mixed;
}
if (type && boardTypes.has(type)) {
return type as BoardType;
}
return undefined;
}
export function getBoardType(
@@ -45,15 +57,17 @@ export function getBoardType(
return getLegacyBoardType(board?.parameters);
}
if (type && boardTypes.has(type)) {
return type as BoardType;
const normalizedType = normalizeBoardType(type);
if (normalizedType) {
return normalizedType;
}
return getLegacyBoardType(board?.parameters);
}
export function isOpenBoardType(type?: string) {
return type === BOARD_TYPES.open || type === BOARD_TYPES.dashboard;
return type === BOARD_TYPES.mixed || type === BOARD_TYPES.dashboard || type === 'open';
}
export function requiresBoardEntity(type?: string) {
@@ -142,6 +156,33 @@ export function getFirstBoardComponentEntity(
return {};
}
export function getBoardWebsiteIds(
board?: Pick<Board, 'type' | 'parameters'> | Partial<Board>,
): string[] {
const ids = new Set<string>();
const boardEntity = getBoardEntity(board);
if (boardEntity.entityType === BOARD_ENTITY_TYPES.website && boardEntity.entityId) {
ids.add(boardEntity.entityId);
}
if (board?.parameters?.websiteId) {
ids.add(board.parameters.websiteId);
}
for (const row of board?.parameters?.rows ?? []) {
for (const column of row.columns ?? []) {
const entity = getComponentEntity(column.component);
if (entity.entityType === BOARD_ENTITY_TYPES.website && entity.entityId) {
ids.add(entity.entityId);
}
}
}
return [...ids];
}
export function clearBoardEntity(parameters: BoardParameters = {}): BoardParameters {
const { websiteId, pixelId, linkId, ...rest } = parameters;
+10 -7
View File
@@ -1,12 +1,15 @@
import type { Link, Pixel, Website } from '@/generated/prisma/client';
import { getLink, getPixel, getWebsite } from '@/queries/prisma';
import type { Board, Link, Pixel, Website } from '@/generated/prisma/client';
import { getBoard, getLink, getPixel, getWebsite } from '@/queries/prisma';
export async function getEntity(entityId: string): Promise<Website | Link | Pixel | null> {
const website = await getWebsite(entityId);
const link = await getLink(entityId);
const pixel = await getPixel(entityId);
export async function getEntity(entityId: string): Promise<Website | Link | Pixel | Board | null> {
const [website, link, pixel, board] = await Promise.all([
getWebsite(entityId),
getLink(entityId),
getPixel(entityId),
getBoard(entityId),
]);
const entity = website || link || pixel;
const entity = website || link || pixel || board;
return entity;
}
+3 -1
View File
@@ -20,7 +20,9 @@ export interface Auth {
isAdmin: boolean;
};
shareToken?: {
websiteId: string;
websiteId?: string;
websiteIds?: string[];
boardId?: string;
};
}