Files
parcer/src/components/integration/IntegrationSettings.tsx

654 lines
22 KiB
TypeScript
Raw Normal View History

2024-11-13 00:06:32 +05:30
import React, { useState, useEffect } from "react";
2025-01-09 19:49:20 +05:30
import { GenericModal } from "../ui/GenericModal";
2024-11-13 00:06:32 +05:30
import {
MenuItem,
Typography,
CircularProgress,
Alert,
AlertTitle,
2025-01-27 21:29:11 +05:30
Button,
TextField,
2024-11-13 00:06:32 +05:30
} from "@mui/material";
import axios from "axios";
import { useGlobalInfoStore } from "../../context/globalInfo";
import { getStoredRecording } from "../../api/storage";
import { apiUrl } from "../../apiConfig.js";
2024-12-06 04:29:40 +05:30
2025-01-26 14:22:36 +05:30
import Cookies from "js-cookie";
import { useTranslation } from "react-i18next";
2025-02-26 23:53:51 +05:30
import { useNavigate } from "react-router-dom";
2024-12-06 04:29:40 +05:30
2024-09-17 20:16:50 +05:30
interface IntegrationProps {
2024-11-13 00:06:32 +05:30
isOpen: boolean;
handleStart: (data: IntegrationSettings) => void;
handleClose: () => void;
2025-02-26 23:53:51 +05:30
preSelectedIntegrationType?: "googleSheets" | "airtable" | null;
2024-09-17 17:28:43 +05:30
}
2024-12-08 04:49:29 +05:30
2024-09-17 20:16:50 +05:30
export interface IntegrationSettings {
2025-01-26 21:05:08 +05:30
spreadsheetId?: string;
spreadsheetName?: string;
airtableBaseId?: string;
airtableBaseName?: string;
airtableTableName?: string,
airtableTableId?: string,
2024-11-13 00:06:32 +05:30
data: string;
2025-01-26 21:05:08 +05:30
integrationType: "googleSheets" | "airtable";
2024-09-17 17:28:43 +05:30
}
2024-12-08 04:49:29 +05:30
const getCookie = (name: string): string | null => {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) {
2025-01-26 14:22:36 +05:30
return parts.pop()?.split(";").shift() || null;
2024-12-08 04:49:29 +05:30
}
return null;
};
const removeCookie = (name: string): void => {
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
};
2024-11-13 00:06:32 +05:30
export const IntegrationSettingsModal = ({
isOpen,
handleStart,
handleClose,
2025-02-26 23:53:51 +05:30
preSelectedIntegrationType = null,
2024-11-13 00:06:32 +05:30
}: IntegrationProps) => {
const { t } = useTranslation();
2024-11-13 00:06:32 +05:30
const [settings, setSettings] = useState<IntegrationSettings>({
spreadsheetId: "",
spreadsheetName: "",
2025-01-26 14:22:36 +05:30
airtableBaseId: "",
airtableBaseName: "",
airtableTableName: "",
airtableTableId: "",
2024-11-13 00:06:32 +05:30
data: "",
2025-02-26 23:53:51 +05:30
integrationType: preSelectedIntegrationType || "googleSheets",
2024-11-13 00:06:32 +05:30
});
2024-10-16 22:37:53 +05:30
2025-01-27 21:29:11 +05:30
const [spreadsheets, setSpreadsheets] = useState<{ id: string; name: string }[]>([]);
const [airtableBases, setAirtableBases] = useState<{ id: string; name: string }[]>([]);
const [airtableTables, setAirtableTables] = useState<{ id: string; name: string }[]>([]);
2024-11-13 00:06:32 +05:30
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
2024-10-16 20:47:14 +05:30
2025-02-26 23:53:51 +05:30
const {
recordingId,
notify,
setRerenderRobots
} = useGlobalInfoStore();
2024-11-13 00:06:32 +05:30
const [recording, setRecording] = useState<any>(null);
2025-02-26 23:53:51 +05:30
const navigate = useNavigate();
2024-10-17 14:21:22 +05:30
2025-02-26 23:53:51 +05:30
const [selectedIntegrationType, setSelectedIntegrationType] = useState<
"googleSheets" | "airtable" | null
>(preSelectedIntegrationType);
2025-01-27 21:29:11 +05:30
2024-11-13 00:06:32 +05:30
const authenticateWithGoogle = () => {
2025-01-26 21:05:08 +05:30
window.location.href = `${apiUrl}/auth/google?robotId=${recordingId}`;
2025-01-26 14:22:36 +05:30
};
2025-01-26 14:33:34 +05:30
2025-01-27 21:29:11 +05:30
// Authenticate with Airtable
2025-01-26 14:22:36 +05:30
const authenticateWithAirtable = () => {
2025-01-26 21:05:08 +05:30
window.location.href = `${apiUrl}/auth/airtable?robotId=${recordingId}`;
2024-11-13 00:06:32 +05:30
};
2024-09-17 17:28:43 +05:30
2025-01-27 21:29:11 +05:30
// Fetch Google Sheets files
2025-01-26 14:22:36 +05:30
const fetchSpreadsheetFiles = async () => {
try {
2025-01-26 21:05:08 +05:30
const response = await axios.get(
`${apiUrl}/auth/gsheets/files?robotId=${recordingId}`,
2025-01-27 21:29:11 +05:30
{ withCredentials: true }
2025-01-26 21:05:08 +05:30
);
2024-11-13 00:06:32 +05:30
setSpreadsheets(response.data);
} catch (error: any) {
2025-02-26 23:53:51 +05:30
setLoading(false);
2025-01-27 21:29:11 +05:30
console.error("Error fetching spreadsheet files:", error);
2025-02-26 14:06:19 +05:30
notify("error", t("integration_settings.google.errors.fetch_error", {
2025-01-27 21:29:11 +05:30
message: error.response?.data?.message || error.message,
}));
2024-11-13 00:06:32 +05:30
}
};
2025-01-27 21:29:11 +05:30
// Fetch Airtable bases
2025-01-26 14:22:36 +05:30
const fetchAirtableBases = async () => {
try {
2025-01-26 21:05:08 +05:30
const response = await axios.get(
`${apiUrl}/auth/airtable/bases?robotId=${recordingId}`,
2025-01-27 21:29:11 +05:30
{ withCredentials: true }
2025-01-26 21:05:08 +05:30
);
2025-01-26 14:22:36 +05:30
setAirtableBases(response.data);
} catch (error: any) {
2025-02-26 23:53:51 +05:30
setLoading(false);
2025-01-27 21:29:11 +05:30
console.error("Error fetching Airtable bases:", error);
2025-02-26 14:06:19 +05:30
notify("error", t("integration_settings.airtable.errors.fetch_error", {
2025-01-27 21:29:11 +05:30
message: error.response?.data?.message || error.message,
}));
2025-01-26 14:22:36 +05:30
}
};
const fetchAirtableTables = async (baseId: string, recordingId: string) => {
try {
const response = await axios.get(
`${apiUrl}/auth/airtable/tables?robotId=${recordingId}&baseId=${baseId}`,
{ withCredentials: true }
);
setAirtableTables(response.data);
}
catch (error: any) {
2025-02-26 23:53:51 +05:30
setLoading(false);
console.error("Error fetching Airtable tables:", error);
2025-02-26 14:06:19 +05:30
notify("error", t("integration_settings.airtable.errors.fetch_tables_error", {
message: error.response?.data?.message || error.message,
}));
}
}
2025-01-27 21:29:11 +05:30
// Handle Google Sheets selection
2024-11-13 00:06:32 +05:30
const handleSpreadsheetSelect = (e: React.ChangeEvent<HTMLInputElement>) => {
2025-01-27 21:29:11 +05:30
const selectedSheet = spreadsheets.find((sheet) => sheet.id === e.target.value);
2024-11-13 00:06:32 +05:30
if (selectedSheet) {
setSettings({
...settings,
spreadsheetId: selectedSheet.id,
spreadsheetName: selectedSheet.name,
});
}
};
2024-10-16 20:47:14 +05:30
2025-01-27 21:29:11 +05:30
// Handle Airtable base selection
const handleAirtableBaseSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
2025-01-27 21:29:11 +05:30
const selectedBase = airtableBases.find((base) => base.id === e.target.value);
2025-01-26 14:22:36 +05:30
if (selectedBase) {
setSettings((prevSettings) => ({
...prevSettings,
2025-01-26 14:22:36 +05:30
airtableBaseId: selectedBase.id,
airtableBaseName: selectedBase.name,
}));
if (recordingId) {
await fetchAirtableTables(selectedBase.id, recordingId);
} else {
console.error("Recording ID is null");
}
2025-01-26 14:22:36 +05:30
}
};
const handleAirtabletableSelect = (e: React.ChangeEvent<HTMLInputElement>) => {
const selectedTable = airtableTables.find((table) => table.id === e.target.value);
if (selectedTable) {
setSettings((prevSettings) => ({
...prevSettings,
airtableTableId: e.target.value,
airtableTableName: selectedTable?.name||"",
}));
}
};
2025-02-26 23:53:51 +05:30
const refreshRecordingData = async () => {
if (!recordingId) return null;
const updatedRecording = await getStoredRecording(recordingId);
setRecording(updatedRecording);
setRerenderRobots(true);
return updatedRecording;
};
2024-11-13 00:06:32 +05:30
const updateGoogleSheetId = async () => {
try {
2025-02-26 23:53:51 +05:30
setLoading(true);
2025-01-27 21:29:11 +05:30
await axios.post(
2024-11-13 00:06:32 +05:30
`${apiUrl}/auth/gsheets/update`,
{
spreadsheetId: settings.spreadsheetId,
spreadsheetName: settings.spreadsheetName,
robotId: recordingId,
},
{ withCredentials: true }
);
2025-02-26 23:53:51 +05:30
// Refresh recording data immediately
await refreshRecordingData();
2025-02-26 14:06:19 +05:30
notify("success", t("integration_settings.google.notifications.sheet_selected"));
2025-02-26 23:53:51 +05:30
setLoading(false);
2024-11-13 00:06:32 +05:30
} catch (error: any) {
2025-02-26 23:53:51 +05:30
setLoading(false);
2025-01-27 21:29:11 +05:30
console.error("Error updating Google Sheet ID:", error);
2025-02-26 14:06:19 +05:30
notify("error", t("integration_settings.google.errors.update_error", {
2025-01-27 21:29:11 +05:30
message: error.response?.data?.message || error.message,
}));
2025-01-26 14:22:36 +05:30
}
};
2025-01-27 21:29:11 +05:30
// Update Airtable integration
const updateAirtableBase = async () => {
2025-01-26 14:22:36 +05:30
try {
2025-02-26 23:53:51 +05:30
setLoading(true);
2025-01-27 21:29:11 +05:30
await axios.post(
2025-01-26 14:22:36 +05:30
`${apiUrl}/auth/airtable/update`,
{
baseId: settings.airtableBaseId,
baseName: settings.airtableBaseName,
robotId: recordingId,
tableName: settings.airtableTableName,
2025-02-07 19:43:55 +05:30
tableId: settings.airtableTableId,
2025-01-26 14:22:36 +05:30
},
{ withCredentials: true }
2024-11-13 00:06:32 +05:30
);
2025-02-26 23:53:51 +05:30
await refreshRecordingData();
2025-02-26 14:06:19 +05:30
notify("success", t("integration_settings.airtable.notifications.base_selected"));
2025-02-26 23:53:51 +05:30
setLoading(false);
2025-01-26 14:22:36 +05:30
} catch (error: any) {
2025-02-26 23:53:51 +05:30
setLoading(false);
2025-01-27 21:29:11 +05:30
console.error("Error updating Airtable base:", error);
2025-02-26 14:06:19 +05:30
notify("error", t("integration_settings.airtable.errors.update_error", {
2025-01-27 21:29:11 +05:30
message: error.response?.data?.message || error.message,
}));
2024-11-13 00:06:32 +05:30
}
};
2024-10-17 19:57:09 +05:30
2025-01-27 21:29:11 +05:30
// Remove Google Sheets integration
const removeGoogleSheetsIntegration = async () => {
2024-11-13 00:06:32 +05:30
try {
2025-02-26 23:53:51 +05:30
setLoading(true);
2024-11-13 00:06:32 +05:30
await axios.post(
2025-01-27 21:29:11 +05:30
`${apiUrl}/auth/gsheets/remove`,
2024-11-13 00:06:32 +05:30
{ robotId: recordingId },
{ withCredentials: true }
);
2025-02-26 23:53:51 +05:30
// Clear UI state
2024-11-13 00:06:32 +05:30
setSpreadsheets([]);
2025-01-27 21:29:11 +05:30
setSettings({ ...settings, spreadsheetId: "", spreadsheetName: "" });
2025-02-26 23:53:51 +05:30
// Refresh recording data
await refreshRecordingData();
2025-02-26 14:06:19 +05:30
notify("success", t("integration_settings.google.notifications.integration_removed"));
2025-02-26 23:53:51 +05:30
setLoading(false);
2024-11-13 00:06:32 +05:30
} catch (error: any) {
2025-02-26 23:53:51 +05:30
setLoading(false);
2025-01-27 21:29:11 +05:30
console.error("Error removing Google Sheets integration:", error);
2025-02-26 14:06:19 +05:30
notify("error", t("integration_settings.google.errors.remove_error", {
2025-01-27 21:29:11 +05:30
message: error.response?.data?.message || error.message,
}));
2024-11-13 00:06:32 +05:30
}
};
2025-01-27 21:29:11 +05:30
// Remove Airtable integration
const removeAirtableIntegration = async () => {
try {
2025-02-26 23:53:51 +05:30
setLoading(true);
2025-01-27 21:29:11 +05:30
await axios.post(
`${apiUrl}/auth/airtable/remove`,
{ robotId: recordingId },
{ withCredentials: true }
);
2025-02-26 23:53:51 +05:30
2025-01-27 21:29:11 +05:30
setAirtableBases([]);
2025-02-26 23:53:51 +05:30
setAirtableTables([]);
setSettings({ ...settings, airtableBaseId: "", airtableBaseName: "", airtableTableName:"", airtableTableId: "" });
await refreshRecordingData();
2025-02-26 14:06:19 +05:30
notify("success", t("integration_settings.airtable.notifications.integration_removed"));
2025-02-26 23:53:51 +05:30
setLoading(false);
2025-01-27 21:29:11 +05:30
} catch (error: any) {
2025-02-26 23:53:51 +05:30
setLoading(false);
2025-01-27 21:29:11 +05:30
console.error("Error removing Airtable integration:", error);
2025-02-26 14:06:19 +05:30
notify("error", t("integration_settings.airtable.errors.remove_error", {
2025-01-27 21:29:11 +05:30
message: error.response?.data?.message || error.message,
}));
2025-01-26 21:05:08 +05:30
}
2025-01-27 21:29:11 +05:30
};
2025-01-26 14:33:34 +05:30
2025-01-27 21:29:11 +05:30
const handleAirtableOAuthCallback = async () => {
try {
const response = await axios.get(`${apiUrl}/auth/airtable/callback`);
if (response.data.success) {
2025-02-26 23:53:51 +05:30
await refreshRecordingData();
2025-01-27 21:29:11 +05:30
}
} catch (error) {
2025-02-26 14:06:19 +05:30
setError(t("integration_settings.airtable.errors.auth_error"));
2025-01-26 21:05:08 +05:30
}
2025-01-27 21:29:11 +05:30
};
2024-11-13 00:06:32 +05:30
2025-01-27 21:29:11 +05:30
useEffect(() => {
2025-01-26 14:33:34 +05:30
const fetchRecordingInfo = async () => {
if (!recordingId) return;
2025-02-26 23:53:51 +05:30
setLoading(true);
2025-01-26 14:33:34 +05:30
const recording = await getStoredRecording(recordingId);
if (recording) {
setRecording(recording);
2025-02-26 23:53:51 +05:30
if (preSelectedIntegrationType) {
setSettings(prev => ({ ...prev, integrationType: preSelectedIntegrationType }));
}
else if (recording.google_sheet_id) {
2025-02-26 23:53:51 +05:30
setSettings(prev => ({ ...prev, integrationType: "googleSheets" }));
2025-01-26 21:05:08 +05:30
} else if (recording.airtable_base_id) {
setSettings(prev => ({
...prev,
airtableBaseId: recording.airtable_base_id || "",
airtableBaseName: recording.airtable_base_name || "",
airtableTableName: recording.airtable_table_name || "",
2025-02-26 23:53:51 +05:30
airtableTableId: recording.airtable_table_id || "",
integrationType: recording.airtable_base_id ? "airtable" : "googleSheets"
}));
2025-01-26 21:05:08 +05:30
}
2025-01-26 14:33:34 +05:30
}
2025-02-26 23:53:51 +05:30
setLoading(false);
2025-01-26 14:33:34 +05:30
};
2025-02-26 23:53:51 +05:30
2025-01-26 14:33:34 +05:30
fetchRecordingInfo();
2025-02-26 23:53:51 +05:30
}, [recordingId, preSelectedIntegrationType]);
2025-01-26 14:33:34 +05:30
2025-01-27 21:29:11 +05:30
useEffect(() => {
const status = getCookie("airtable_auth_status");
const message = getCookie("airtable_auth_message");
2025-02-26 23:53:51 +05:30
if (status === "success") {
notify("success", message || t("integration_settings.airtable.notifications.auth_success"));
2025-01-27 21:29:11 +05:30
removeCookie("airtable_auth_status");
removeCookie("airtable_auth_message");
2025-02-26 23:53:51 +05:30
refreshRecordingData();
2025-01-27 21:29:11 +05:30
}
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get("code");
if (code) {
handleAirtableOAuthCallback();
}
2025-02-26 23:53:51 +05:30
}, []);
// Add this UI at the top of the modal return statement
if (!selectedIntegrationType) {
return (
<GenericModal
isOpen={isOpen}
onClose={handleClose}
modalStyle={modalStyle}
>
<div style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
padding: "20px"
}}>
<div style={{ display: "flex", gap: "20px" }}>
<Button
variant="contained"
color="primary"
onClick={() => {
setSelectedIntegrationType("googleSheets");
setSettings({ ...settings, integrationType: "googleSheets" });
navigate(`/robots/${recordingId}/integrate/google`);
}}
>
Google Sheets
</Button>
<Button
variant="contained"
color="primary"
onClick={() => {
setSelectedIntegrationType("airtable");
setSettings({ ...settings, integrationType: "airtable" });
navigate(`/robots/${recordingId}/integrate/airtable`);
}}
>
Airtable
</Button>
</div>
2025-01-26 21:05:08 +05:30
</div>
2025-02-26 23:53:51 +05:30
</GenericModal>
);
}
2025-01-27 21:29:11 +05:30
2024-11-13 00:06:32 +05:30
return (
<GenericModal isOpen={isOpen} onClose={handleClose} modalStyle={modalStyle}>
2025-01-27 21:29:11 +05:30
<div style={{
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
marginLeft: "65px",
}}>
2025-01-26 21:05:08 +05:30
2025-01-27 21:29:11 +05:30
{settings.integrationType === "googleSheets" && (
<>
2025-02-26 14:06:19 +05:30
<Typography variant="h6">
{t("integration_settings.google.title")}
</Typography>
2025-01-27 21:29:11 +05:30
{recording?.google_sheet_id ? (
<>
<Alert severity="info" sx={{ marginTop: "10px", border: "1px solid #ff00c3" }}>
2025-02-26 14:06:19 +05:30
<AlertTitle>{t("integration_settings.google.alerts.success.title")}</AlertTitle>
{t("integration_settings.google.alerts.success.content", {
2025-01-27 21:29:11 +05:30
sheetName: recording.google_sheet_name,
})}
<a
href={`https://docs.google.com/spreadsheets/d/${recording.google_sheet_id}`}
target="_blank"
rel="noreferrer"
>
2025-02-26 14:06:19 +05:30
{t("integration_settings.google.alerts.success.here")}
2025-01-27 21:29:11 +05:30
</a>
</Alert>
<Button
variant="outlined"
color="error"
onClick={removeGoogleSheetsIntegration}
style={{ marginTop: "15px" }}
2025-02-26 23:53:51 +05:30
disabled={loading}
2025-01-27 21:29:11 +05:30
>
2025-02-26 23:53:51 +05:30
{loading ? <CircularProgress size={24} /> : t("integration_settings.google.buttons.remove_integration")}
2025-01-27 21:29:11 +05:30
</Button>
</>
) : (
<>
{!recording?.google_sheet_email ? (
2025-01-26 21:05:08 +05:30
<>
2025-02-26 14:06:19 +05:30
<p>{t("integration_settings.google.descriptions.sync_info")}</p>
2025-01-27 21:29:11 +05:30
<Button
variant="contained"
color="primary"
onClick={authenticateWithGoogle}
2025-02-26 23:53:51 +05:30
disabled={loading}
2025-01-26 21:05:08 +05:30
>
2025-02-26 23:53:51 +05:30
{loading ? <CircularProgress size={24} /> : t("integration_settings.google.buttons.authenticate")}
2025-01-27 21:29:11 +05:30
</Button>
2025-01-26 21:05:08 +05:30
</>
) : (
<>
2025-01-27 21:29:11 +05:30
<Typography sx={{ margin: "20px 0px 30px 0px" }}>
2025-02-26 14:06:19 +05:30
{t("integration_settings.google.descriptions.authenticated_as", {
2025-01-27 21:29:11 +05:30
email: recording.google_sheet_email,
})}
</Typography>
{loading ? (
<CircularProgress sx={{ marginBottom: "15px" }} />
) : error ? (
<Typography color="error">{error}</Typography>
) : spreadsheets.length === 0 ? (
<Button
variant="outlined"
color="primary"
onClick={fetchSpreadsheetFiles}
2025-02-26 23:53:51 +05:30
disabled={loading}
2025-01-27 21:29:11 +05:30
>
2025-02-26 14:06:19 +05:30
{t("integration_settings.google.buttons.fetch_sheets")}
2025-01-27 21:29:11 +05:30
</Button>
) : (
<>
<TextField
sx={{ marginBottom: "15px" }}
select
2025-02-26 14:06:19 +05:30
label={t("integration_settings.google.fields.select_sheet")}
2025-01-27 21:29:11 +05:30
required
value={settings.spreadsheetId}
onChange={handleSpreadsheetSelect}
fullWidth
>
{spreadsheets.map((sheet) => (
<MenuItem key={sheet.id} value={sheet.id}>
{sheet.name}
</MenuItem>
))}
</TextField>
<Button
variant="contained"
color="primary"
2025-02-26 23:53:51 +05:30
onClick={updateGoogleSheetId}
2025-01-27 21:29:11 +05:30
style={{ marginTop: "10px" }}
disabled={!settings.spreadsheetId || loading}
>
2025-02-26 23:53:51 +05:30
{loading ? <CircularProgress size={24} /> : t("integration_settings.google.buttons.submit")}
2025-01-27 21:29:11 +05:30
</Button>
</>
)}
2025-01-26 21:05:08 +05:30
</>
)}
2025-01-27 21:29:11 +05:30
</>
2025-01-26 21:05:08 +05:30
)}
2025-01-27 21:29:11 +05:30
</>
)}
2025-01-26 21:05:08 +05:30
2025-01-27 21:29:11 +05:30
{settings.integrationType === "airtable" && (
<>
2025-02-26 14:06:19 +05:30
<Typography variant="h6">
{t("integration_settings.airtable.title")}
</Typography>
2025-01-27 21:29:11 +05:30
{recording?.airtable_base_id ? (
2024-11-13 00:06:32 +05:30
<>
2025-02-26 14:06:19 +05:30
<Alert severity="info" sx={{ marginTop: "10px", border: "1px solid #ff00c3" }}>
<AlertTitle>{t("integration_settings.airtable.alerts.success.title")}</AlertTitle>
{t("integration_settings.airtable.alerts.success.content", {
2025-01-27 21:29:11 +05:30
baseName: recording.airtable_base_name,
2025-02-26 14:06:19 +05:30
tableName: recording.airtable_table_name
2025-01-27 21:29:11 +05:30
})}
<a
href={`https://airtable.com/${recording.airtable_base_id}`}
target="_blank"
rel="noreferrer"
2025-01-26 21:05:08 +05:30
>
2025-02-26 14:06:19 +05:30
{t("integration_settings.airtable.alerts.success.here")}
2025-01-27 21:29:11 +05:30
</a>
</Alert>
<Button
variant="outlined"
color="error"
onClick={removeAirtableIntegration}
style={{ marginTop: "15px" }}
2025-02-26 23:53:51 +05:30
disabled={loading}
2025-01-27 21:29:11 +05:30
>
2025-02-26 23:53:51 +05:30
{loading ? <CircularProgress size={24} /> : t("integration_settings.airtable.buttons.remove_integration")}
2025-01-27 21:29:11 +05:30
</Button>
2024-11-13 00:06:32 +05:30
</>
) : (
<>
2025-01-27 21:29:11 +05:30
{!recording?.airtable_access_token ? (
<>
2025-02-26 14:06:19 +05:30
<p>{t("integration_settings.airtable.descriptions.sync_info")}</p>
2025-01-27 21:29:11 +05:30
<Button
variant="contained"
2025-02-26 14:06:19 +05:30
color="primary"
2025-01-27 21:29:11 +05:30
onClick={authenticateWithAirtable}
2025-02-26 23:53:51 +05:30
disabled={loading}
2025-01-27 21:29:11 +05:30
>
2025-02-26 23:53:51 +05:30
{loading ? <CircularProgress size={24} /> : t("integration_settings.airtable.buttons.authenticate")}
2025-01-27 21:29:11 +05:30
</Button>
</>
) : (
<>
<Typography sx={{ margin: "20px 0px 30px 0px" }}>
2025-02-26 14:06:19 +05:30
{t("integration_settings.airtable.descriptions.authenticated_as")}
2025-01-27 21:29:11 +05:30
</Typography>
{loading ? (
<CircularProgress sx={{ marginBottom: "15px" }} />
) : error ? (
<Typography color="error">{error}</Typography>
) : airtableBases.length === 0 ? (
<Button
variant="outlined"
2025-02-26 14:06:19 +05:30
color="primary"
2025-01-27 21:29:11 +05:30
onClick={fetchAirtableBases}
2025-02-26 23:53:51 +05:30
disabled={loading}
2025-01-27 21:29:11 +05:30
>
2025-02-26 14:06:19 +05:30
{t("integration_settings.airtable.buttons.fetch_bases")}
2025-01-27 21:29:11 +05:30
</Button>
) : (
<>
<TextField
sx={{ marginBottom: "15px" }}
select
2025-02-26 14:06:19 +05:30
label={t("integration_settings.airtable.fields.select_base")}
2025-01-27 21:29:11 +05:30
required
value={settings.airtableBaseId}
onChange={handleAirtableBaseSelect}
fullWidth
>
{airtableBases.map((base) => (
<MenuItem key={base.id} value={base.id}>
{base.name}
</MenuItem>
))}
</TextField>
<TextField
sx={{ marginBottom: "15px" }}
select
2025-02-26 14:06:19 +05:30
label={t("integration_settings.airtable.fields.select_table")}
required
value={settings.airtableTableId}
onChange={handleAirtabletableSelect}
fullWidth
>
{airtableTables.map((table) => (
<MenuItem key={table.id} value={table.id}>
{table.name}
</MenuItem>
))}
2025-01-27 21:29:11 +05:30
</TextField>
<Button
variant="contained"
2025-02-26 14:06:19 +05:30
color="primary"
2025-02-26 23:53:51 +05:30
onClick={updateAirtableBase}
2025-01-27 21:29:11 +05:30
style={{ marginTop: "10px" }}
disabled={!settings.airtableBaseId || loading}
>
2025-02-26 23:53:51 +05:30
{loading ? <CircularProgress size={24} /> : t("integration_settings.airtable.buttons.submit")}
2025-01-27 21:29:11 +05:30
</Button>
</>
)}
</>
2024-11-13 00:06:32 +05:30
)}
</>
)}
</>
)}
</div>
</GenericModal>
);
2024-09-17 20:10:51 +05:30
};
export const modalStyle = {
2024-11-13 00:06:32 +05:30
top: "40%",
left: "50%",
transform: "translate(-50%, -50%)",
width: "50%",
backgroundColor: "background.paper",
p: 4,
height: "fit-content",
display: "block",
padding: "20px",
2025-01-27 21:29:11 +05:30
};