feat: handle state as per robot
This commit is contained in:
@@ -28,28 +28,28 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I
|
|||||||
const [userInfo, setUserInfo] = useState<{ email: string } | null>(null);
|
const [userInfo, setUserInfo] = useState<{ email: string } | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
const [googleSheetsEmail, setGoogleSheetsEmail] = useState<string | null>(null); // To store the Google Sheets email
|
||||||
|
|
||||||
const { recordingId } = useGlobalInfoStore();
|
const { recordingId } = useGlobalInfoStore();
|
||||||
|
|
||||||
// trigger Google OAuth authentication
|
// Function to trigger Google OAuth authentication
|
||||||
const authenticateWithGoogle = () => {
|
const authenticateWithGoogle = () => {
|
||||||
window.location.href = `http://localhost:8080/auth/google?robotId=${recordingId}`;
|
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 () => {
|
const handleOAuthCallback = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`http://localhost:8080/auth/google/callback`);
|
const response = await axios.get(`http://localhost:8080/auth/google/callback`);
|
||||||
const { google_sheet_email, files } = response.data;
|
const { google_sheet_email, files } = response.data;
|
||||||
setUserInfo({ email: google_sheet_email });
|
setUserInfo({ email: google_sheet_email });
|
||||||
setSpreadsheets(files);
|
setSpreadsheets(files);
|
||||||
setIsAuthenticated(true);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError('Error authenticating with Google');
|
setError('Error authenticating with Google');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle spreadsheet selection
|
||||||
const handleSpreadsheetSelect = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleSpreadsheetSelect = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setSettings({ ...settings, spreadsheetId: e.target.value });
|
setSettings({ ...settings, spreadsheetId: e.target.value });
|
||||||
};
|
};
|
||||||
@@ -61,7 +61,18 @@ export const IntegrationSettingsModal = ({ isOpen, handleStart, handleClose }: I
|
|||||||
if (code) {
|
if (code) {
|
||||||
handleOAuthCallback();
|
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 (
|
return (
|
||||||
<GenericModal
|
<GenericModal
|
||||||
@@ -76,8 +87,8 @@ 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>
|
||||||
|
|
||||||
{/* If user is not authenticated, show Google OAuth button */}
|
{/* If Google Sheets email is empty, show Google OAuth button */}
|
||||||
{!isAuthenticated ? (
|
{!googleSheetsEmail ? (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
|
|||||||
Reference in New Issue
Block a user