import { c } from 'ttag' ; import { EASY_SWITCH_SOURCE , ImportType } from '@proton/shared/lib/interfaces/EasySwitch' ; import { GoogleButton , PrimaryButton , FeatureCode , Loader , EasySwitchOauthModal } from '@proton/components' ; import { useAddresses , useFeature , useModals , useUser } from '@proton/components/hooks' ; import ImportModal from '@proton/components/containers/contacts/import/ImportModal' ; interface Props { onImportButtonClick ? : ( ) => void ; easySwitchSource ? : EASY_SWITCH_SOURCE ; } const ImportCsvContactButton = ( { easySwitchSource = EASY_SWITCH_SOURCE . IMPORT_CONTACTS_BUTTON , onImportButtonClick , } ) => { const { createModal } = useModals ( ) ; const [ user , loadingUser ] = useUser ( ) ; const [ addresses , loadingAddresses ] = useAddresses ( ) ; const easySwitchCalendarFeature = useFeature ( FeatureCode . EasySwitchCalendar ) ; const isEasySwitchCalendarEnabled = easySwitchCalendarFeature . feature ?. Value ; const handleClick = ( ) => { createModal ( < ImportModal />); if ( onImportButtonClick !== undefined ) { onImportButtonClick ( ) ; } } ; const isLoading = loadingUser || loadingAddresses || easySwitchCalendarFeature . loading ; if ( isLoading ) { return < Loader />; } const disabled = isLoading || ! user . hasNonDelinquentScope ; return ( < > < GoogleButton onClick = { ( ) => { createModal ( < EasySwitchOauthModal source = { easySwitchSource } addresses = { addresses } defaultCheckedTypes = { [ ImportType . CONTACTS ] } isEasySwitchCalendarEnabled = { isEasySwitchCalendarEnabled } / > ) ; } } disabled = { disabled } className = "mr1" / > < PrimaryButton id = "import-contacts-button" disabled = { disabled } onClick = { handleClick } > { c ( 'Action' ) . t `Import from .csv or vCard` } < /PrimaryButton> < />); } ; export default ImportCsvContactButton ;