Skip to content

Commit

Permalink
Inclusão de timer para reload do Sistema
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed Jan 5, 2025
1 parent 8628a43 commit c058a86
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion frontend/src/pages/Connections/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,39 @@ const Connections = () => {
};

const restartpm2 = async () => {
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
let secondsRemaining = 15;

const countdownToastId = toast.info(`O sistema será reiniciado em ${secondsRemaining} segundos...`, {
autoClose: false,
});

const updateToast = () => {
toast.update(countdownToastId, {
render: `O sistema será reiniciado em ${secondsRemaining} segundos...`,
});
};

try {
await api.post('/restartpm2');

const intervalId = setInterval(() => {
secondsRemaining -= 1;
updateToast();

if (secondsRemaining <= 0) {
clearInterval(intervalId);
toast.dismiss(countdownToastId);
}
}, 1000);

await delay(secondsRemaining * 1000);
history.go(0);
} catch (err) {
toast.dismiss(countdownToastId);
toastError(err);
}
}
};

const formatPhoneNumber = (number) => {
if (number.startsWith('55') && number.length === 13) {
Expand Down

0 comments on commit c058a86

Please # to comment.