From 746c3b5ea194e0a50a4e64475824fa474ebdf18a Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 17 Oct 2024 19:24:03 +0530 Subject: [PATCH] refactor: remove extra S in column names --- .../molecules/IntegrationSettings.tsx | 172 +++++++++--------- 1 file changed, 87 insertions(+), 85 deletions(-) diff --git a/src/components/molecules/IntegrationSettings.tsx b/src/components/molecules/IntegrationSettings.tsx index 34c4911c..ef0645eb 100644 --- a/src/components/molecules/IntegrationSettings.tsx +++ b/src/components/molecules/IntegrationSettings.tsx @@ -28,7 +28,9 @@ 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 [googleSheetsEmail, setGoogleSheetsEmail] = useState(null); // To store the Google Sheets email + const [googleSheetsEmail, setGoogleSheetsEmail] = useState(null); + const [googleSheetId, setGoogleSheetId] = useState(null); // Store the integrated sheet ID + const [googleSheetName, setGoogleSheetName] = useState(null); // Store the integrated sheet name const { recordingId } = useGlobalInfoStore(); @@ -43,7 +45,6 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I 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); } catch (error) { setError('Error authenticating with Google'); } @@ -55,28 +56,18 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I withCredentials: true, }); setSpreadsheets(response.data); - console.log(`Fetched spreadsheets:`, response.data); } catch (error: any) { console.error('Error fetching spreadsheet files:', error.response?.data?.message || error.message); } }; - // Function to send the selected sheet ID to the backend to update the robot's google_sheet_id - const updateGoogleSheetId = async () => { - try { - const response = await axios.post( - `http://localhost:8080/auth/gsheets/update`, - { spreadsheetId: settings.spreadsheetId, robotId: recordingId }, - { withCredentials: true } - ); - console.log('Google Sheet ID updated:', response.data); - } catch (error: any) { - console.error('Error updating Google Sheet ID:', error.response?.data?.message || error.message); - } - }; - // Handle spreadsheet selection const handleSpreadsheetSelect = (e: React.ChangeEvent) => { + const selectedSheet = spreadsheets.find(sheet => sheet.id === e.target.value); + if (selectedSheet) { + setGoogleSheetId(selectedSheet.id); + setGoogleSheetName(selectedSheet.name); + } setSettings({ ...settings, spreadsheetId: e.target.value }); }; @@ -88,12 +79,14 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I handleOAuthCallback(); } - // Fetch the stored recording to check the Google Sheets email + // Fetch the stored recording to check the Google Sheets email and google_sheet_id const fetchRecordingInfo = async () => { if (!recordingId) return; const recording = await getStoredRecording(recordingId); if (recording) { - setGoogleSheetsEmail(recording.google_sheets_email); + setGoogleSheetsEmail(recording.google_sheet_email); + setGoogleSheetId(recording.google_sheet_id); + setGoogleSheetName(recording.google_sheet_id); } }; @@ -101,83 +94,92 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I }, [recordingId]); return ( - -
+ +
Google Sheets Integration - {!googleSheetsEmail ? ( - + {/* Check if Google Sheet is already integrated */} + {googleSheetId ? ( + + Google Sheet Integrated Successfully! +
+ Sheet Name: {googleSheetName} +
+ Sheet ID: {googleSheetId} +
) : ( <> - {userInfo && ( - <> - - Logged in as: {userInfo.email} - - - )} - - {loading ? ( - - ) : error ? ( - {error} + {/* If Google Sheets email is empty, show Google OAuth button */} + {!googleSheetsEmail ? ( + ) : ( <> - - {spreadsheets.map(sheet => ( - - {sheet.name} - - ))} - - - - - {settings.spreadsheetId && ( + {/* Show user info and allow spreadsheet selection once authenticated */} + {userInfo && ( - Selected Spreadsheet ID: {settings.spreadsheetId} + Logged in as: {userInfo.email} )} + + {loading ? ( + + ) : error ? ( + {error} + ) : spreadsheets.length === 0 ? ( + + ) : ( + <> + {/* Dropdown for selecting the Google Sheet */} + + {spreadsheets.map(sheet => ( + + {sheet.name} + + ))} + + + {/* Display selected spreadsheet name and ID */} + {settings.spreadsheetId && ( + + Selected Sheet: {googleSheetName} (ID: {settings.spreadsheetId}) + + )} + + + + )} )} - - )}