import { useState } from "react"; import { __ } from "@wordpress/i18n"; import classnames from 'classnames'; import SyncDetails,{ SyncPaymentDetails } from "./Details"; import { SubscriptionSyncResponse } from "../../../hooks/useSubscriptionSync"; import styles from './styles.module.scss'; /** * @since 4.8.0 */ type SubscriptionSyncListProps = { syncResult: SubscriptionSyncResponse; } /** * @since 4.8.0 */ export default function SubscriptionSyncList({ syncResult }: SubscriptionSyncListProps) { const { details, missingTransactions } = syncResult; const [openItem, setOpenItem] = useState(null); const statusUpdated = details?.currentStatus !== details?.gatewayStatus; const periodUpdated = details?.currentPeriod !== details?.gatewayPeriod; const createdAtUpdated = details?.currentCreatedAt !== details?.gatewayCreatedAt; const paymentsUpdated = missingTransactions?.length > 0; const transactions = paymentsUpdated ? missingTransactions : [null]; const handleItemToggle = (itemId: string) => { setOpenItem(openItem === itemId ? null : itemId); }; return (
handleItemToggle("status")} > handleItemToggle("period")} > handleItemToggle("created")} > handleItemToggle("payments")} > {transactions?.map((transaction, index) => ())}
); } /** * @since 4.8.0 */ type SyncItemProps = { id: string; title: string; isAccurate: boolean | null; isOpen: boolean; onToggle: () => void; children: React.ReactNode; } /** * @since 4.8.0 */ function SyncItem({ id, title, isAccurate, isOpen, onToggle, children }: SyncItemProps) { return (
{isAccurate ? __('ACCURATE', 'give') : __('UPDATED', 'give')}

{title}

{isOpen && children}
); }