updateAlert.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {useContext} from 'react';
  2. import styled from '@emotion/styled';
  3. import Alert from 'sentry/components/alert';
  4. import AppStoreConnectContext from 'sentry/components/projects/appStoreConnectContext';
  5. import space from 'sentry/styles/space';
  6. import {Project} from 'sentry/types';
  7. type Props = {
  8. Wrapper?: React.ComponentType;
  9. className?: string;
  10. project?: Project;
  11. };
  12. function UpdateAlert({Wrapper, project, className}: Props) {
  13. const appStoreConnectContext = useContext(AppStoreConnectContext);
  14. if (
  15. !project ||
  16. !appStoreConnectContext ||
  17. !Object.keys(appStoreConnectContext).some(
  18. key => !!appStoreConnectContext[key].updateAlertMessage
  19. )
  20. ) {
  21. return null;
  22. }
  23. const notices = (
  24. <Notices className={className}>
  25. {Object.keys(appStoreConnectContext).map(key => {
  26. const {updateAlertMessage} = appStoreConnectContext[key];
  27. if (!updateAlertMessage) {
  28. return null;
  29. }
  30. return (
  31. <NoMarginBottomAlert key={key} type="warning" showIcon>
  32. <AlertContent>{updateAlertMessage}</AlertContent>
  33. </NoMarginBottomAlert>
  34. );
  35. })}
  36. </Notices>
  37. );
  38. return Wrapper ? <Wrapper>{notices}</Wrapper> : notices;
  39. }
  40. export default UpdateAlert;
  41. const Notices = styled('div')`
  42. display: grid;
  43. gap: ${space(2)};
  44. margin-bottom: ${space(3)};
  45. `;
  46. const NoMarginBottomAlert = styled(Alert)`
  47. margin-bottom: 0;
  48. `;
  49. const AlertContent = styled('div')`
  50. display: grid;
  51. grid-template-columns: 1fr max-content;
  52. gap: ${space(1)};
  53. `;