|
| 1 | +import Image from "next/image"; |
| 2 | +import { useState, useEffect } from "react"; |
| 3 | +import { FaArrowRightLong, FaClock } from "react-icons/fa6"; |
| 4 | +import { |
| 5 | + Button, |
| 6 | + Box, |
| 7 | + Text, |
| 8 | + VStack, |
| 9 | + HStack, |
| 10 | + Container, |
| 11 | + Flex, |
| 12 | + ChakraProvider, |
| 13 | + useColorModeValue, |
| 14 | +} from "@chakra-ui/react"; |
| 15 | + |
| 16 | +// Get the redirect URL from environment variables with a fallback |
| 17 | +const REDIRECT_URL = |
| 18 | + process.env.NEXT_PUBLIC_REDIRECT_URL ?? "https://docs.hyperweb.io"; |
| 19 | + |
| 20 | +export function RedirectSplashPage({ |
| 21 | + fallbackChildran, |
| 22 | +}: { |
| 23 | + fallbackChildran: React.ReactNode; |
| 24 | +}) { |
| 25 | + const [countdown, setCountdown] = useState(30); |
| 26 | + const [isCancelled, setIsCancelled] = useState(false); |
| 27 | + |
| 28 | + // Color mode values |
| 29 | + const bgColor = useColorModeValue("white", "gray.800"); |
| 30 | + const borderColor = useColorModeValue("gray.200", "gray.700"); |
| 31 | + const textColor = useColorModeValue("gray.600", "gray.400"); |
| 32 | + const accentColor = useColorModeValue("#0066CC", "#3B82F6"); |
| 33 | + const arrowColor = useColorModeValue("gray.700", "gray.400"); |
| 34 | + |
| 35 | + const redirectToSite = () => { |
| 36 | + window.location.href = REDIRECT_URL; |
| 37 | + }; |
| 38 | + |
| 39 | + useEffect(() => { |
| 40 | + if (isCancelled) return; |
| 41 | + |
| 42 | + const timer = setInterval(() => { |
| 43 | + setCountdown((prev) => { |
| 44 | + if (prev <= 1) { |
| 45 | + clearInterval(timer); |
| 46 | + redirectToSite(); |
| 47 | + return 1; |
| 48 | + } |
| 49 | + return prev - 1; |
| 50 | + }); |
| 51 | + }, 1000); |
| 52 | + return () => clearInterval(timer); |
| 53 | + }, [isCancelled]); |
| 54 | + |
| 55 | + const handleCancel = () => { |
| 56 | + setIsCancelled(true); |
| 57 | + setCountdown(0); |
| 58 | + }; |
| 59 | + |
| 60 | + if (isCancelled) { |
| 61 | + return fallbackChildran; |
| 62 | + } |
| 63 | + |
| 64 | + return ( |
| 65 | + <ChakraProvider> |
| 66 | + <Flex |
| 67 | + w="100%" |
| 68 | + h="50vh" |
| 69 | + align="center" |
| 70 | + justify="center" |
| 71 | + bg={bgColor} |
| 72 | + my={18} |
| 73 | + > |
| 74 | + <Container |
| 75 | + maxW="600px" |
| 76 | + py={12} |
| 77 | + px={8} |
| 78 | + display="flex" |
| 79 | + flexDirection="column" |
| 80 | + alignItems="center" |
| 81 | + bg={bgColor} |
| 82 | + boxShadow="lg" |
| 83 | + borderRadius="lg" |
| 84 | + borderWidth="1px" |
| 85 | + borderColor={borderColor} |
| 86 | + > |
| 87 | + <HStack spacing={6} pb={10}> |
| 88 | + <Image |
| 89 | + src="/brand/cosmology-darker.svg" |
| 90 | + alt="Cosmology" |
| 91 | + height={0} |
| 92 | + width={0} |
| 93 | + style={{ width: "45px", height: "45px" }} |
| 94 | + /> |
| 95 | + <Box color={arrowColor}> |
| 96 | + <FaArrowRightLong size={24} /> |
| 97 | + </Box> |
| 98 | + <Image |
| 99 | + src="/brand/hyperweb.svg" |
| 100 | + alt="Hyperweb" |
| 101 | + height={0} |
| 102 | + width={0} |
| 103 | + style={{ width: "45px", height: "45px" }} |
| 104 | + /> |
| 105 | + </HStack> |
| 106 | + |
| 107 | + <Text |
| 108 | + fontSize={{ base: "2xl", md: "3xl" }} |
| 109 | + fontWeight="semibold" |
| 110 | + textAlign="center" |
| 111 | + mb={2} |
| 112 | + > |
| 113 | + Hyperweb Docs is the new home for Cosmology Zone Docs. |
| 114 | + </Text> |
| 115 | + |
| 116 | + <Text color={textColor} maxW="440px" fontSize="md" textAlign="center"> |
| 117 | + Check out our new docs over at Hyperweb for existing products' docs |
| 118 | + and much more. |
| 119 | + </Text> |
| 120 | + |
| 121 | + <HStack spacing={6} mt={10} mb={8}> |
| 122 | + <Box color={accentColor}> |
| 123 | + <FaClock size={16} /> |
| 124 | + </Box> |
| 125 | + <Text fontSize="md" fontWeight="medium" color={accentColor}> |
| 126 | + Redirecting to Hyperweb Docs in{" "} |
| 127 | + <Text as="span" fontSize="lg" fontWeight="semibold"> |
| 128 | + {countdown} |
| 129 | + </Text>{" "} |
| 130 | + second{countdown === 1 ? "" : "s"}... |
| 131 | + </Text> |
| 132 | + </HStack> |
| 133 | + |
| 134 | + <Box px={10} w="full"> |
| 135 | + <HStack spacing={4}> |
| 136 | + <Button |
| 137 | + size="sm" |
| 138 | + variant="outline" |
| 139 | + onClick={handleCancel} |
| 140 | + w="full" |
| 141 | + borderColor={accentColor} |
| 142 | + color={accentColor} |
| 143 | + > |
| 144 | + Stay here |
| 145 | + </Button> |
| 146 | + <Button |
| 147 | + size="sm" |
| 148 | + bg={accentColor} |
| 149 | + color="white" |
| 150 | + onClick={redirectToSite} |
| 151 | + w="full" |
| 152 | + _hover={{ |
| 153 | + bg: useColorModeValue("#0052A3", "#2563EB"), |
| 154 | + }} |
| 155 | + > |
| 156 | + Redirect now |
| 157 | + </Button> |
| 158 | + </HStack> |
| 159 | + </Box> |
| 160 | + </Container> |
| 161 | + </Flex> |
| 162 | + </ChakraProvider> |
| 163 | + ); |
| 164 | +} |
0 commit comments