diff --git a/src/components/robot/RecordingsTable.tsx b/src/components/robot/RecordingsTable.tsx index f0c0a4da..429c53c5 100644 --- a/src/components/robot/RecordingsTable.tsx +++ b/src/components/robot/RecordingsTable.tsx @@ -168,6 +168,8 @@ export const RecordingsTable = ({ setRecordingUrl, isLogin, setIsLogin, + rerenderRobots, + setRerenderRobots, recordingName, setRecordingName, recordingId, @@ -261,6 +263,14 @@ export const RecordingsTable = ({ } }, [fetchRecordings]); + useEffect(() => { + if (rerenderRobots) { + fetchRecordings().then(() => { + setRerenderRobots(false); + }); + } + }, [rerenderRobots, fetchRecordings, setRerenderRobots]); + function useDebounce(value: T, delay: number): T { const [debouncedValue, setDebouncedValue] = React.useState(value); diff --git a/src/components/robot/RobotDuplicate.tsx b/src/components/robot/RobotDuplicate.tsx index efde9b2a..bee1ef5b 100644 --- a/src/components/robot/RobotDuplicate.tsx +++ b/src/components/robot/RobotDuplicate.tsx @@ -55,9 +55,9 @@ interface RobotSettingsProps { export const RobotDuplicationModal = ({ isOpen, handleStart, handleClose, initialSettings }: RobotSettingsProps) => { const { t } = useTranslation(); - const [robot, setRobot] = useState(null); const [targetUrl, setTargetUrl] = useState(''); - const { recordingId, notify } = useGlobalInfoStore(); + const [robot, setRobot] = useState(null); + const { recordingId, notify, setRerenderRobots } = useGlobalInfoStore(); useEffect(() => { if (isOpen) { @@ -96,13 +96,11 @@ export const RobotDuplicationModal = ({ isOpen, handleStart, handleClose, initia const success = await duplicateRecording(robot.recording_meta.id, targetUrl); if (success) { + setRerenderRobots(true); + notify('success', t('robot_duplication.notifications.duplicate_success')); handleStart(robot); handleClose(); - - setTimeout(() => { - window.location.reload(); - }, 1000); } else { notify('error', t('robot_duplication.notifications.duplicate_error')); } diff --git a/src/components/robot/RobotEdit.tsx b/src/components/robot/RobotEdit.tsx index f1f79b77..25edaa3f 100644 --- a/src/components/robot/RobotEdit.tsx +++ b/src/components/robot/RobotEdit.tsx @@ -7,6 +7,7 @@ import { modalStyle } from "../recorder/AddWhereCondModal"; import { useGlobalInfoStore } from '../../context/globalInfo'; import { getStoredRecording, updateRecording } from '../../api/storage'; import { WhereWhatPair } from 'maxun-core'; +import { useNavigate } from 'react-router-dom'; interface RobotMeta { name: string; @@ -75,9 +76,9 @@ interface GroupedCredentials { export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettings }: RobotSettingsProps) => { const { t } = useTranslation(); - const [robot, setRobot] = useState(null); const [credentials, setCredentials] = useState({}); - const { recordingId, notify } = useGlobalInfoStore(); + const { recordingId, notify, setRerenderRobots } = useGlobalInfoStore(); + const [robot, setRobot] = useState(null); const [credentialGroups, setCredentialGroups] = useState({ passwords: [], emails: [], @@ -366,13 +367,11 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin const success = await updateRecording(robot.recording_meta.id, payload); if (success) { + setRerenderRobots(true); + notify('success', t('robot_edit.notifications.update_success')); handleStart(robot); handleClose(); - - setTimeout(() => { - window.location.reload(); - }, 1000); } else { notify('error', t('robot_edit.notifications.update_failed')); } diff --git a/src/components/robot/RobotSettings.tsx b/src/components/robot/RobotSettings.tsx index fdbf90e2..6ae59f89 100644 --- a/src/components/robot/RobotSettings.tsx +++ b/src/components/robot/RobotSettings.tsx @@ -54,8 +54,8 @@ interface RobotSettingsProps { export const RobotSettingsModal = ({ isOpen, handleStart, handleClose, initialSettings }: RobotSettingsProps) => { const { t } = useTranslation(); - const [robot, setRobot] = useState(null); const [userEmail, setUserEmail] = useState(null); + const [robot, setRobot] = useState(null); const { recordingId, notify } = useGlobalInfoStore(); useEffect(() => { diff --git a/src/context/globalInfo.tsx b/src/context/globalInfo.tsx index 28d65b34..eaa6ded7 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; @@ -16,6 +54,8 @@ interface GlobalInfo { setRecordings: (recordings: string[]) => void; rerenderRuns: boolean; setRerenderRuns: (rerenderRuns: boolean) => void; + rerenderRobots: boolean; + setRerenderRobots: (rerenderRuns: boolean) => void; recordingLength: number; setRecordingLength: (recordingLength: number) => void; recordingId: string | null; @@ -52,6 +92,7 @@ class GlobalInfoStore implements Partial { recordingId = null; recordings: string[] = []; rerenderRuns = false; + rerenderRobots = false; recordingName = ''; initialUrl = 'https://'; recordingUrl = 'https://'; @@ -75,6 +116,7 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => { const [notification, setNotification] = useState(globalInfoStore.notification); const [recordings, setRecordings] = useState(globalInfoStore.recordings); const [rerenderRuns, setRerenderRuns] = useState(globalInfoStore.rerenderRuns); + const [rerenderRobots, setRerenderRobots] = useState(globalInfoStore.rerenderRobots); const [recordingLength, setRecordingLength] = useState(globalInfoStore.recordingLength); const [recordingId, setRecordingId] = useState(globalInfoStore.recordingId); const [recordingName, setRecordingName] = useState(globalInfoStore.recordingName); @@ -121,6 +163,8 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => { setRecordings, rerenderRuns, setRerenderRuns, + rerenderRobots, + setRerenderRobots, recordingLength, setRecordingLength, recordingId,