SettingsDomain.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import styled from 'styled-components';
  4. import TextInput from '../TextInput';
  5. import Checkbox from '../Checkbox';
  6. import Button from '../Button';
  7. import Error from '../Error';
  8. import { fadeIn } from '../../helpers/animations';
  9. const Form = styled.form`
  10. position: relative;
  11. display: flex;
  12. flex-direction: column;
  13. align-items: flex-start;
  14. justify-content: flex-start;
  15. margin: 32px 0;
  16. animation: ${fadeIn} 0.8s ease;
  17. input {
  18. flex: 0 0 auto;
  19. margin-right: 16px;
  20. }
  21. @media only screen and (max-width: 768px) {
  22. margin: 16px 0;
  23. }
  24. `;
  25. const DomainWrapper = styled.div`
  26. display: flex;
  27. align-items: center;
  28. `;
  29. const ButtonWrapper = styled.div`
  30. display: flex;
  31. align-items: center;
  32. margin: 32px 0;
  33. animation: ${fadeIn} 0.8s ease;
  34. button {
  35. margin-right: 16px;
  36. }
  37. @media only screen and (max-width: 768px) {
  38. flex-direction: column;
  39. align-items: flex-start;
  40. > * {
  41. margin: 8px 0;
  42. }
  43. }
  44. `;
  45. const Domain = styled.h4`
  46. margin: 0 16px 0 0;
  47. font-size: 20px;
  48. font-weight: bold;
  49. span {
  50. border-bottom: 2px dotted #999;
  51. }
  52. `;
  53. const Homepage = styled.h6`
  54. margin: 0 16px 0 0;
  55. font-size: 14px;
  56. font-weight: 300;
  57. span {
  58. border-bottom: 2px dotted #999;
  59. }
  60. `;
  61. const InputWrapper = styled.div`
  62. display: flex;
  63. align-items: center;
  64. `;
  65. const LabelWrapper = styled.div`
  66. display: flex;
  67. flex-direction: column;
  68. span {
  69. font-weight: bold;
  70. margin-bottom: 8px;
  71. }
  72. `;
  73. const SettingsDomain = ({
  74. settings,
  75. handleCustomDomain,
  76. loading,
  77. showDomainInput,
  78. showModal,
  79. useHttps,
  80. handleCheckbox,
  81. }) => (
  82. <div>
  83. <h3>Custom domain</h3>
  84. <p>
  85. You can set a custom domain for your short URLs, so instead of <b>kutt.it/shorturl</b> you can
  86. have <b>example.com/shorturl.</b>
  87. </p>
  88. <p>
  89. Point your domain A record to <b>164.132.153.221</b> then add the domain via form below:
  90. </p>
  91. {settings.customDomain && !settings.domainInput ? (
  92. <div>
  93. <DomainWrapper>
  94. <Domain>
  95. <span>{settings.customDomain}</span>
  96. </Domain>
  97. {settings.useHttps && <Homepage>(With HTTPS)</Homepage>}
  98. <Homepage>
  99. (Homepage redirects to <span>{settings.homepage || window.location.hostname}</span>)
  100. </Homepage>
  101. </DomainWrapper>
  102. <ButtonWrapper>
  103. <Button icon="edit" onClick={showDomainInput}>
  104. Change
  105. </Button>
  106. <Button color="gray" icon="x" onClick={showModal}>
  107. Delete
  108. </Button>
  109. </ButtonWrapper>
  110. </div>
  111. ) : (
  112. <Form onSubmit={handleCustomDomain}>
  113. <Error type="domain" left={0} bottom={-54} />
  114. <InputWrapper>
  115. <LabelWrapper htmlFor="customdomain">
  116. <span>Domain</span>
  117. <TextInput
  118. id="customdomain"
  119. name="customdomain"
  120. type="text"
  121. placeholder="example.com"
  122. defaultValue={settings.customDomain}
  123. height={44}
  124. small
  125. />
  126. </LabelWrapper>
  127. <LabelWrapper>
  128. <span>Homepage (Optional)</span>
  129. <TextInput
  130. id="homepage"
  131. name="homepage"
  132. type="text"
  133. placeholder="Homepage URL"
  134. defaultValue={settings.homepage}
  135. height={44}
  136. small
  137. />
  138. </LabelWrapper>
  139. </InputWrapper>
  140. <Checkbox
  141. checked={useHttps === null ? settings.useHttps : useHttps}
  142. id="useHttps"
  143. name="useHttps"
  144. onClick={handleCheckbox}
  145. withMargin={false}
  146. label="Use HTTPS (We don't handle the SSL, you should take care of it)"
  147. />
  148. <Button type="submit" color="purple" icon={loading ? 'loader' : ''}>
  149. Set domain
  150. </Button>
  151. </Form>
  152. )}
  153. </div>
  154. );
  155. SettingsDomain.propTypes = {
  156. settings: PropTypes.shape({
  157. customDomain: PropTypes.string.isRequired,
  158. domainInput: PropTypes.bool.isRequired,
  159. }).isRequired,
  160. handleCustomDomain: PropTypes.func.isRequired,
  161. loading: PropTypes.bool.isRequired,
  162. showDomainInput: PropTypes.func.isRequired,
  163. showModal: PropTypes.func.isRequired,
  164. handleCheckbox: PropTypes.func.isRequired,
  165. useHttps: PropTypes.bool.isRequired,
  166. };
  167. export default SettingsDomain;