mirror of
https://github.com/freedbygrace/ActiveDirectoryManager.git
synced 2026-08-08 18:04:38 +00:00
9d39faf2cf
Replit-Commit-Author: Agent Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/3caa578d-3a2c-45ec-a6c0-75313ad18bfb.jpg
95 lines
2.1 KiB
TypeScript
95 lines
2.1 KiB
TypeScript
import { DashboardConfig } from "@/components/dashboard/dashboard-layout";
|
|
|
|
// Interface for snapshot branding options
|
|
export interface SnapshotBranding {
|
|
logoUrl: string;
|
|
companyName: string;
|
|
title: string;
|
|
description: string;
|
|
primaryColor: string;
|
|
secondaryColor: string;
|
|
showDate: boolean;
|
|
showFooter: boolean;
|
|
footerText: string;
|
|
expiresInDays: number;
|
|
}
|
|
|
|
// Interface for snapshot data
|
|
export interface SnapshotData {
|
|
dashboard: DashboardConfig;
|
|
dataSources: Array<{
|
|
id: string;
|
|
name: string;
|
|
data: any[];
|
|
fields: Array<{ name: string; type: string }>;
|
|
}>;
|
|
branding: SnapshotBranding;
|
|
createdAt: string;
|
|
expiresAt: string | null;
|
|
}
|
|
|
|
/**
|
|
* Generate a snapshot of the dashboard data for sharing
|
|
*/
|
|
export function generateSnapshot({
|
|
dashboard,
|
|
dataSources,
|
|
branding,
|
|
}: {
|
|
dashboard: DashboardConfig;
|
|
dataSources: Array<{
|
|
id: string;
|
|
name: string;
|
|
data: any[];
|
|
fields: Array<{ name: string; type: string }>;
|
|
}>;
|
|
branding: SnapshotBranding;
|
|
}): SnapshotData {
|
|
const createdAt = new Date().toISOString();
|
|
|
|
// Calculate expiry date if applicable
|
|
let expiresAt: string | null = null;
|
|
if (branding.expiresInDays > 0) {
|
|
const expiry = new Date();
|
|
expiry.setDate(expiry.getDate() + branding.expiresInDays);
|
|
expiresAt = expiry.toISOString();
|
|
}
|
|
|
|
const snapshotData: SnapshotData = {
|
|
dashboard,
|
|
dataSources,
|
|
branding,
|
|
createdAt,
|
|
expiresAt,
|
|
};
|
|
|
|
return snapshotData;
|
|
}
|
|
|
|
/**
|
|
* Checks if a snapshot has expired
|
|
*/
|
|
export function isSnapshotExpired(snapshot: SnapshotData): boolean {
|
|
if (!snapshot.expiresAt) {
|
|
return false; // No expiry date means it never expires
|
|
}
|
|
|
|
const expiryDate = new Date(snapshot.expiresAt);
|
|
const now = new Date();
|
|
|
|
return now > expiryDate;
|
|
}
|
|
|
|
/**
|
|
* Format a date for display in the snapshot
|
|
*/
|
|
export function formatSnapshotDate(dateString: string): string {
|
|
const date = new Date(dateString);
|
|
return date.toLocaleDateString('en-US', {
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric',
|
|
hour: '2-digit',
|
|
minute: '2-digit'
|
|
});
|
|
} |