SettingsDomain.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. margin: 32px 0;
  12. animation: ${fadeIn} 0.8s ease;
  13. input {
  14. flex: 0 0 auto;
  15. margin-right: 16px;
  16. }
  17. @media only screen and (max-width: 768px) {
  18. margin: 16px 0;
  19. }
  20. `;
  21. const DomainWrapper = styled.div`
  22. display: flex;
  23. align-items: center;
  24. margin: 32px 0;
  25. animation: ${fadeIn} 0.8s ease;
  26. button {
  27. margin-right: 16px;
  28. }
  29. @media only screen and (max-width: 768px) {
  30. flex-direction: column;
  31. align-items: flex-start;
  32. > * {
  33. margin: 8px 0;
  34. }
  35. }
  36. `;
  37. const Domain = styled.span`
  38. margin-right: 16px;
  39. font-size: 20px;
  40. font-weight: bold;
  41. border-bottom: 2px dotted #999;
  42. `;
  43. const SettingsDomain = ({ settings, handleCustomDomain, loading, showDomainInput, showModal }) => (
  44. <div>
  45. <h3>Custom domain</h3>
  46. <p>
  47. You can set a custom domain for your short URLs, so instead of <b>kutt.it/shorturl</b> you can
  48. have <b>example.com/shorturl.</b>
  49. </p>
  50. <p>
  51. Point your domain A record to <b>164.132.153.221</b> then add the domain via form below:
  52. </p>
  53. {settings.customDomain && !settings.domainInput ? (
  54. <DomainWrapper>
  55. <Domain>{settings.customDomain}</Domain>
  56. <Button icon="edit" onClick={showDomainInput}>
  57. Change
  58. </Button>
  59. <Button color="gray" icon="x" onClick={showModal}>
  60. Delete
  61. </Button>
  62. </DomainWrapper>
  63. ) : (
  64. <Form onSubmit={handleCustomDomain}>
  65. <Error type="domain" left={0} bottom={-48} />
  66. <TextInput
  67. id="customdomain"
  68. name="customdomain"
  69. type="text"
  70. placeholder="example.com"
  71. defaultValue={settings.customDomain}
  72. height={44}
  73. small
  74. />
  75. <Button type="submit" color="purple" icon={loading ? 'loader' : ''}>
  76. Set domain
  77. </Button>
  78. </Form>
  79. )}
  80. </div>
  81. );
  82. SettingsDomain.propTypes = {
  83. settings: PropTypes.shape({
  84. customDomain: PropTypes.string.isRequired,
  85. domainInput: PropTypes.bool.isRequired,
  86. }).isRequired,
  87. handleCustomDomain: PropTypes.func.isRequired,
  88. loading: PropTypes.bool.isRequired,
  89. showDomainInput: PropTypes.func.isRequired,
  90. showModal: PropTypes.func.isRequired,
  91. };
  92. export default SettingsDomain;