AppWrapper.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { Flex } from "rebass/styled-components";
  2. import React, { useEffect } from "react";
  3. import styled from "styled-components";
  4. import { useStoreState, useStoreActions } from "../store";
  5. import PageLoading from "./PageLoading";
  6. import Header from "./Header";
  7. const Wrapper = styled(Flex)`
  8. input {
  9. filter: none;
  10. }
  11. * {
  12. box-sizing: border-box;
  13. }
  14. *::-moz-focus-inner {
  15. border: none;
  16. }
  17. `;
  18. const AppWrapper = ({ children }: { children: any }) => {
  19. const isAuthenticated = useStoreState((s) => s.auth.isAuthenticated);
  20. const logout = useStoreActions((s) => s.auth.logout);
  21. const fetched = useStoreState((s) => s.settings.fetched);
  22. const loading = useStoreState((s) => s.loading.loading);
  23. const getSettings = useStoreActions((s) => s.settings.getSettings);
  24. const isVerifyEmailPage =
  25. typeof window !== "undefined" &&
  26. window.location.pathname.includes("verify-email");
  27. useEffect(() => {
  28. if (isAuthenticated && !fetched && !isVerifyEmailPage) {
  29. getSettings().catch(() => logout());
  30. }
  31. }, [isAuthenticated, fetched, isVerifyEmailPage, getSettings, logout]);
  32. return (
  33. <Wrapper
  34. minHeight="100vh"
  35. width={1}
  36. flex="0 0 auto"
  37. alignItems="center"
  38. flexDirection="column"
  39. >
  40. <Header />
  41. {loading ? <PageLoading /> : children}
  42. </Wrapper>
  43. );
  44. };
  45. export default AppWrapper;