feat(frontend): implement step 1 - entity task detail and scheduler UX

This commit is contained in:
2026-03-26 20:32:06 -03:00
parent 381c6cbfcd
commit 888fb9f665
11 changed files with 470 additions and 45 deletions

View File

@@ -0,0 +1,82 @@
const STORAGE_KEY = 'condado:entity-tasks'
export type EmailLookback = 'last_day' | 'last_week' | 'last_month'
export interface EntityTaskResponse {
id: string
entityId: string
name: string
prompt: string
scheduleCron: string
emailLookback: EmailLookback
createdAt: string
}
export interface EntityTaskCreateDto {
entityId: string
name: string
prompt: string
scheduleCron: string
emailLookback: EmailLookback
}
function readTasks(): EntityTaskResponse[] {
const raw = localStorage.getItem(STORAGE_KEY)
if (!raw) return []
try {
return JSON.parse(raw) as EntityTaskResponse[]
} catch {
return []
}
}
function writeTasks(tasks: EntityTaskResponse[]): void {
localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks))
}
export function getEmailLookbackLabel(value: EmailLookback): string {
if (value === 'last_day') return 'Last 24 hours'
if (value === 'last_month') return 'Last month'
return 'Last week'
}
/** Simulates a task preview generated from the configured prompt. */
export async function generateTaskPreview(data: EntityTaskCreateDto): Promise<string> {
return [
`SUBJECT: Internal Alignment Update - ${data.name}`,
'BODY:',
`Dear Team,`,
'',
`In strict accordance with our communication standards, this message was generated from the prompt: "${data.prompt}".`,
`Context window considered: ${getEmailLookbackLabel(data.emailLookback)}.`,
'Operational interpretation: please proceed casually, but with ceremonial seriousness.',
'',
'Regards,',
'Automated Task Preview',
].join('\n')
}
/** Returns all scheduled tasks currently configured in local storage. */
export async function getAllTasks(): Promise<EntityTaskResponse[]> {
return readTasks()
}
/** Returns scheduled tasks for a specific entity. */
export async function getTasksByEntity(entityId: string): Promise<EntityTaskResponse[]> {
return readTasks().filter((task) => task.entityId === entityId)
}
/** Creates a scheduled task in local storage. */
export async function createTask(data: EntityTaskCreateDto): Promise<EntityTaskResponse> {
const current = readTasks()
const task: EntityTaskResponse = {
...data,
id: crypto.randomUUID(),
createdAt: new Date().toISOString(),
}
current.push(task)
writeTasks(current)
return task
}