Skip to content

Commit

Permalink
AddProfileLinksButtons: migrate to TypeScript & FC
Browse files Browse the repository at this point in the history
  • Loading branch information
flootr committed Nov 14, 2023
1 parent 441292c commit 2c59e43
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 69 deletions.
69 changes: 0 additions & 69 deletions client/me/profile-links/add-buttons.jsx

This file was deleted.

70 changes: 70 additions & 0 deletions client/me/profile-links/add-buttons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Button, Gridicon } from '@automattic/components';
import { useTranslate } from 'i18n-calypso';
import { useRef } from 'react';
import { useDispatch } from 'react-redux';
import PopoverMenu from 'calypso/components/popover-menu';
import PopoverMenuItem from 'calypso/components/popover-menu/item';
import { recordGoogleEvent } from 'calypso/state/analytics/actions';

type AddProfileLinksButtonsProps = {
disabled?: boolean;
showPopoverMenu?: boolean;
onShowPopoverMenu: () => void;
onClosePopoverMenu: () => void;
onShowAddWordPress: () => void;
onShowAddOther: () => void;
};

const AddProfileLinksButtons = ( {
disabled = false,
showPopoverMenu = false,
onShowPopoverMenu,
onClosePopoverMenu,
onShowAddWordPress,
onShowAddOther,
}: AddProfileLinksButtonsProps ) => {
const translate = useTranslate();
const dispatch = useDispatch();

const popoverContext = useRef( null );

const recordClickEvent = ( action: string ) => {
dispatch( recordGoogleEvent( 'Me', 'Clicked on ' + action ) );
};

const handleAddWordPressSiteButtonClick = () => {
recordClickEvent( 'Add a WordPress Site Button' );
onShowAddWordPress();
};

const handleOtherSiteButtonClick = () => {
recordClickEvent( 'Add Other Site Button' );
onShowAddOther();
};

return (
<>
<Button
ref={ popoverContext }
compact
disabled={ disabled }
onClick={ showPopoverMenu ? onClosePopoverMenu : onShowPopoverMenu }
>
<Gridicon icon="add-outline" />
<span>{ translate( 'Add' ) }</span>
</Button>
{ showPopoverMenu && (
<PopoverMenu isVisible onClose={ onClosePopoverMenu } context={ popoverContext.current }>
<PopoverMenuItem onClick={ handleAddWordPressSiteButtonClick }>
{ translate( 'Add WordPress Site' ) }
</PopoverMenuItem>
<PopoverMenuItem onClick={ handleOtherSiteButtonClick }>
{ translate( 'Add URL' ) }
</PopoverMenuItem>
</PopoverMenu>
) }
</>
);
};

export default AddProfileLinksButtons;

0 comments on commit 2c59e43

Please sign in to comment.