Skip to content

Commit 8475f5b

Browse files
committed
Add "Manage this purchase" link to PurchasesDataViews
1 parent 1735618 commit 8475f5b

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

client/me/purchases/purchases-list-in-dataviews/purchases-data-view.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Card } from '@automattic/components';
1+
import page from '@automattic/calypso-router';
2+
import { Gridicon, Card } from '@automattic/components';
23
import { Purchases } from '@automattic/data-stores';
34
import { DataViews, View, filterSortAndPaginate } from '@wordpress/dataviews';
4-
import { LocalizeProps } from 'i18n-calypso';
5+
import { LocalizeProps, useTranslate } from 'i18n-calypso';
56
import { useMemo, useState } from 'react';
67
import { MembershipSubscription } from 'calypso/lib/purchases/types';
78
import {
@@ -27,13 +28,31 @@ export function PurchasesDataViews( props: {
2728
translate: LocalizeProps[ 'translate' ];
2829
} ) {
2930
const { purchases } = props;
31+
const translate = useTranslate();
3032
const [ currentView, setView ] = useState( purchasesDataView );
3133
const purchasesDataFields = usePurchasesFieldDefinitions( purchasesDataView.fields );
3234

3335
const { data: adjustedPurchases, paginationInfo } = useMemo( () => {
3436
return filterSortAndPaginate( purchases, currentView, purchasesDataFields );
3537
}, [ purchases, currentView, purchasesDataFields ] );
3638

39+
const actions = useMemo(
40+
() => [
41+
{
42+
id: 'manage-purchase',
43+
label: translate( 'Manage this purchase', { textOnly: true } ),
44+
isPrimary: true,
45+
icon: <Gridicon icon="chevron-right" />,
46+
callback: ( items: Purchases.Purchase[] ) => {
47+
const siteUrl = items[ 0 ].domain;
48+
const subscriptionId = items[ 0 ].id;
49+
page( `/me/purchases/${ siteUrl }/${ subscriptionId }` );
50+
},
51+
},
52+
],
53+
[ translate ]
54+
);
55+
3756
const getItemId = ( item: Purchases.Purchase ) => {
3857
return item.id.toString();
3958
};
@@ -45,7 +64,7 @@ export function PurchasesDataViews( props: {
4564
view={ currentView }
4665
onChangeView={ setView }
4766
defaultLayouts={ { table: {} } }
48-
actions={ undefined }
67+
actions={ actions }
4968
getItemId={ getItemId }
5069
paginationInfo={ paginationInfo }
5170
/>

0 commit comments

Comments
 (0)