import { noop } from 'lodash' import { PropsWithChildren, useState } from 'react' import { Button } from 'ui' interface ActionBarProps { loading?: boolean disableApply?: boolean hideApply?: boolean applyButtonLabel?: string backButtonLabel?: string applyFunction?: (resolve: any) => void closePanel: () => void formId?: string } const ActionBar = ({ loading = false, disableApply = false, hideApply = false, children = undefined, applyButtonLabel = 'Apply', backButtonLabel = 'Back', applyFunction = undefined, closePanel = noop, formId, }: PropsWithChildren) => { const [isRunning, setIsRunning] = useState(false) // @ts-ignore const applyCallback = () => new Promise((resolve) => applyFunction(resolve)) const onSelectApply = async () => { setIsRunning(true) await applyCallback() setIsRunning(false) } return (
{children} {applyFunction !== undefined ? ( // Old solution, necessary when loading is handled by this component itself ) : !hideApply ? ( // New solution, when using the Form component, loading is handled by the Form itself // Does not require applyFunction() callback ) : (
)}
) } export default ActionBar