|
| 1 | +import { FC, useMemo } from 'react'; |
| 2 | +import { Box, Button, Flex, Text } from '@chakra-ui/react'; |
| 3 | +import { TonConsoleIcon } from 'src/shared/ui/icons/TonConsoleIcon'; |
| 4 | +import { H4 } from 'src/shared/ui/typography'; |
| 5 | +import { maintenanceConfig } from 'src/shared/config/maintenance'; |
| 6 | +import { useLogoutMutation } from 'src/entities/user/queries'; |
| 7 | + |
| 8 | +function formatEndTime(isoString: string): string { |
| 9 | + const date = new Date(isoString); |
| 10 | + |
| 11 | + const local = date.toLocaleString(undefined, { |
| 12 | + month: 'short', |
| 13 | + day: 'numeric', |
| 14 | + hour: '2-digit', |
| 15 | + minute: '2-digit' |
| 16 | + }); |
| 17 | + |
| 18 | + const utc = date.toLocaleString('en-GB', { |
| 19 | + month: 'short', |
| 20 | + day: 'numeric', |
| 21 | + hour: '2-digit', |
| 22 | + minute: '2-digit', |
| 23 | + timeZone: 'UTC' |
| 24 | + }); |
| 25 | + |
| 26 | + return `${local} (${utc} UTC)`; |
| 27 | +} |
| 28 | + |
| 29 | +export const MaintenancePage: FC = () => { |
| 30 | + const { mutate: logout, isPending: isLoggingOut } = useLogoutMutation(); |
| 31 | + |
| 32 | + const estimatedEnd = useMemo(() => { |
| 33 | + const { estimatedEndTime } = maintenanceConfig; |
| 34 | + if (!estimatedEndTime) { |
| 35 | + return null; |
| 36 | + } |
| 37 | + return formatEndTime(estimatedEndTime); |
| 38 | + }, []); |
| 39 | + |
| 40 | + return ( |
| 41 | + <Flex |
| 42 | + align="center" |
| 43 | + justify="center" |
| 44 | + direction="column" |
| 45 | + h="100vh" |
| 46 | + px={4} |
| 47 | + bgColor="background.page" |
| 48 | + > |
| 49 | + <Flex align="center" gap={2} mb={10}> |
| 50 | + <TonConsoleIcon w="40px" h="40px" /> |
| 51 | + <H4>Ton Console</H4> |
| 52 | + </Flex> |
| 53 | + |
| 54 | + <Box textStyle="h2" mb={4} color="text.primary"> |
| 55 | + Under Maintenance |
| 56 | + </Box> |
| 57 | + |
| 58 | + <Text sx={{ textWrap: 'balance' }} textStyle="body1" maxW="480px" mb={2} color="text.secondary" textAlign="center"> |
| 59 | + {maintenanceConfig.message ?? |
| 60 | + 'We are performing scheduled maintenance. The service will be back shortly.'} |
| 61 | + </Text> |
| 62 | + |
| 63 | + {estimatedEnd && ( |
| 64 | + <Text textStyle="body2" mb={8} color="text.tertiary"> |
| 65 | + Expected back by {estimatedEnd} |
| 66 | + </Text> |
| 67 | + )} |
| 68 | + |
| 69 | + {!estimatedEnd && <Box mb={8} />} |
| 70 | + |
| 71 | + <Button |
| 72 | + isLoading={isLoggingOut} |
| 73 | + onClick={() => logout()} |
| 74 | + size="sm" |
| 75 | + variant="outline" |
| 76 | + > |
| 77 | + Log out |
| 78 | + </Button> |
| 79 | + </Flex> |
| 80 | + ); |
| 81 | +}; |
0 commit comments