Merge pull request #78 from amhsirak/develop
feat: option to remove gsheet integration
This commit is contained in:
@@ -302,7 +302,7 @@ router.post('/gsheets/data', requireSignIn, async (req, res) => {
|
|||||||
router.get('/gsheets/files', requireSignIn, async (req, res) => {
|
router.get('/gsheets/files', requireSignIn, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const robotId = req.query.robotId;
|
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) {
|
if (!robot) {
|
||||||
return res.status(400).json({ message: 'Robot not found' });
|
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}` });
|
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}` });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -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,13 +118,23 @@ 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' }}>
|
<>
|
||||||
Google Sheet Integrated Successfully!
|
<Typography sx={{ marginBottom: '10px' }}>
|
||||||
<br />
|
Google Sheet Integrated Successfully!
|
||||||
Sheet Name: {recording.google_sheet_name}
|
<br />
|
||||||
<br />
|
Sheet Name: {recording.google_sheet_name}
|
||||||
Sheet ID: {recording.google_sheet_id}
|
<br />
|
||||||
</Typography>
|
Sheet ID: {recording.google_sheet_id}
|
||||||
|
</Typography>
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
color="error"
|
||||||
|
onClick={removeIntegration}
|
||||||
|
style={{ marginTop: '15px' }}
|
||||||
|
>
|
||||||
|
Remove Integration
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{!recording?.google_sheet_email ? (
|
{!recording?.google_sheet_email ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user