import { Box, CheckBox } from '@rocket.chat/fuselage'; import { useUserPreference, useTranslation, useEndpoint } from '@rocket.chat/ui-contexts'; import type { FC, ReactElement, ComponentType } from 'react'; import React, { useState } from 'react'; import type { DontAskAgainList } from '../hooks/useDontAskAgain'; type DoNotAskAgainProps = { onConfirm: (...args: any) => Promise | void; dontAskAgain: { action: string; label: string; }; }; export type RequiredModalProps = { onConfirm?: (...args: any) => Promise | void; 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 = useEndpoint('POST', '/v1/users.setPreferences'); const [state, setState] = useState(false); const handleConfirm = async (): Promise => { try { if (state) { await saveFn({ data: { 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 };