footerWithButtons.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import styled from '@emotion/styled';
  2. import type {ButtonProps} from 'sentry/components/button';
  3. import {Button, LinkButton} from 'sentry/components/button';
  4. import {space} from 'sentry/styles/space';
  5. interface FooterWithButtonsProps {
  6. buttonText: string;
  7. disabled?: boolean;
  8. formFields?: Array<{name: string; value: any}>;
  9. formProps?: React.FormHTMLAttributes<HTMLFormElement>;
  10. href?: string;
  11. onClick?: ButtonProps['onClick'];
  12. }
  13. export default function FooterWithButtons({
  14. buttonText,
  15. disabled,
  16. formFields,
  17. formProps,
  18. href,
  19. onClick,
  20. }: FooterWithButtonsProps) {
  21. const buttonProps = {
  22. priority: 'primary',
  23. disabled,
  24. onClick,
  25. children: buttonText,
  26. } satisfies Partial<ButtonProps>;
  27. const button =
  28. href !== undefined ? (
  29. <LinkButton href={href} {...buttonProps} />
  30. ) : (
  31. <Button type="submit" {...buttonProps} />
  32. );
  33. // We use a form post here to replicate what we do with standard HTML views
  34. // for the integration pipeline. Since this is a form post, we need to pass a
  35. // hidden replica of the form inputs so we can submit this form instead of
  36. // the one collecting the user inputs.
  37. return (
  38. <Footer data-test-id="aws-lambda-footer-form" {...formProps}>
  39. {formFields?.map(field => <input type="hidden" key={field.name} {...field} />)}
  40. {button}
  41. </Footer>
  42. );
  43. }
  44. // wrap in form so we can keep form submission behavior
  45. const Footer = styled('form')`
  46. width: 100%;
  47. position: fixed;
  48. display: flex;
  49. justify-content: flex-end;
  50. bottom: 0;
  51. z-index: 100;
  52. background-color: ${p => p.theme.bodyBackground};
  53. border-top: 1px solid ${p => p.theme.innerBorder};
  54. padding: ${space(2)};
  55. `;