LicenseTokenUpload.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { css } from '@emotion/css';
  2. import React, { FormEvent } from 'react';
  3. import { Button, FileUpload, stylesFactory } from '@grafana/ui';
  4. interface Props {
  5. isUploading: boolean;
  6. title?: string;
  7. onFileUpload: (event: FormEvent<HTMLInputElement>) => void;
  8. isDisabled?: boolean;
  9. licensedUrl?: string;
  10. }
  11. export const LicenseTokenUpload = ({ isUploading, title, onFileUpload, isDisabled, licensedUrl }: Props) => {
  12. const styles = getStyles();
  13. return (
  14. <>
  15. {title && <h2 className={styles.title}>{title}</h2>}
  16. {isUploading ? (
  17. <Button disabled={true}>Uploading…</Button>
  18. ) : isDisabled ? (
  19. <Button disabled={true}>Upload a new token</Button>
  20. ) : (
  21. <FileUpload onFileUpload={onFileUpload} accept=".jwt">
  22. Upload a new token
  23. </FileUpload>
  24. )}
  25. {licensedUrl && (
  26. <p className={styles.instanceUrl}>
  27. Instance URL: <code>{licensedUrl}</code>
  28. </p>
  29. )}
  30. </>
  31. );
  32. };
  33. const getStyles = stylesFactory(() => {
  34. return {
  35. title: css`
  36. margin-top: 30px;
  37. margin-bottom: 20px;
  38. `,
  39. instanceUrl: css`
  40. margin-top: 10px;
  41. `,
  42. };
  43. });