@finos/legend-application-marketplace
Version:
Legend Marketplace application core
147 lines • 8.97 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { observer } from 'mobx-react-lite';
import { Button, Typography, CircularProgress } from '@mui/material';
import { LegendMarketplacePage } from '../LegendMarketplacePage.js';
import { useCallback, useEffect, useState } from 'react';
import { DataGrid, } from '@finos/legend-lego/data-grid';
import { useLegendMarketplaceBaseStore } from '../../application/providers/LegendMarketplaceFrameworkProvider.js';
import { flowResult } from 'mobx';
import { UserSearchInput } from '@finos/legend-art';
import { useLegendMarketplaceSubscriptionsStore, withLegendMarketplaceSubscriptionsStore, } from '../../application/providers/LegendMarketplaceSubscriptionsStoreProvider.js';
export const LegendMarketplaceSubscriptions = withLegendMarketplaceSubscriptionsStore(observer(() => {
const marketplaceStore = useLegendMarketplaceBaseStore();
const subscriptionStore = useLegendMarketplaceSubscriptionsStore();
const [userSearchEnabled, setUserSearchEnabled] = useState(false);
const initialUser = marketplaceStore.applicationStore.identityService.currentUser;
const fetchSubscriptions = useCallback(async (user) => {
flowResult(subscriptionStore.fetchSubscription(user)).catch(marketplaceStore.applicationStore.alertUnhandledError);
}, [
subscriptionStore,
marketplaceStore.applicationStore.alertUnhandledError,
]);
const cancelSubscription = () => {
const orderItems = {};
subscriptionStore.selectedSubscriptions.forEach((s) => {
const subscription = {
providerName: s.carrierVendor,
productName: s.serviceName,
category: s.itemName,
price: s.price,
servicepriceId: s.servicepriceId ?? 0,
model: s.model,
};
if (s.permId in orderItems) {
orderItems[s.permId]?.push(subscription);
}
else {
orderItems[s.permId] = [subscription];
}
});
const cancellationRequest = {
ordered_by: initialUser,
kerberos: subscriptionStore.selectedUser.id,
order_items: orderItems,
};
flowResult(subscriptionStore.cancelSubscription(cancellationRequest)).catch(marketplaceStore.applicationStore.alertUnhandledError);
};
useEffect(() => {
flowResult(subscriptionStore.refresh()).catch(marketplaceStore.applicationStore.alertUnhandledError);
}, [
subscriptionStore,
marketplaceStore.applicationStore.alertUnhandledError,
]);
return (_jsx(LegendMarketplacePage, { className: "legend-marketplace-home", children: _jsxs("div", { className: "legend-marketplace-subscriptions-content", children: [_jsxs("div", { className: "legend-marketplace-subscriptions-content__search-section", children: [_jsx(Typography, { variant: "h2", fontWeight: "bold", children: "Subscriptions" }), userSearchEnabled ? (_jsx(UserSearchInput, { className: "legend-marketplace-subscriptions__user-input", userValue: subscriptionStore.selectedUser, setUserValue: (_user) => {
subscriptionStore.setSelectedUser(_user);
fetchSubscriptions(_user.id).catch(marketplaceStore.applicationStore.alertUnhandledError);
}, userSearchService: marketplaceStore.userSearchService, label: "Search user", required: true, variant: "outlined", fullWidth: true })) : (_jsx(Button, { variant: "contained", className: "legend-marketplace-subscriptions-content_button", onClick: () => setUserSearchEnabled(!userSearchEnabled), children: "Change User" })), _jsx(Button, { className: "legend-marketplace-subscriptions-content__cancel-button", disabled: subscriptionStore.selectedSubscriptions.length <= 0 ||
subscriptionStore.cancelSubscriptionState.isInProgress, onClick: cancelSubscription, variant: "contained", color: "secondary", startIcon: subscriptionStore.cancelSubscriptionState.isInProgress ? (_jsx(CircularProgress, { size: 16, color: "inherit" })) : null, sx: { minWidth: 180 }, children: subscriptionStore.cancelSubscriptionState.isInProgress
? 'Cancelling...'
: 'Cancel Subscription' })] }), subscriptionStore.fetchSubscriptionState.isInProgress ? (_jsx(CircularProgress, { size: 25 })) : (_jsx("div", { className: "legend-marketplace-subscriptions-content__subscription-grid ag-theme-balham", style: { height: '1000px', width: '100%', fontSize: '14px' }, children: _jsx(DataGrid, { rowData: subscriptionStore.subscriptionFeeds, columnDefs: [
{
minWidth: 50,
headerName: 'Carrier Vendor',
field: 'carrierVendor',
spanRows: true,
suppressHeaderMenuButton: true,
flex: 1,
},
{
minWidth: 50,
headerName: 'Product',
field: 'model',
spanRows: true,
suppressHeaderMenuButton: true,
flex: 1,
},
{
minWidth: 50,
headerName: 'Source Vendor',
field: 'sourceVendor',
suppressHeaderMenuButton: true,
flex: 1,
},
{
minWidth: 50,
headerName: 'Item Type',
field: 'itemName',
suppressHeaderMenuButton: true,
flex: 1,
},
{
minWidth: 50,
headerName: 'Service',
field: 'serviceName',
suppressHeaderMenuButton: true,
flex: 1,
},
{
minWidth: 50,
headerName: 'Cost (USD)',
field: 'annualAmount',
suppressHeaderMenuButton: true,
flex: 1,
},
{
minWidth: 50,
headerName: 'Cost Code',
field: 'costCode',
suppressHeaderMenuButton: true,
flex: 1,
},
{
minWidth: 60,
headerName: 'Cancel Subscription',
suppressHeaderMenuButton: true,
flex: 1,
cellRenderer: (params) => (_jsx("input", { type: "checkbox", checked: subscriptionStore.selectedSubscriptions.some((sub) => sub.id === params.data?.id), onChange: (e) => {
if (e.target.checked) {
subscriptionStore.addSelectedSubscriptions(params.data ?? null);
}
else {
subscriptionStore.removeSelectedSubscription(params.data ?? null);
}
} })),
},
], enableCellSpan: true, defaultColDef: {
headerStyle: {
fontSize: '18px',
backgroundColor: '#dce3e8',
},
} }) }))] }) }));
}));
//# sourceMappingURL=LegendMarketplaceSubscriptions.js.map