SettingsDomain.js 3.8 KB

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