footerWithButtons.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. size: 'xs',
  24. disabled,
  25. onClick,
  26. children: buttonText,
  27. } satisfies Partial<ButtonProps>;
  28. const button =
  29. href !== undefined ? (
  30. <LinkButton href={href} {...buttonProps} />
  31. ) : (
  32. <Button type="submit" {...buttonProps} />
  33. );
  34. // We use a form post here to replicate what we do with standard HTML views
  35. // for the integration pipeline. Since this is a form post, we need to pass a
  36. // hidden replica of the form inputs so we can submit this form instead of
  37. // the one collecting the user inputs.
  38. return (
  39. <Footer data-test-id="aws-lambda-footer-form" {...formProps}>
  40. {formFields?.map(field => <input type="hidden" key={field.name} {...field} />)}
  41. {button}
  42. </Footer>
  43. );
  44. }
  45. // wrap in form so we can keep form submission behavior
  46. const Footer = styled('form')`
  47. width: 100%;
  48. position: fixed;
  49. display: flex;
  50. justify-content: flex-end;
  51. bottom: 0;
  52. z-index: 100;
  53. background-color: ${p => p.theme.bodyBackground};
  54. border-top: 1px solid ${p => p.theme.innerBorder};
  55. padding: ${space(2)};
  56. `;