apiTokenRow.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import Button from 'app/components/button';
  4. import DateTime from 'app/components/dateTime';
  5. import {PanelItem} from 'app/components/panels';
  6. import {IconSubtract} from 'app/icons';
  7. import {t} from 'app/locale';
  8. import space from 'app/styles/space';
  9. import {InternalAppApiToken} from 'app/types';
  10. import getDynamicText from 'app/utils/getDynamicText';
  11. import TextCopyInput from 'app/views/settings/components/forms/textCopyInput';
  12. type Props = {
  13. token: InternalAppApiToken;
  14. onRemove: (token: InternalAppApiToken) => void;
  15. };
  16. function ApiTokenRow({token, onRemove}: Props) {
  17. return (
  18. <StyledPanelItem>
  19. <Controls>
  20. <InputWrapper>
  21. <TextCopyInput>
  22. {getDynamicText({value: token.token, fixed: 'CI_AUTH_TOKEN'})}
  23. </TextCopyInput>
  24. </InputWrapper>
  25. <Button
  26. size="small"
  27. onClick={() => onRemove(token)}
  28. icon={<IconSubtract isCircled size="xs" />}
  29. >
  30. {t('Remove')}
  31. </Button>
  32. </Controls>
  33. <Details>
  34. <ScopesWrapper>
  35. <Heading>{t('Scopes')}</Heading>
  36. <ScopeList>{token.scopes.join(', ')}</ScopeList>
  37. </ScopesWrapper>
  38. <div>
  39. <Heading>{t('Created')}</Heading>
  40. <Time>
  41. <DateTime
  42. date={getDynamicText({
  43. value: token.dateCreated,
  44. fixed: new Date(1508208080000), //National Pasta Day
  45. })}
  46. />
  47. </Time>
  48. </div>
  49. </Details>
  50. </StyledPanelItem>
  51. );
  52. }
  53. const StyledPanelItem = styled(PanelItem)`
  54. flex-direction: column;
  55. padding: ${space(2)};
  56. `;
  57. const Controls = styled('div')`
  58. display: flex;
  59. align-items: center;
  60. margin-bottom: ${space(1)};
  61. `;
  62. const InputWrapper = styled('div')`
  63. font-size: ${p => p.theme.fontSizeRelativeSmall};
  64. flex: 1;
  65. margin-right: ${space(1)};
  66. `;
  67. const Details = styled('div')`
  68. display: flex;
  69. margin-top: ${space(1)};
  70. `;
  71. const ScopesWrapper = styled('div')`
  72. flex: 1;
  73. `;
  74. const ScopeList = styled('div')`
  75. font-size: ${p => p.theme.fontSizeRelativeSmall};
  76. line-height: 1.4;
  77. `;
  78. const Time = styled('time')`
  79. font-size: ${p => p.theme.fontSizeRelativeSmall};
  80. line-height: 1.4;
  81. `;
  82. const Heading = styled('div')`
  83. font-size: ${p => p.theme.fontSizeMedium};
  84. text-transform: uppercase;
  85. color: ${p => p.theme.subText};
  86. margin-bottom: ${space(1)};
  87. `;
  88. export default ApiTokenRow;