Files
parcer/src/components/molecules/RobotSettings.tsx

118 lines
3.9 KiB
TypeScript
Raw Normal View History

2024-10-24 03:37:57 +05:30
import React, { useState, useEffect } from 'react';
import { GenericModal } from "../atoms/GenericModal";
2024-10-24 03:51:26 +05:30
import { TextField, Typography, Box } from "@mui/material";
2024-10-24 03:37:57 +05:30
import { modalStyle } from "./AddWhereCondModal";
import { useGlobalInfoStore } from '../../context/globalInfo';
2024-10-24 03:51:26 +05:30
import { getStoredRecording } from '../../api/storage';
import { WhereWhatPair } from 'maxun-core';
2024-10-24 03:37:57 +05:30
interface RobotMeta {
name: string;
id: string;
createdAt: string;
pairs: number;
updatedAt: string;
params: any[];
}
interface RobotWorkflow {
workflow: WhereWhatPair[];
2024-10-24 03:38:11 +05:30
}
2024-10-24 03:37:57 +05:30
2024-10-24 03:38:11 +05:30
interface ScheduleConfig {
2024-10-24 03:37:57 +05:30
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;
2024-10-24 03:38:11 +05:30
}
2024-10-24 03:40:38 +05:30
export interface RobotSettings {
2024-10-24 03:38:11 +05:30
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;
2024-10-24 03:37:57 +05:30
}
interface RobotSettingsProps {
2024-10-24 03:38:11 +05:30
isOpen: boolean;
handleStart: (settings: RobotSettings) => void;
handleClose: () => void;
initialSettings?: RobotSettings | null;
2024-10-24 03:37:57 +05:30
}
export const RobotSettingsModal = ({ isOpen, handleStart, handleClose, initialSettings }: RobotSettingsProps) => {
const [robot, setRobot] = useState<RobotSettings | null>(null);
2024-10-24 03:50:46 +05:30
const { recordingId, notify } = useGlobalInfoStore();
2024-10-24 03:37:57 +05:30
useEffect(() => {
if (isOpen) {
getRobot();
}
}, [isOpen]);
const getRobot = async () => {
if (recordingId) {
const robot = await getStoredRecording(recordingId);
setRobot(robot);
} else {
2024-10-24 03:50:46 +05:30
notify('error', 'Could not find robot details. Please try again.');
2024-10-24 03:37:57 +05:30
}
}
2024-10-24 03:38:11 +05:30
return (
<GenericModal
isOpen={isOpen}
onClose={handleClose}
modalStyle={modalStyle}
>
<>
<Typography variant="h5" style={{ marginBottom: '20px' }}>Robot Settings</Typography>
<Box style={{ display: 'flex', flexDirection: 'column' }}>
{
robot && (
<>
<TextField
2024-10-24 03:38:59 +05:30
label="Robot Target URL"
2024-10-24 03:38:11 +05:30
value={robot.recording.workflow[0].where.url}
2024-10-24 03:47:23 +05:30
InputProps={{
readOnly: true,
2024-10-24 03:47:36 +05:30
}}
2024-10-24 03:38:11 +05:30
style={{ marginBottom: '20px' }}
/>
2024-10-24 03:40:38 +05:30
<TextField
label="Robot ID"
value={robot.recording_meta.id}
2024-10-24 03:47:23 +05:30
InputProps={{
readOnly: true,
2024-10-24 03:47:36 +05:30
}}
2024-10-24 03:40:38 +05:30
style={{ marginBottom: '20px' }}
/>
2024-10-24 03:44:27 +05:30
<TextField
label="Robot Created At"
value={robot.recording_meta.createdAt}
2024-10-24 03:47:23 +05:30
InputProps={{
readOnly: true,
2024-10-24 03:47:36 +05:30
}}
2024-10-24 03:44:27 +05:30
style={{ marginBottom: '20px' }}
/>
2024-10-24 03:38:11 +05:30
</>
)
}
</Box>
</>
</GenericModal>
);
2024-10-24 03:37:57 +05:30
};