Skip to content
Merged
10 changes: 10 additions & 0 deletions src/components/robot/RecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ export const RecordingsTable = ({
setRecordingUrl,
isLogin,
setIsLogin,
rerenderRobots,
setRerenderRobots,
recordingName,
setRecordingName,
recordingId,
Expand Down Expand Up @@ -265,6 +267,14 @@ export const RecordingsTable = ({
}
}, [fetchRecordings]);

useEffect(() => {
if (rerenderRobots) {
fetchRecordings().then(() => {
setRerenderRobots(false);
});
}
}, [rerenderRobots, fetchRecordings, setRerenderRobots]);

function useDebounce<T>(value: T, delay: number): T {
const [debouncedValue, setDebouncedValue] = React.useState<T>(value);

Expand Down
10 changes: 4 additions & 6 deletions src/components/robot/RobotDuplicate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ interface RobotSettingsProps {

export const RobotDuplicationModal = ({ isOpen, handleStart, handleClose, initialSettings }: RobotSettingsProps) => {
const { t } = useTranslation();
const [robot, setRobot] = useState<RobotSettings | null>(null);
const [targetUrl, setTargetUrl] = useState<string | undefined>('');
const { recordingId, notify } = useGlobalInfoStore();
const [robot, setRobot] = useState<RobotSettings | null>(null);
const { recordingId, notify, setRerenderRobots } = useGlobalInfoStore();

useEffect(() => {
if (isOpen) {
Expand Down Expand Up @@ -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'));
}
Expand Down
11 changes: 5 additions & 6 deletions src/components/robot/RobotEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,9 +76,9 @@ interface GroupedCredentials {

export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettings }: RobotSettingsProps) => {
const { t } = useTranslation();
const [robot, setRobot] = useState<RobotSettings | null>(null);
const [credentials, setCredentials] = useState<Credentials>({});
const { recordingId, notify } = useGlobalInfoStore();
const { recordingId, notify, setRerenderRobots } = useGlobalInfoStore();
const [robot, setRobot] = useState<RobotSettings | null>(null);
const [credentialGroups, setCredentialGroups] = useState<GroupedCredentials>({
passwords: [],
emails: [],
Expand Down Expand Up @@ -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'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/robot/RobotSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ interface RobotSettingsProps {

export const RobotSettingsModal = ({ isOpen, handleStart, handleClose, initialSettings }: RobotSettingsProps) => {
const { t } = useTranslation();
const [robot, setRobot] = useState<RobotSettings | null>(null);
const [userEmail, setUserEmail] = useState<string | null>(null);
const [robot, setRobot] = useState<RobotSettings | null>(null);
const { recordingId, notify } = useGlobalInfoStore();

useEffect(() => {
Expand Down
44 changes: 44 additions & 0 deletions src/context/globalInfo.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -52,6 +92,7 @@ class GlobalInfoStore implements Partial<GlobalInfo> {
recordingId = null;
recordings: string[] = [];
rerenderRuns = false;
rerenderRobots = false;
recordingName = '';
initialUrl = 'https://';
recordingUrl = 'https://';
Expand All @@ -75,6 +116,7 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => {
const [notification, setNotification] = useState<AlertSnackbarProps>(globalInfoStore.notification);
const [recordings, setRecordings] = useState<string[]>(globalInfoStore.recordings);
const [rerenderRuns, setRerenderRuns] = useState<boolean>(globalInfoStore.rerenderRuns);
const [rerenderRobots, setRerenderRobots] = useState<boolean>(globalInfoStore.rerenderRobots);
const [recordingLength, setRecordingLength] = useState<number>(globalInfoStore.recordingLength);
const [recordingId, setRecordingId] = useState<string | null>(globalInfoStore.recordingId);
const [recordingName, setRecordingName] = useState<string>(globalInfoStore.recordingName);
Expand Down Expand Up @@ -121,6 +163,8 @@ export const GlobalInfoProvider = ({ children }: { children: JSX.Element }) => {
setRecordings,
rerenderRuns,
setRerenderRuns,
rerenderRobots,
setRerenderRobots,
recordingLength,
setRecordingLength,
recordingId,
Expand Down