feat: add page components for config actions

This commit is contained in:
Rohit
2025-08-04 22:40:33 +05:30
parent 3fa00c8add
commit aa2775d744

View File

@@ -2,11 +2,14 @@ import React, { useEffect, useState } from "react";
import { RecordingsTable } from "./RecordingsTable"; import { RecordingsTable } from "./RecordingsTable";
import { Grid } from "@mui/material"; import { Grid } from "@mui/material";
import { RunSettings, RunSettingsModal } from "../run/RunSettings"; import { RunSettings, RunSettingsModal } from "../run/RunSettings";
import { ScheduleSettings, ScheduleSettingsModal } from "./ScheduleSettings"; import {
import { IntegrationSettingsModal } from "../integration/IntegrationSettings"; ScheduleSettings,
import { RobotSettingsModal } from "./RobotSettings"; ScheduleSettingsPage,
import { RobotEditModal } from "./RobotEdit"; } from "./pages/ScheduleSettingsPage";
import { RobotDuplicationModal } from "./RobotDuplicate"; import { RobotIntegrationPage } from "./pages/RobotIntegrationPage";
import { RobotSettingsPage } from "./pages/RobotSettingsPage";
import { RobotEditPage } from "./pages/RobotEditPage";
import { RobotDuplicatePage } from "./pages/RobotDuplicatePage";
import { useNavigate, useLocation, useParams } from "react-router-dom"; import { useNavigate, useLocation, useParams } from "react-router-dom";
import { useGlobalInfoStore } from "../../context/globalInfo"; import { useGlobalInfoStore } from "../../context/globalInfo";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@@ -26,12 +29,16 @@ export const Recordings = ({
}: RecordingsProps) => { }: RecordingsProps) => {
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
const { selectedRecordingId } = useParams();
const [params, setParams] = useState<string[]>([]); const [params, setParams] = useState<string[]>([]);
const { notify } = useGlobalInfoStore(); const { notify } = useGlobalInfoStore();
const { t } = useTranslation(); const { t } = useTranslation();
const handleNavigate = (path: string, id: string, name: string, params: string[]) => { const handleNavigate = (
path: string,
id: string,
name: string,
params: string[]
) => {
setParams(params); setParams(params);
setRecordingInfo(id, name); setRecordingInfo(id, name);
navigate(path); navigate(path);
@@ -47,9 +54,9 @@ export const Recordings = ({
// Helper function to get and clear a cookie // Helper function to get and clear a cookie
const getAndClearCookie = (name: string) => { const getAndClearCookie = (name: string) => {
const value = document.cookie const value = document.cookie
.split('; ') .split("; ")
.find(row => row.startsWith(`${name}=`)) .find((row) => row.startsWith(`${name}=`))
?.split('=')[1]; ?.split("=")[1];
if (value) { if (value) {
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`; document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
@@ -58,24 +65,25 @@ export const Recordings = ({
return value; return value;
}; };
const authStatus = getAndClearCookie('robot_auth_status'); const authStatus = getAndClearCookie("robot_auth_status");
const airtableAuthStatus = getAndClearCookie('airtable_auth_status'); const airtableAuthStatus = getAndClearCookie("airtable_auth_status");
const robotId = getAndClearCookie('robot_auth_robotId'); const robotId = getAndClearCookie("robot_auth_robotId");
if (airtableAuthStatus === 'success' && robotId) { if (airtableAuthStatus === "success" && robotId) {
console.log("Airtable Auth Status:", airtableAuthStatus); console.log("Airtable Auth Status:", airtableAuthStatus);
notify(airtableAuthStatus, t("recordingtable.notifications.auth_success")); notify(
airtableAuthStatus,
t("recordingtable.notifications.auth_success")
);
handleNavigate(`/robots/${robotId}/integrate/airtable`, robotId, "", []); handleNavigate(`/robots/${robotId}/integrate/airtable`, robotId, "", []);
} } else if (authStatus === "success" && robotId) {
else if (authStatus === 'success' && robotId) {
console.log("Google Auth Status:", authStatus); console.log("Google Auth Status:", authStatus);
notify(authStatus, t("recordingtable.notifications.auth_success")); notify(authStatus, t("recordingtable.notifications.auth_success"));
handleNavigate(`/robots/${robotId}/integrate/google`, robotId, "", []); handleNavigate(`/robots/${robotId}/integrate/google`, robotId, "", []);
} }
}, []); }, []);
// Determine which modal to open based on the current route const getCurrentPageComponent = () => {
const getCurrentModal = () => {
const currentPath = location.pathname; const currentPath = location.pathname;
if (currentPath.endsWith("/run")) { if (currentPath.endsWith("/run")) {
@@ -89,79 +97,36 @@ export const Recordings = ({
/> />
); );
} else if (currentPath.endsWith("/schedule")) { } else if (currentPath.endsWith("/schedule")) {
return <ScheduleSettingsPage handleStart={handleScheduleRecording} />;
} else if (currentPath.includes("/integrate")) {
return ( return (
<ScheduleSettingsModal <RobotIntegrationPage handleStart={() => {}} robotPath={"robots"} />
isOpen={true}
handleClose={handleClose}
handleStart={handleScheduleRecording}
/>
);
} else if (currentPath.endsWith("/integrate/google")) {
return (
<IntegrationSettingsModal
isOpen={true}
handleClose={handleClose}
handleStart={() => {}}
preSelectedIntegrationType="googleSheets"
/>
);
} else if (currentPath.endsWith("/integrate/airtable")) {
return (
<IntegrationSettingsModal
isOpen={true}
handleClose={handleClose}
handleStart={() => {}}
preSelectedIntegrationType="airtable"
/>
);
} else if (currentPath.endsWith("/integrate/webhook")) {
return (
<IntegrationSettingsModal
isOpen={true}
handleClose={handleClose}
handleStart={() => {}}
preSelectedIntegrationType="webhook"
/>
);
} else if (currentPath.endsWith("/integrate")) {
return (
<IntegrationSettingsModal
isOpen={true}
handleClose={handleClose}
handleStart={() => {}}
/>
); );
} else if (currentPath.endsWith("/settings")) { } else if (currentPath.endsWith("/settings")) {
return ( return <RobotSettingsPage handleStart={() => {}} />;
<RobotSettingsModal
isOpen={true}
handleClose={handleClose}
handleStart={() => {}}
/>
);
} else if (currentPath.endsWith("/edit")) { } else if (currentPath.endsWith("/edit")) {
return ( return <RobotEditPage handleStart={() => {}} />;
<RobotEditModal
isOpen={true}
handleClose={handleClose}
handleStart={() => {}}
/>
);
} else if (currentPath.endsWith("/duplicate")) { } else if (currentPath.endsWith("/duplicate")) {
return ( return <RobotDuplicatePage handleStart={() => {}} />;
<RobotDuplicationModal
isOpen={true}
handleClose={handleClose}
handleStart={() => {}}
/>
);
} }
return null; return null;
}; };
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();
}
return ( return (
<React.Fragment> <React.Fragment>
{getCurrentModal()}
<Grid container direction="column" sx={{ padding: "30px" }}> <Grid container direction="column" sx={{ padding: "30px" }}>
<Grid item xs> <Grid item xs>
<RecordingsTable <RecordingsTable