Merge pull request #427 from getmaxun/rm-reload

feat: prevent hard reload on robot edit and duplication
This commit is contained in:
Karishma Shukla
2025-02-01 15:52:07 +05:30
committed by GitHub
5 changed files with 64 additions and 13 deletions

View File

@@ -168,6 +168,8 @@ export const RecordingsTable = ({
setRecordingUrl,
isLogin,
setIsLogin,
rerenderRobots,
setRerenderRobots,
recordingName,
setRecordingName,
recordingId,
@@ -261,6 +263,14 @@ export const RecordingsTable = ({
}
}, [fetchRecordings]);
useEffect(() => {
if (rerenderRobots) {
fetchRecordings().then(() => {
setRerenderRobots(false);
});
}
}, [rerenderRobots, fetchRecordings, setRerenderRobots]);
function useDebounce<T>(value: T, delay: number): T {
const [debouncedValue, setDebouncedValue] = React.useState<T>(value);

View File

@@ -55,9 +55,9 @@ interface RobotSettingsProps {
export const RobotDuplicationModal = ({ isOpen, handleStart, handleClose, initialSettings }: RobotSettingsProps) => {
const { t } = useTranslation();
const [robot, setRobot] = useState<RobotSettings | null>(null);
const [targetUrl, setTargetUrl] = useState<string | undefined>('');
const { recordingId, notify } = useGlobalInfoStore();
const [robot, setRobot] = useState<RobotSettings | null>(null);
const { recordingId, notify, setRerenderRobots } = useGlobalInfoStore();
useEffect(() => {
if (isOpen) {
@@ -96,13 +96,11 @@ export const RobotDuplicationModal = ({ isOpen, handleStart, handleClose, initia
const success = await duplicateRecording(robot.recording_meta.id, targetUrl);
if (success) {
setRerenderRobots(true);
notify('success', t('robot_duplication.notifications.duplicate_success'));
handleStart(robot);
handleClose();
setTimeout(() => {
window.location.reload();
}, 1000);
} else {
notify('error', t('robot_duplication.notifications.duplicate_error'));
}

View File

@@ -7,6 +7,7 @@ import { modalStyle } from "../recorder/AddWhereCondModal";
import { useGlobalInfoStore } from '../../context/globalInfo';
import { getStoredRecording, updateRecording } from '../../api/storage';
import { WhereWhatPair } from 'maxun-core';
import { useNavigate } from 'react-router-dom';
interface RobotMeta {
name: string;
@@ -75,9 +76,9 @@ interface GroupedCredentials {
export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettings }: RobotSettingsProps) => {
const { t } = useTranslation();
const [robot, setRobot] = useState<RobotSettings | null>(null);
const [credentials, setCredentials] = useState<Credentials>({});
const { recordingId, notify } = useGlobalInfoStore();
const { recordingId, notify, setRerenderRobots } = useGlobalInfoStore();
const [robot, setRobot] = useState<RobotSettings | null>(null);
const [credentialGroups, setCredentialGroups] = useState<GroupedCredentials>({
passwords: [],
emails: [],
@@ -366,13 +367,11 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
const success = await updateRecording(robot.recording_meta.id, payload);
if (success) {
setRerenderRobots(true);
notify('success', t('robot_edit.notifications.update_success'));
handleStart(robot);
handleClose();
setTimeout(() => {
window.location.reload();
}, 1000);
} else {
notify('error', t('robot_edit.notifications.update_failed'));
}

View File

@@ -54,8 +54,8 @@ interface RobotSettingsProps {
export const RobotSettingsModal = ({ isOpen, handleStart, handleClose, initialSettings }: RobotSettingsProps) => {
const { t } = useTranslation();
const [robot, setRobot] = useState<RobotSettings | null>(null);
const [userEmail, setUserEmail] = useState<string | null>(null);
const [robot, setRobot] = useState<RobotSettings | null>(null);
const { recordingId, notify } = useGlobalInfoStore();
useEffect(() => {