import { Box, CheckBox } from '@rocket.chat/fuselage'; import React, { useState, FC, ReactElement, ComponentType } from 'react'; import { useMethod } from '../contexts/ServerContext'; import { useTranslation } from '../contexts/TranslationContext'; import { useUserPreference } from '../contexts/UserContext'; import { DontAskAgainList } from '../hooks/useDontAskAgain'; type DoNotAskAgainProps = { onConfirm: (...args: any) => any; dontAskAgain: { action: string; label: string; }; }; export type RequiredModalProps = { onConfirm: (...args: any) => any; dontAskAgain?: ReactElement; }; function withDoNotAskAgain( Component: ComponentType, ): FC> { const WrappedComponent: FC> = function ({ onConfirm, dontAskAgain, ...props }) { const t = useTranslation(); const dontAskAgainList = useUserPreference('dontAskAgainList'); const { action, label } = dontAskAgain; const saveFn = useMethod('saveUserPreferences'); const [state, setState] = useState(false); const handleConfirm = async (): Promise => { try { if (state) { await saveFn({ dontAskAgainList: [...(dontAskAgainList || []), { action, label }] }); } await onConfirm(); } catch (e) { console.error(e); } }; const onChange = (): void => { setState(!state); }; return ( } onConfirm={handleConfirm} /> ); }; WrappedComponent.displayName = `withDoNotAskAgain(${Component.displayName ?? Component.name ?? 'Component'})`; return WrappedComponent; } export { withDoNotAskAgain };