ProductEmptyState.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { ExternalLink } from 'lucide-react'
  2. import Link from 'next/link'
  3. import { PropsWithChildren } from 'react'
  4. import { Button } from 'ui'
  5. import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
  6. interface ProductEmptyStateProps {
  7. title?: string
  8. size?: 'medium' | 'large'
  9. ctaButtonLabel?: string
  10. infoButtonLabel?: string
  11. infoButtonUrl?: string
  12. onClickCta?: () => void
  13. loading?: boolean
  14. disabled?: boolean
  15. disabledMessage?: string
  16. ctaUrl?: string
  17. }
  18. const ProductEmptyState = ({
  19. title = '',
  20. size = 'medium',
  21. children,
  22. ctaButtonLabel = '',
  23. infoButtonLabel = '',
  24. infoButtonUrl = '',
  25. onClickCta = () => {},
  26. loading = false,
  27. disabled = false,
  28. disabledMessage = '',
  29. ctaUrl,
  30. }: PropsWithChildren<ProductEmptyStateProps>) => {
  31. const hasAction = (ctaButtonLabel && onClickCta) || (infoButtonUrl && infoButtonLabel)
  32. return (
  33. <div className="flex h-full w-full items-center justify-center">
  34. <div className="flex space-x-4 rounded-sm border bg-surface-100 p-6 shadow-md">
  35. {/* A graphic can probably be placed here as a sibling to the div below*/}
  36. <div className="flex flex-col">
  37. <div className={`${size === 'medium' ? 'w-80' : 'w-[400px]'} space-y-4`}>
  38. <h5 className="text-foreground">{title}</h5>
  39. <div className="flex flex-col space-y-2 text-foreground-light">{children}</div>
  40. {hasAction && (
  41. <div className="flex items-center space-x-2">
  42. {ctaButtonLabel && !!ctaUrl ? (
  43. <Button asChild type="primary">
  44. <Link href={ctaUrl}>{ctaButtonLabel}</Link>
  45. </Button>
  46. ) : ctaButtonLabel && !!onClickCta ? (
  47. <ButtonTooltip
  48. type="primary"
  49. onClick={onClickCta}
  50. loading={loading}
  51. disabled={loading || disabled}
  52. tooltip={{
  53. content: {
  54. side: 'bottom',
  55. text: disabled && disabledMessage.length > 0 ? disabledMessage : undefined,
  56. },
  57. }}
  58. >
  59. {ctaButtonLabel}
  60. </ButtonTooltip>
  61. ) : null}
  62. {infoButtonUrl && infoButtonLabel ? (
  63. <Button type="default" icon={<ExternalLink strokeWidth={1.5} />}>
  64. <a target="_blank" rel="noreferrer" href={infoButtonUrl}>
  65. {infoButtonLabel}
  66. </a>
  67. </Button>
  68. ) : null}
  69. </div>
  70. )}
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. )
  76. }
  77. export default ProductEmptyState