SettingsBan.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 Checkbox from '../Checkbox';
  7. const Form = styled.form`
  8. position: relative;
  9. display: flex;
  10. flex-direction: column;
  11. margin: 32px 0;
  12. input {
  13. flex: 0 0 auto;
  14. margin-right: 16px;
  15. }
  16. `;
  17. const InputWrapper = styled.div`
  18. display: flex;
  19. `;
  20. const Message = styled.div`
  21. position: absolute;
  22. left: 0;
  23. bottom: -32px;
  24. color: green;
  25. `;
  26. const Error = styled.div`
  27. position: absolute;
  28. left: 0;
  29. bottom: -32px;
  30. color: red;
  31. `;
  32. const SettingsBan = props => (
  33. <div>
  34. <h3>Ban link</h3>
  35. <Form onSubmit={props.onSubmitBan}>
  36. <InputWrapper>
  37. <Message>{props.message}</Message>
  38. <TextInput
  39. id="id"
  40. name="id"
  41. type="text"
  42. placeholder="Link ID (e.g. K7b2A)"
  43. height={44}
  44. small
  45. />
  46. <Button type="submit" icon={props.loading ? 'loader' : 'lock'} disabled={props.loading}>
  47. {props.loading ? 'Baning...' : 'Ban'}
  48. </Button>
  49. </InputWrapper>
  50. <div>
  51. <Checkbox
  52. id="user"
  53. name="user"
  54. label="Ban user (and all of their links)"
  55. withMargin={false}
  56. checked={props.user}
  57. onClick={props.onChangeBanCheckboxes('user')}
  58. />
  59. <Checkbox
  60. id="domain"
  61. name="domain"
  62. label="Ban domain"
  63. withMargin={false}
  64. checked={props.domain}
  65. onClick={props.onChangeBanCheckboxes('domain')}
  66. />
  67. <Checkbox
  68. id="host"
  69. name="host"
  70. label="Ban Host/IP"
  71. withMargin={false}
  72. checked={props.host}
  73. onClick={props.onChangeBanCheckboxes('host')}
  74. />
  75. </div>
  76. <Error>{props.error}</Error>
  77. </Form>
  78. </div>
  79. );
  80. SettingsBan.propTypes = {
  81. domain: PropTypes.bool.isRequired,
  82. error: PropTypes.string.isRequired,
  83. host: PropTypes.bool.isRequired,
  84. loading: PropTypes.bool.isRequired,
  85. message: PropTypes.string.isRequired,
  86. onChangeBanCheckboxes: PropTypes.func.isRequired,
  87. onSubmitBan: PropTypes.func.isRequired,
  88. user: PropTypes.bool.isRequired,
  89. };
  90. export default SettingsBan;