import * as React from 'react'; import Dropdown from '@wcpos/components/src/dropdown'; import Icon from '@wcpos/components/src/icon'; import Loader from '@wcpos/components/src/loader'; import { useT } from '../../../contexts/translations'; interface SyncButtonProps { sync: () => Promise; clear: () => Promise; active: boolean; } const SyncButton = ({ sync, clear, active }: SyncButtonProps) => { const [openMenu, setOpenMenu] = React.useState(false); const t = useT(); /** * */ const handleClearAndSync = React.useCallback(async () => { await clear(); // await sync(); // this sync function is going to be stale after clear }, [clear]); /** * */ return active ? ( ) : ( setOpenMenu(false)} placement="top-end" items={[ { label: t('Sync', { _tags: 'core' }), action: sync, icon: 'arrowRotateRight', }, { label: '__' }, { label: t('Clear and Refresh', { _tags: 'core' }), action: handleClearAndSync, type: 'critical', icon: 'trash', }, ]} trigger="longpress" > setOpenMenu(true)} tooltip={t('Press to sync, long press for more options', { _tags: 'core' })} tooltipPlacement="top-end" /> ); }; export default SyncButton;