Files
parcer/src/components/robot/Recordings.tsx

158 lines
5.2 KiB
TypeScript
Raw Normal View History

2025-01-25 12:43:57 +05:30
import React, { useEffect, useState } from "react";
2025-01-09 20:01:43 +05:30
import { RecordingsTable } from "./RecordingsTable";
2024-06-24 22:41:54 +05:30
import { Grid } from "@mui/material";
2025-01-09 20:02:58 +05:30
import { RunSettings, RunSettingsModal } from "../run/RunSettings";
import {
ScheduleSettings,
ScheduleSettingsPage,
} from "./pages/ScheduleSettingsPage";
import { RobotIntegrationPage } from "./pages/RobotIntegrationPage";
import { RobotSettingsPage } from "./pages/RobotSettingsPage";
import { RobotEditPage } from "./pages/RobotEditPage";
import { RobotDuplicatePage } from "./pages/RobotDuplicatePage";
2025-01-10 11:22:49 +05:30
import { useNavigate, useLocation, useParams } from "react-router-dom";
2025-01-25 12:43:57 +05:30
import { useGlobalInfoStore } from "../../context/globalInfo";
2025-01-25 12:56:19 +05:30
import { useTranslation } from "react-i18next";
2024-06-24 22:41:54 +05:30
interface RecordingsProps {
handleEditRecording: (id: string, fileName: string) => void;
2024-06-24 22:41:54 +05:30
handleRunRecording: (settings: RunSettings) => void;
handleScheduleRecording: (settings: ScheduleSettings) => Promise<boolean>;
2024-10-09 22:31:11 +05:30
setRecordingInfo: (id: string, name: string) => void;
2024-06-24 22:41:54 +05:30
}
2025-01-10 11:22:49 +05:30
export const Recordings = ({
handleEditRecording,
handleRunRecording,
setRecordingInfo,
handleScheduleRecording,
}: RecordingsProps) => {
const navigate = useNavigate();
const location = useLocation();
2024-06-24 22:41:54 +05:30
const [params, setParams] = useState<string[]>([]);
2025-01-25 12:43:57 +05:30
const { notify } = useGlobalInfoStore();
2025-01-25 12:56:19 +05:30
const { t } = useTranslation();
2024-06-24 22:41:54 +05:30
const handleNavigate = (
path: string,
id: string,
name: string,
params: string[]
) => {
2025-01-10 11:22:49 +05:30
setParams(params);
setRecordingInfo(id, name);
navigate(path);
};
2024-11-17 14:06:26 +05:30
2024-06-24 22:41:54 +05:30
const handleClose = () => {
setParams([]);
2025-01-10 11:22:49 +05:30
setRecordingInfo("", "");
navigate("/robots"); // Navigate back to the main robots page
};
2024-09-10 12:09:53 +05:30
2025-01-25 12:43:57 +05:30
useEffect(() => {
// Helper function to get and clear a cookie
const getAndClearCookie = (name: string) => {
const value = document.cookie
.split("; ")
.find((row) => row.startsWith(`${name}=`))
?.split("=")[1];
2025-01-25 12:43:57 +05:30
if (value) {
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
}
2025-01-25 12:43:57 +05:30
return value;
};
const authStatus = getAndClearCookie("robot_auth_status");
const airtableAuthStatus = getAndClearCookie("airtable_auth_status");
const robotId = getAndClearCookie("robot_auth_robotId");
2025-01-25 12:43:57 +05:30
if (airtableAuthStatus === "success" && robotId) {
2025-02-26 23:52:58 +05:30
console.log("Airtable Auth Status:", airtableAuthStatus);
notify(
airtableAuthStatus,
t("recordingtable.notifications.auth_success")
);
2025-02-26 23:52:58 +05:30
handleNavigate(`/robots/${robotId}/integrate/airtable`, robotId, "", []);
} else if (authStatus === "success" && robotId) {
2025-02-26 23:52:58 +05:30
console.log("Google Auth Status:", authStatus);
notify(authStatus, t("recordingtable.notifications.auth_success"));
handleNavigate(`/robots/${robotId}/integrate/google`, robotId, "", []);
}
2025-01-25 12:43:57 +05:30
}, []);
const getCurrentPageComponent = () => {
2025-01-10 11:22:49 +05:30
const currentPath = location.pathname;
2024-11-17 00:33:23 +05:30
2025-01-10 11:22:49 +05:30
if (currentPath.endsWith("/run")) {
return (
<RunSettingsModal
isOpen={true}
handleClose={handleClose}
handleStart={handleRunRecording}
isTask={params.length !== 0}
params={params}
/>
);
} else if (currentPath.endsWith("/schedule")) {
return <ScheduleSettingsPage handleStart={handleScheduleRecording} />;
} else if (currentPath.includes("/integrate")) {
2025-01-10 11:22:49 +05:30
return (
<RobotIntegrationPage handleStart={() => {}} robotPath={"robots"} />
2025-01-10 11:22:49 +05:30
);
} else if (currentPath.endsWith("/settings")) {
return <RobotSettingsPage handleStart={() => {}} />;
2025-01-10 11:22:49 +05:30
} else if (currentPath.endsWith("/edit")) {
return <RobotEditPage handleStart={() => {}} />;
2025-01-10 11:22:49 +05:30
} else if (currentPath.endsWith("/duplicate")) {
return <RobotDuplicatePage handleStart={() => {}} />;
2025-01-10 11:22:49 +05:30
}
return null;
};
2024-11-17 14:06:26 +05:30
const currentPath = location.pathname;
const isConfigPage =
currentPath.includes("/schedule") ||
currentPath.includes("/integrate") ||
currentPath.includes("/settings") ||
currentPath.includes("/edit") ||
currentPath.includes("/duplicate") ||
currentPath.includes("/run");
if (isConfigPage) {
return getCurrentPageComponent();
}
2024-06-24 22:41:54 +05:30
return (
<React.Fragment>
2025-01-10 11:22:49 +05:30
<Grid container direction="column" sx={{ padding: "30px" }}>
2024-09-10 03:11:49 +05:30
<Grid item xs>
<RecordingsTable
handleEditRecording={handleEditRecording}
2025-01-10 11:22:49 +05:30
handleRunRecording={(id, name, params) =>
handleNavigate(`/robots/${id}/run`, id, name, params)
}
handleScheduleRecording={(id, name, params) =>
handleNavigate(`/robots/${id}/schedule`, id, name, params)
}
handleIntegrateRecording={(id, name, params) =>
handleNavigate(`/robots/${id}/integrate`, id, name, params)
}
handleSettingsRecording={(id, name, params) =>
handleNavigate(`/robots/${id}/settings`, id, name, params)
}
handleEditRobot={(id, name, params) =>
handleNavigate(`/robots/${id}/edit`, id, name, params)
}
handleDuplicateRobot={(id, name, params) =>
handleNavigate(`/robots/${id}/duplicate`, id, name, params)
}
2024-09-10 03:11:49 +05:30
/>
</Grid>
2024-06-24 22:41:54 +05:30
</Grid>
</React.Fragment>
);
2025-01-10 11:22:49 +05:30
};