StatusDisplay.tsx81 lines · main
| 1 | import { AlertCircle, Check, RefreshCwIcon } from 'lucide-react' |
| 2 | import { SchemaInstallationStatus } from 'stripe-experiment-sync/supabase' |
| 3 | |
| 4 | import { |
| 5 | hasInstallError, |
| 6 | hasUninstallError, |
| 7 | isInstalled, |
| 8 | isInstalling, |
| 9 | isUninstalling, |
| 10 | } from './stripe-sync-status' |
| 11 | |
| 12 | export const StatusDisplay = ({ |
| 13 | status, |
| 14 | isInstallRequested, |
| 15 | isInstallInitiated, |
| 16 | isUninstallRequested, |
| 17 | isUninstallInitiated, |
| 18 | isUpgrade, |
| 19 | timedOut, |
| 20 | }: { |
| 21 | status: SchemaInstallationStatus |
| 22 | isInstallRequested: boolean |
| 23 | isInstallInitiated: boolean |
| 24 | isUninstallRequested: boolean |
| 25 | isUninstallInitiated: boolean |
| 26 | isUpgrade?: boolean |
| 27 | timedOut: boolean |
| 28 | }) => { |
| 29 | const installed = isInstalled(status) |
| 30 | const installError = hasInstallError(status) |
| 31 | const uninstallError = hasUninstallError(status) |
| 32 | const installInProgress = isInstalling(status) |
| 33 | const uninstallInProgress = isUninstalling(status) |
| 34 | |
| 35 | const installing = (installInProgress || isInstallRequested || isInstallInitiated) && !timedOut |
| 36 | const uninstalling = |
| 37 | (uninstallInProgress || isUninstallRequested || isUninstallInitiated) && !timedOut |
| 38 | |
| 39 | if (uninstalling) { |
| 40 | return ( |
| 41 | <span className="flex items-center gap-2 text-foreground-light text-sm"> |
| 42 | <RefreshCwIcon size={14} className="animate-spin text-foreground-lighter" /> |
| 43 | Uninstalling... |
| 44 | </span> |
| 45 | ) |
| 46 | } |
| 47 | if (uninstallError) { |
| 48 | return ( |
| 49 | <span className="flex items-center gap-2 text-foreground-light text-sm"> |
| 50 | <AlertCircle size={14} className="text-destructive" /> |
| 51 | Uninstallation error |
| 52 | </span> |
| 53 | ) |
| 54 | } |
| 55 | if (installing) { |
| 56 | return ( |
| 57 | <span className="flex items-center gap-2 text-foreground-light text-sm"> |
| 58 | <RefreshCwIcon size={14} className="animate-spin text-foreground-lighter" /> |
| 59 | {isUpgrade ? 'Upgrading...' : 'Installing...'} |
| 60 | </span> |
| 61 | ) |
| 62 | } |
| 63 | if (installError) { |
| 64 | return ( |
| 65 | <span className="flex items-center gap-2 text-foreground-light text-sm"> |
| 66 | <AlertCircle size={14} className="text-destructive" /> |
| 67 | {isUpgrade ? 'Upgrade error' : 'Installation error'} |
| 68 | </span> |
| 69 | ) |
| 70 | } |
| 71 | if (installed) { |
| 72 | return ( |
| 73 | <span className="flex items-center gap-2 text-foreground-light text-sm"> |
| 74 | <Check size={14} strokeWidth={1.5} className="text-brand" /> Installed |
| 75 | </span> |
| 76 | ) |
| 77 | } |
| 78 | return ( |
| 79 | <span className="flex items-center gap-2 text-foreground-light text-sm">Not installed</span> |
| 80 | ) |
| 81 | } |