import React, { useState } from 'react'; import { Grid, Button, Box, Typography } from '@mui/material'; import { SaveRecording } from "./SaveRecording"; import { useGlobalInfoStore } from '../../context/globalInfo'; import { useActionContext } from '../../context/browserActions'; import { useBrowserSteps } from '../../context/browserSteps'; import { stopRecording } from "../../api/recording"; import { useNavigate } from 'react-router-dom'; import { GenericModal } from "../atoms/GenericModal"; import { useTranslation } from 'react-i18next'; import { emptyWorkflow } from '../../shared/constants'; import { useSocketStore } from '../../context/socket'; const BrowserRecordingSave = () => { const { t } = useTranslation(); const [openDiscardModal, setOpenDiscardModal] = useState(false); const [openResetModal, setOpenResetModal] = useState(false); const { recordingName, browserId, setBrowserId, notify, setCurrentWorkflowActionsState, resetInterpretationLog } = useGlobalInfoStore(); const navigate = useNavigate(); const { socket } = useSocketStore(); const { stopGetText, stopGetList, stopGetScreenshot, stopPaginationMode, stopLimitMode, setCaptureStage, updatePaginationType, updateLimitType, updateCustomLimit, setShowLimitOptions, setShowPaginationOptions, setWorkflow, } = useActionContext(); const { browserSteps, deleteBrowserStep } = useBrowserSteps(); const goToMainMenu = async () => { if (browserId) { await stopRecording(browserId); notify('warning', t('browser_recording.notifications.terminated')); setBrowserId(null); } navigate('/'); }; const performReset = () => { stopGetText(); stopGetList(); stopGetScreenshot(); stopPaginationMode(); stopLimitMode(); setShowLimitOptions(false); setShowPaginationOptions(false); setCaptureStage('initial'); updatePaginationType(''); updateLimitType(''); updateCustomLimit(''); setCurrentWorkflowActionsState({ hasScrapeListAction: false, hasScreenshotAction: false, hasScrapeSchemaAction: false }); setWorkflow(emptyWorkflow); resetInterpretationLog(); // Clear all browser steps browserSteps.forEach(step => { deleteBrowserStep(step.id); }); // Close the reset confirmation modal setOpenResetModal(false); // Notify user notify('info', t('browser_recording.notifications.environment_reset')); }; return (
{/* Reset Button */} {/* Discard Confirmation Modal */} setOpenDiscardModal(false)} modalStyle={modalStyle}> {t('browser_recording.modal.confirm_discard')} {/* Reset Confirmation Modal */} setOpenResetModal(false)} modalStyle={modalStyle}> {t('browser_recording.modal.confirm_reset')} {t('browser_recording.modal.reset_warning')}
); }; export default BrowserRecordingSave; const modalStyle = { top: '25%', left: '50%', transform: 'translate(-50%, -50%)', width: '30%', backgroundColor: 'background.paper', p: 4, height: 'fit-content', display: 'block', padding: '20px', };