AppWrapper.tsx 1.3 KB

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