Merge pull request #78 from amhsirak/develop

feat: option to remove gsheet integration
This commit is contained in:
Karishma Shukla
2024-10-21 02:40:41 +05:30
committed by GitHub
2 changed files with 61 additions and 8 deletions

View File

@@ -354,3 +354,30 @@ router.post('/gsheets/update', requireSignIn, async (req, res) => {
res.status(500).json({ message: `Error updating robot: ${error.message}` }); 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}` });
}
});

View File

@@ -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(() => { useEffect(() => {
// Check if we're on the callback URL // Check if we're on the callback URL
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
@@ -102,6 +118,7 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I
<Typography sx={{ margin: '20px 0px' }}>Google Sheets Integration</Typography> <Typography sx={{ margin: '20px 0px' }}>Google Sheets Integration</Typography>
{recording && recording.google_sheet_id ? ( {recording && recording.google_sheet_id ? (
<>
<Typography sx={{ marginBottom: '10px' }}> <Typography sx={{ marginBottom: '10px' }}>
Google Sheet Integrated Successfully! Google Sheet Integrated Successfully!
<br /> <br />
@@ -109,6 +126,15 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I
<br /> <br />
Sheet ID: {recording.google_sheet_id} Sheet ID: {recording.google_sheet_id}
</Typography> </Typography>
<Button
variant="outlined"
color="error"
onClick={removeIntegration}
style={{ marginTop: '15px' }}
>
Remove Integration
</Button>
</>
) : ( ) : (
<> <>
{!recording?.google_sheet_email ? ( {!recording?.google_sheet_email ? (