-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a586337
commit 7b0657a
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import client from "../client"; | ||
|
||
export interface getServerInfoResponse { | ||
datetime: string; | ||
} | ||
|
||
export async function getServerInfo(): Promise<getServerInfoResponse> { | ||
const response = await client.get<getServerInfoResponse>(`/api/info`); | ||
return response.data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/views/Login/components/TimeSynchronizationWarningDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
Stack, | ||
useTheme, | ||
} from "@mui/material"; | ||
import { FunctionComponent, useEffect, useState } from "react"; | ||
import { TbClockX } from "react-icons/tb"; | ||
import { isLocalTimeSynchronized } from "../../../utilities/time"; | ||
|
||
interface TimeSynchronizationWarningDialogProps {} | ||
|
||
const TimeSynchronizationWarningDialog: FunctionComponent< | ||
TimeSynchronizationWarningDialogProps | ||
> = () => { | ||
const theme = useTheme(); | ||
|
||
const [showTimeWarning, setShowTimeWarning] = useState(false); | ||
const [timeDifference, setTimeDifference] = useState<number | null>(null); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const [isSynchronized, difference] = await isLocalTimeSynchronized(); | ||
|
||
setTimeDifference(difference); | ||
setShowTimeWarning(!isSynchronized); | ||
})(); | ||
}, []); | ||
|
||
return ( | ||
<Dialog | ||
open={showTimeWarning} | ||
PaperProps={{ | ||
sx: { | ||
maxWidth: "400px", | ||
}, | ||
}} | ||
> | ||
<DialogContent> | ||
<Stack alignItems="center" textAlign="center" spacing={2}> | ||
<TbClockX size={96} color={theme.palette.error.dark} /> | ||
|
||
<p>Your local time is not synchronized with the server time.</p> | ||
|
||
<p> | ||
Your are {timeDifference && timeDifference > 0 ? "ahead" : "behind"}{" "} | ||
by {timeDifference} ms. | ||
</p> | ||
|
||
<p> | ||
Please make sure your system clock is synchronized to avoid any | ||
problems. | ||
</p> | ||
</Stack> | ||
</DialogContent> | ||
|
||
<DialogActions sx={{ justifyContent: "center" }}> | ||
<Button onClick={() => setShowTimeWarning(false)}>Dismiss</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default TimeSynchronizationWarningDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters