diff --git a/src/components/molecules/IntegrationSettings.tsx b/src/components/molecules/IntegrationSettings.tsx index 81279f85..a258ded1 100644 --- a/src/components/molecules/IntegrationSettings.tsx +++ b/src/components/molecules/IntegrationSettings.tsx @@ -28,28 +28,28 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I const [userInfo, setUserInfo] = useState<{ email: string } | null>(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); - const [isAuthenticated, setIsAuthenticated] = useState(false); + const [googleSheetsEmail, setGoogleSheetsEmail] = useState(null); // To store the Google Sheets email const { recordingId } = useGlobalInfoStore(); - // trigger Google OAuth authentication + // Function to trigger Google OAuth authentication const authenticateWithGoogle = () => { window.location.href = `http://localhost:8080/auth/google?robotId=${recordingId}`; }; - // handle Google OAuth callback and fetch spreadsheets + // Function to handle Google OAuth callback and fetch spreadsheets const handleOAuthCallback = async () => { try { const response = await axios.get(`http://localhost:8080/auth/google/callback`); const { google_sheet_email, files } = response.data; setUserInfo({ email: google_sheet_email }); setSpreadsheets(files); - setIsAuthenticated(true); } catch (error) { setError('Error authenticating with Google'); } }; + // Handle spreadsheet selection const handleSpreadsheetSelect = (e: React.ChangeEvent) => { setSettings({ ...settings, spreadsheetId: e.target.value }); }; @@ -61,7 +61,18 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I if (code) { handleOAuthCallback(); } - }, []); + + // Fetch the stored recording to check the Google Sheets email + const fetchRecordingInfo = async () => { + if (!recordingId) return; + const recording = await getStoredRecording(recordingId); + if (recording) { + setGoogleSheetsEmail(recording.google_sheets_email); // Assuming this is how the email is stored + } + }; + + fetchRecordingInfo(); + }, [recordingId]); return ( Google Sheets Integration - {/* If user is not authenticated, show Google OAuth button */} - {!isAuthenticated ? ( + {/* If Google Sheets email is empty, show Google OAuth button */} + {!googleSheetsEmail ? (