import { Flex, FlexItem, Grid, Text } from "../../../components/wp"; import { __ } from "@wordpress/i18n"; import type { useCheckConnection, useConnect, useReauthorize } from "../../../api/hooks"; import { AdminButton } from "../../../components/common"; import { ConnectConsentNote } from "../../connection/components"; import { AdminPanel, adminLayoutStyles as sharedStyles, badgeStyle } from "../../../layouts/admin"; import type { ConnectionDetails, Renderable } from "../../../types"; import { DATE_TIME_FORMAT_PRESETS, formatDateTime, formatLocale } from "../../../utils"; interface ConnectionSettingsPanelProps { checkConnection: ReturnType; connect: ReturnType; connection: ConnectionDetails; reauthorize: ReturnType; } interface ConnectionRowProps { label: string; value?: string | number | null; code?: boolean; children?: Renderable; } const ConnectionRow = ({ label, value, code = false, children }: ConnectionRowProps) => { const fallbackValue = value || "-"; return (
{label}
{children ?? (code ? {fallbackValue} : fallbackValue)}
); }; export const ConnectionSettingsPanel = ({ checkConnection, connect, connection, reauthorize, }: ConnectionSettingsPanelProps) => { // "failed" only exists once a store token does, so it needs Reauthorize, not first-install Connect. const hasStoreToken = connection.status !== "not_connected"; return (
{connection.label || "-"}
{!hasStoreToken && ( connect.mutate()} variant="primary" > {__("Connect store", "market-sync")} )} checkConnection.mutate()} variant="secondary" > {__("Check connection status", "market-sync")} {hasStoreToken && ( reauthorize.mutate()} variant="secondary" > {__("Reauthorize", "market-sync")} )} {hasStoreToken && ( {__("Generates a new store token and invalidates the previous token.", "market-sync")} )}
); };