ShortenerOptions.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import React, { FC, useState } from "react";
  2. import styled from "styled-components";
  3. import { Flex } from "reflexbox/styled-components";
  4. // import Checkbox from "../Checkbox";
  5. import TextInput from "../TextInput";
  6. import { fadeIn } from "../../helpers/animations";
  7. interface Props {
  8. isAuthenticated: boolean;
  9. domain: string;
  10. setShortenerFormError: any; // TODO: types
  11. }
  12. const Wrapper = styled(Flex).attrs({
  13. flexDirection: "column",
  14. alignSelf: "flex-start",
  15. justifyContent: "flex-start"
  16. })`
  17. position: absolute;
  18. top: 74px;
  19. left: 0;
  20. z-index: 2;
  21. @media only screen and (max-width: 448px) {
  22. width: 100%;
  23. top: 56px;
  24. }
  25. `;
  26. const InputWrapper = styled(Flex).attrs({
  27. flexDirection: ["column", "row"],
  28. alignItems: ["flex-start", "center"]
  29. })`
  30. @media only screen and (max-width: 448px) {
  31. > * {
  32. margin-bottom: 16px;
  33. }
  34. }
  35. `;
  36. const Label = styled.label`
  37. font-size: 18px;
  38. margin-right: 16px;
  39. animation: ${fadeIn} 0.5s ease-out;
  40. @media only screen and (max-width: 448px) {
  41. font-size: 14px;
  42. margin-right: 8px;
  43. }
  44. `;
  45. const ShortenerOptions: FC<Props> = props => {
  46. const [customurl, setCustomurl] = useState();
  47. const [password, setPassword] = useState();
  48. const checkAuth = () => {
  49. if (!props.isAuthenticated) {
  50. props.setShortenerFormError(
  51. "Please login or sign up to use this feature."
  52. );
  53. return false;
  54. }
  55. return true;
  56. };
  57. const handleCustomUrl = e => {
  58. if (!checkAuth()) return;
  59. setCustomurl(e.target.value);
  60. };
  61. const handlePassword = e => {
  62. if (!checkAuth()) return;
  63. setPassword(e.target.value);
  64. };
  65. const customUrlInput = customurl && (
  66. <div>
  67. <Label htmlFor="customurl">
  68. {props.domain || window.location.hostname}/
  69. </Label>
  70. <TextInput id="customurl" type="text" placeholder="custom name" small />
  71. </div>
  72. );
  73. const passwordInput = password && (
  74. <div>
  75. <Label htmlFor="customurl">password:</Label>
  76. <TextInput id="password" type="password" placeholder="password" small />
  77. </div>
  78. );
  79. return (
  80. <Wrapper>
  81. <Flex justifyContent={["center", "flex-start"]}>
  82. {/* <Checkbox
  83. id="customurlCheckbox"
  84. name="customurlCheckbox"
  85. label="Set custom URL"
  86. checked={customurl}
  87. onClick={handleCustomUrl}
  88. />
  89. <Checkbox
  90. id="passwordCheckbox"
  91. name="passwordCheckbox"
  92. label="Set password"
  93. checked={password}
  94. onClick={handlePassword}
  95. /> */}
  96. </Flex>
  97. <InputWrapper>
  98. {customUrlInput}
  99. {passwordInput}
  100. </InputWrapper>
  101. </Wrapper>
  102. );
  103. };
  104. // TODO: see if needed
  105. // shouldComponentUpdate(nextProps, nextState) {
  106. // const { customurlCheckbox, passwordCheckbox } = state;
  107. // return (
  108. // props.isAuthenticated !== nextProps.isAuthenticated ||
  109. // customurlCheckbox !== nextState.customurlCheckbox ||
  110. // props.domain !== nextProps.domain ||
  111. // passwordCheckbox !== nextState.passwordCheckbox
  112. // );
  113. // }
  114. export default ShortenerOptions;