SettingsDomain.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. handleCheckbox,
  80. }) => (
  81. <div>
  82. <h3>Custom domain</h3>
  83. <p>
  84. You can set a custom domain for your short URLs, so instead of <b>kutt.it/shorturl</b> you can
  85. have <b>example.com/shorturl.</b>
  86. </p>
  87. <p>
  88. Point your domain A record to <b>164.132.153.221</b> then add the domain via form below:
  89. </p>
  90. {settings.customDomain && !settings.domainInput ? (
  91. <div>
  92. <DomainWrapper>
  93. <Domain>
  94. <span>{settings.customDomain}</span>
  95. </Domain>
  96. <Homepage>
  97. (Homepage redirects to <span>{settings.homepage || window.location.hostname}</span>)
  98. </Homepage>
  99. </DomainWrapper>
  100. <ButtonWrapper>
  101. <Button icon="edit" onClick={showDomainInput}>
  102. Change
  103. </Button>
  104. <Button color="gray" icon="x" onClick={showModal}>
  105. Delete
  106. </Button>
  107. </ButtonWrapper>
  108. </div>
  109. ) : (
  110. <Form onSubmit={handleCustomDomain}>
  111. <Error type="domain" left={0} bottom={-54} />
  112. <InputWrapper>
  113. <LabelWrapper htmlFor="customdomain">
  114. <span>Domain</span>
  115. <TextInput
  116. id="customdomain"
  117. name="customdomain"
  118. type="text"
  119. placeholder="example.com"
  120. defaultValue={settings.customDomain}
  121. height={44}
  122. small
  123. />
  124. </LabelWrapper>
  125. <LabelWrapper>
  126. <span>Homepage (Optional)</span>
  127. <TextInput
  128. id="homepage"
  129. name="homepage"
  130. type="text"
  131. placeholder="Homepage URL"
  132. defaultValue={settings.homepage}
  133. height={44}
  134. small
  135. />
  136. </LabelWrapper>
  137. </InputWrapper>
  138. <Button type="submit" color="purple" icon={loading ? 'loader' : ''}>
  139. Set domain
  140. </Button>
  141. </Form>
  142. )}
  143. </div>
  144. );
  145. SettingsDomain.propTypes = {
  146. settings: PropTypes.shape({
  147. customDomain: PropTypes.string.isRequired,
  148. domainInput: PropTypes.bool.isRequired,
  149. }).isRequired,
  150. handleCustomDomain: PropTypes.func.isRequired,
  151. loading: PropTypes.bool.isRequired,
  152. showDomainInput: PropTypes.func.isRequired,
  153. showModal: PropTypes.func.isRequired,
  154. handleCheckbox: PropTypes.func.isRequired,
  155. };
  156. export default SettingsDomain;