diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 697a1129..16304d09 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -302,7 +302,7 @@ router.post('/gsheets/data', requireSignIn, async (req, res) => { router.get('/gsheets/files', requireSignIn, async (req, res) => { try { const robotId = req.query.robotId; - const robot = await Robot.findOne({ where: { 'recording_meta.id': robotId }, raw:true }); + const robot = await Robot.findOne({ where: { 'recording_meta.id': robotId }, raw: true }); if (!robot) { return res.status(400).json({ message: 'Robot not found' }); @@ -354,3 +354,30 @@ router.post('/gsheets/update', requireSignIn, async (req, res) => { res.status(500).json({ message: `Error updating robot: ${error.message}` }); } }); + +router.post('/gsheets/remove', requireSignIn, async (req, res) => { + const { robotId } = req.body; + if (!robotId) { + return res.status(400).json({ message: 'Robot ID is required' }); + } + + try { + let robot = await Robot.findOne({ where: { 'recording_meta.id': robotId } }); + + if (!robot) { + return res.status(404).json({ message: 'Robot not found' }); + } + + await robot.update({ + google_sheet_id: null, + google_sheet_name: null, + google_sheet_email: null, + google_access_token: null, + google_refresh_token: null + }); + + res.json({ message: 'Google Sheets integration removed successfully' }); + } catch (error: any) { + res.status(500).json({ message: `Error removing Google Sheets integration: ${error.message}` }); + } +}); diff --git a/src/components/molecules/IntegrationSettings.tsx b/src/components/molecules/IntegrationSettings.tsx index b1e87347..898a2042 100644 --- a/src/components/molecules/IntegrationSettings.tsx +++ b/src/components/molecules/IntegrationSettings.tsx @@ -77,6 +77,22 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I } }; + const removeIntegration = async () => { + try { + await axios.post( + `http://localhost:8080/auth/gsheets/remove`, + { robotId: recordingId }, + { withCredentials: true } + ); + + setRecording(null); + setSpreadsheets([]); + setSettings({ spreadsheetId: '', spreadsheetName: '', data: '' }); + } catch (error: any) { + console.error('Error removing Google Sheets integration:', error.response?.data?.message || error.message); + } + }; + useEffect(() => { // Check if we're on the callback URL const urlParams = new URLSearchParams(window.location.search); @@ -102,13 +118,23 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I Google Sheets Integration {recording && recording.google_sheet_id ? ( - - Google Sheet Integrated Successfully! -
- Sheet Name: {recording.google_sheet_name} -
- Sheet ID: {recording.google_sheet_id} -
+ <> + + Google Sheet Integrated Successfully! +
+ Sheet Name: {recording.google_sheet_name} +
+ Sheet ID: {recording.google_sheet_id} +
+ + ) : ( <> {!recording?.google_sheet_email ? (