From a28c59b82e26b8257480bee54efb27c78fb60f6d Mon Sep 17 00:00:00 2001 From: Rohit Date: Thu, 30 Jan 2025 23:25:13 +0530 Subject: [PATCH] feat: add global info for robot state --- src/context/globalInfo.tsx | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/context/globalInfo.tsx b/src/context/globalInfo.tsx index 28d65b34..3a9203b1 100644 --- a/src/context/globalInfo.tsx +++ b/src/context/globalInfo.tsx @@ -1,6 +1,44 @@ import React, { createContext, useContext, useState } from "react"; import { AlertSnackbarProps } from "../components/ui/AlertSnackbar"; +import { WhereWhatPair } from "maxun-core"; +interface RobotMeta { + name: string; + id: string; + createdAt: string; + pairs: number; + updatedAt: string; + params: any[]; +} + +interface RobotWorkflow { + workflow: WhereWhatPair[]; +} + +interface ScheduleConfig { + runEvery: number; + runEveryUnit: 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS'; + startFrom: 'SUNDAY' | 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY'; + atTimeStart?: string; + atTimeEnd?: string; + timezone: string; + lastRunAt?: Date; + nextRunAt?: Date; + cronExpression?: string; +} + +export interface RobotSettings { + id: string; + userId?: number; + recording_meta: RobotMeta; + recording: RobotWorkflow; + google_sheet_email?: string | null; + google_sheet_name?: string | null; + google_sheet_id?: string | null; + google_access_token?: string | null; + google_refresh_token?: string | null; + schedule?: ScheduleConfig | null; +} interface GlobalInfo { browserId: string | null; @@ -12,6 +50,8 @@ interface GlobalInfo { closeNotify: () => void; isLogin: boolean; setIsLogin: (isLogin: boolean) => void; + robot: RobotSettings | null; + setRobot: (robot: RobotSettings | null | ((prev: RobotSettings | null) => RobotSettings | null)) => void; recordings: string[]; setRecordings: (recordings: string[]) => void; rerenderRuns: boolean; @@ -50,6 +90,7 @@ class GlobalInfoStore implements Partial { isOpen: false, }; recordingId = null; + robot = null; recordings: string[] = []; rerenderRuns = false; recordingName = ''; @@ -83,6 +124,7 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => { const [recordingUrl, setRecordingUrl] = useState(globalInfoStore.recordingUrl); const [currentWorkflowActionsState, setCurrentWorkflowActionsState] = useState(globalInfoStore.currentWorkflowActionsState); const [shouldResetInterpretationLog, setShouldResetInterpretationLog] = useState(globalInfoStore.shouldResetInterpretationLog); + const [robot, setRobot] = useState(null); const notify = (severity: 'error' | 'warning' | 'info' | 'success', message: string) => { setNotification({ severity, message, isOpen: true }); @@ -117,6 +159,8 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => { notification, notify, closeNotify, + robot, + setRobot, recordings, setRecordings, rerenderRuns,