SettingsApi.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import styled, { css } from 'styled-components';
  4. import { CopyToClipboard } from 'react-copy-to-clipboard';
  5. import Button from '../Button';
  6. import { fadeIn } from '../../helpers/animations';
  7. const Wrapper = styled.div`
  8. display: flex;
  9. flex-direction: column;
  10. align-items: flex-start;
  11. `;
  12. const ApiKeyWrapper = styled.div`
  13. position: relative;
  14. display: flex;
  15. align-items: center;
  16. margin: 16px 0;
  17. button {
  18. margin-right: 16px;
  19. }
  20. ${({ apikey }) =>
  21. apikey &&
  22. css`
  23. flex-direction: column;
  24. align-items: flex-start;
  25. > span {
  26. margin-bottom: 32px;
  27. }
  28. `};
  29. @media only screen and (max-width: 768px) {
  30. width: 100%;
  31. overflow-wrap: break-word;
  32. }
  33. `;
  34. const KeyWrapper = styled.div`
  35. max-width: 100%;
  36. display: flex;
  37. flex-wrap: wrap;
  38. align-items: center;
  39. margin-bottom: 16px;
  40. `;
  41. const ApiKey = styled.span`
  42. max-width: 100%;
  43. margin-right: 16px;
  44. font-size: 16px;
  45. font-weight: bold;
  46. border-bottom: 2px dotted #999;
  47. @media only screen and (max-width: 768px) {
  48. font-size: 14px;
  49. }
  50. @media only screen and (max-width: 520px) {
  51. margin-bottom: 16px;
  52. }
  53. `;
  54. const Link = styled.a`
  55. margin: 16px 0;
  56. @media only screen and (max-width: 768px) {
  57. margin: 8px 0;
  58. }
  59. `;
  60. const CopyMessage = styled.p`
  61. position: absolute;
  62. top: -42px;
  63. left: 0;
  64. font-size: 14px;
  65. color: #689f38;
  66. animation: ${fadeIn} 0.3s ease-out;
  67. `;
  68. const SettingsApi = ({ apikey, generateKey, loader, isCopied, onCopy }) => (
  69. <Wrapper>
  70. <h3>API</h3>
  71. <p>
  72. In additional to this website, you can use the API to create, delete and get shortend URLs. If
  73. {" you're"} not familiar with API, {"don't"} generate the key. DO NOT share this key on the
  74. client side of your website.
  75. </p>
  76. <ApiKeyWrapper apikey={apikey}>
  77. {isCopied && <CopyMessage>Copied to clipboard.</CopyMessage>}
  78. {apikey && (
  79. <KeyWrapper>
  80. <ApiKey>{apikey}</ApiKey>
  81. <CopyToClipboard text={apikey} onCopy={onCopy}>
  82. <Button icon="copy">Copy</Button>
  83. </CopyToClipboard>
  84. </KeyWrapper>
  85. )}
  86. <Button color="purple" icon={loader ? 'loader' : 'zap'} onClick={generateKey}>
  87. {apikey ? 'Regenerate' : 'Generate'} key
  88. </Button>
  89. </ApiKeyWrapper>
  90. <Link href="https://github.com/thedevs-network/kutt#api" title="API Docs" target="_blank">
  91. Read API docs
  92. </Link>
  93. </Wrapper>
  94. );
  95. SettingsApi.propTypes = {
  96. apikey: PropTypes.string.isRequired,
  97. loader: PropTypes.bool.isRequired,
  98. isCopied: PropTypes.bool.isRequired,
  99. generateKey: PropTypes.func.isRequired,
  100. onCopy: PropTypes.func.isRequired,
  101. };
  102. export default SettingsApi;