StripeSyncSettingsPage.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { useParams } from 'common'
  2. import { formatRelative } from 'date-fns'
  3. import { BadgeCheck, RefreshCwIcon } from 'lucide-react'
  4. import Link from 'next/link'
  5. import { Button, Card, CardContent, CardHeader, CardTitle } from 'ui'
  6. import { Admonition, ShimmeringLoader, TimestampInfo } from 'ui-patterns'
  7. import {
  8. PageSection,
  9. PageSectionContent,
  10. PageSectionDescription,
  11. PageSectionMeta,
  12. PageSectionSummary,
  13. PageSectionTitle,
  14. } from 'ui-patterns/PageSection'
  15. import { isInstalled, isSyncRunning, isUninstalling } from './stripe-sync-status'
  16. import { ConstrainedIntegrationTabScaffold } from '@/components/interfaces/Integrations/ConstrainedIntegrationTabScaffold'
  17. import { useStripeSyncStatus } from '@/components/interfaces/Integrations/templates/StripeSyncEngine/useStripeSyncStatus'
  18. export const StripeSyncSettingsPage = () => {
  19. const { ref } = useParams()
  20. const {
  21. schemaComment: { status: installationStatus },
  22. syncState,
  23. } = useStripeSyncStatus()
  24. const installed = isInstalled(installationStatus)
  25. const isSyncing = isSyncRunning(syncState)
  26. const uninstalling = isUninstalling(installationStatus)
  27. if (!installed || uninstalling) {
  28. return (
  29. <ConstrainedIntegrationTabScaffold>
  30. <PageSection>
  31. <Admonition type="default" description="Stripe Sync Engine is not installed." />
  32. </PageSection>
  33. </ConstrainedIntegrationTabScaffold>
  34. )
  35. }
  36. return (
  37. <ConstrainedIntegrationTabScaffold>
  38. <PageSection className="py-0!">
  39. <PageSectionMeta>
  40. <PageSectionSummary>
  41. <PageSectionTitle>Manage Stripe data</PageSectionTitle>
  42. <PageSectionDescription>
  43. Access and manage the synced Stripe data in your database.
  44. </PageSectionDescription>
  45. </PageSectionSummary>
  46. </PageSectionMeta>
  47. <PageSectionContent>
  48. <Card>
  49. <CardHeader>
  50. <CardTitle className="text-foreground-lighter">
  51. {!syncState ? (
  52. <ShimmeringLoader className="py-2" />
  53. ) : (
  54. <div className="flex items-center justify-between gap-2">
  55. {isSyncing ? (
  56. <>
  57. <div className="flex items-center gap-x-3 text-foreground-light">
  58. <RefreshCwIcon size={14} className="animate-spin" />
  59. <p>Sync in progress</p>
  60. </div>
  61. {syncState.started_at && (
  62. <p className="text-foreground-light">
  63. Started{' '}
  64. <TimestampInfo
  65. utcTimestamp={syncState.started_at}
  66. label={
  67. syncState.started_at
  68. ? formatRelative(new Date(syncState.started_at), new Date())
  69. : 'recently'
  70. }
  71. />
  72. </p>
  73. )}
  74. </>
  75. ) : (
  76. <>
  77. <div className="flex items-center gap-x-3 text-foreground-light">
  78. <BadgeCheck size={14} />
  79. <p>All up to date</p>
  80. </div>
  81. {syncState.closed_at && (
  82. <p className="text-foreground-light">
  83. Last synced{' '}
  84. <TimestampInfo
  85. utcTimestamp={syncState.closed_at}
  86. label={
  87. syncState.closed_at
  88. ? formatRelative(new Date(syncState.closed_at), new Date())
  89. : 'recently'
  90. }
  91. />
  92. </p>
  93. )}
  94. </>
  95. )}
  96. </div>
  97. )}
  98. </CardTitle>
  99. </CardHeader>
  100. <CardContent className="@container">
  101. <div className="flex flex-col items-start justify-between gap-4 @md:flex-row @md:items-center">
  102. <div className="flex flex-col gap-1">
  103. <h5 className="text-sm">View Stripe data in Table Editor</h5>
  104. <p className="text-sm text-foreground-light text-balance">
  105. The Stripe Sync Engine stores all synced data in the{' '}
  106. <code className="text-code-inline break-keep!">stripe</code> schema. You can
  107. view and query this data directly in the Table Editor.
  108. </p>
  109. </div>
  110. <Button asChild type="default" className="ml-8 @md:ml-0">
  111. <Link href={`/project/${ref}/editor?schema=stripe`}>Open Table Editor</Link>
  112. </Button>
  113. </div>
  114. </CardContent>
  115. </Card>
  116. </PageSectionContent>
  117. </PageSection>
  118. </ConstrainedIntegrationTabScaffold>
  119. )
  120. }