ソースを参照

fix(dashboard): refresh page when update is successful

Nicolas Meienberger 2 年 前
コミット
69ed0fd028

+ 6 - 1
packages/dashboard/src/components/StatusScreens/StatusWrapper.tsx

@@ -16,6 +16,11 @@ const StatusWrapper: React.FC<IProps> = ({ children }) => {
   const { data } = useSWR('/api/status', fetcher, { refreshInterval: 1000 });
 
   useEffect(() => {
+    // If previous was not running and current is running, we need to refresh the page
+    if (data?.status === SystemStatus.RUNNING && s !== SystemStatus.RUNNING) {
+      window.location.reload();
+    }
+
     if (data?.status === SystemStatus.RUNNING) {
       setS(SystemStatus.RUNNING);
     }
@@ -25,7 +30,7 @@ const StatusWrapper: React.FC<IProps> = ({ children }) => {
     if (data?.status === SystemStatus.UPDATING) {
       setS(SystemStatus.UPDATING);
     }
-  }, [data?.status]);
+  }, [data?.status, s]);
 
   if (s === SystemStatus.RESTARTING) {
     return (

+ 7 - 4
packages/dashboard/src/pages/settings.tsx

@@ -1,10 +1,12 @@
 import type { NextPage } from 'next';
 import { AlertDialog, AlertDialogBody, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, Button, Text, useDisclosure, useToast } from '@chakra-ui/react';
 import Layout from '../components/Layout';
-import { useLogoutMutation, useRestartMutation, useUpdateMutation, useVersionQuery } from '../generated/graphql';
+import { useRestartMutation, useUpdateMutation, useVersionQuery } from '../generated/graphql';
 import { useRef, useState } from 'react';
 import semver from 'semver';
 
+const wait = (time: number) => new Promise((resolve) => setTimeout(resolve, time));
+
 const Settings: NextPage = () => {
   const toast = useToast();
   const restartDisclosure = useDisclosure();
@@ -15,7 +17,6 @@ const Settings: NextPage = () => {
 
   const [restart] = useRestartMutation();
   const [update] = useUpdateMutation();
-  const [logout] = useLogoutMutation({ refetchQueries: ['Me'] });
 
   const defaultVersion = '0.0.0';
   const isLatest = semver.gte(data?.version.current || defaultVersion, data?.version.latest || defaultVersion);
@@ -55,7 +56,8 @@ const Settings: NextPage = () => {
     setLoading(true);
     try {
       restart();
-      logout();
+      await wait(1000);
+      localStorage.removeItem('token');
     } catch (error) {
       handleError(error);
     } finally {
@@ -67,7 +69,8 @@ const Settings: NextPage = () => {
     setLoading(true);
     try {
       update();
-      logout();
+      await wait(1000);
+      localStorage.removeItem('token');
     } catch (error) {
       handleError(error);
     } finally {