Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | 1x 51x 51x 1x 59x 59x 59x 59x 4x 4x 59x 59x 59x 59x 59x 8x 59x 59x 59x | import Table from "componentsV2/Table/Table";
import GiveMerchantBanner from "@shared/Banner/GiveMerchantBanner";
import GiveMotionWrapper from "@shared/Motion/GiveMotionWrapper";
import { useMemo } from "react";
import BackgroundAnimation from "@shared/Banner/BackgroundAnimation";
import useTableSearch from "componentsV2/Table/hooks/useTableSearch";
import { useHandleScroll } from "componentsV2/Table/hooks/useHandleScroll";
import { useGetMerchantsApiKeyTable } from "./hooks/useGetMerchantsApiKeyTable";
import { MechantBannerProps, MerchantsKeyTableProps } from "./types";
import ContextualMenu from "@shared/ContextualMenu/ContextualMenu";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import {
FAILED_TO_PROCEED_API_KEY_MODAL,
GENERATE_MERCHANT_API_KEY_MODAL,
MERCHANT_DEVELOPER_API_PANEL,
} from "modals/modal_names";
import { useTable } from "componentsV2/Table/hooks/useTable";
import { QKEY_MERCHANTS_API_KEYS } from "@constants/queryKeys";
import NiceModal from "@ebay/nice-modal-react";
import { useAccessControl } from "@features/Permissions/AccessControl";
import RESOURCE_BASE, {
CREATE_DENY_MESSAGE,
OPERATIONS,
} from "@constants/permissions";
import { useComponentHeight } from "@hooks/common/useComponentHeight";
const MerchantBanner = ({
handleSearchChange,
handleCreate,
search,
compact = false,
totalRows = 0,
}: MechantBannerProps) => {
const canCreateApiKey = useAccessControl({
withPortal: true,
resource: RESOURCE_BASE.DEVELOPER,
operation: OPERATIONS.CREATE,
});
return (
<GiveMerchantBanner
title="Developer"
action="Add API Key"
filters={[]}
handleCreate={handleCreate}
type={"developer"}
handleSearchChange={handleSearchChange}
search={search}
disableCreate={!canCreateApiKey}
compact={compact}
compactStats={[{ key: "apiKeys", value: totalRows, label: "API Keys" }]}
tooltipProps={{
disableHoverListener: canCreateApiKey,
title: CREATE_DENY_MESSAGE,
}}
/>
);
};
const MerchantsApiKeyTable = ({ ...props }: MerchantsKeyTableProps) => {
const { height } = useComponentHeight();
const { isMobileView } = useCustomThemeV2();
const {
isLoading,
page,
setPageDispatcher,
setPage,
totalRows,
allRows: rows,
columns,
getMenuActions,
onCloseMenu,
anchorEl,
isProductionOptionEnabled,
merchantData,
isDisabledCreation,
} = useGetMerchantsApiKeyTable();
const openCreateApiKeyModal = () => {
if (merchantData?.owner?.email) {
NiceModal.show(GENERATE_MERCHANT_API_KEY_MODAL, {
isProductionOptionEnabled,
isDisabledCreation,
});
} else E{
NiceModal.show(FAILED_TO_PROCEED_API_KEY_MODAL, {
isProductionOptionEnabled,
});
}
};
const { setSelectedRowIdx, loadMore, numberOfPages, selectedRowIdx } =
useTable({
allRows: rows,
isLoading,
totalRows,
page,
setPageDispatcher,
setPage,
openModal: MERCHANT_DEVELOPER_API_PANEL,
});
const { onScroll } = useHandleScroll();
const canCreateApiKey = useAccessControl({
withPortal: true,
resource: RESOURCE_BASE.DEVELOPER,
operation: OPERATIONS.CREATE,
});
const { search, searchQuery, handleSearchChange } = useTableSearch({
queryKey: QKEY_MERCHANTS_API_KEYS,
});
const emptyStateAction = useMemo(
() => ({
handleAction: openCreateApiKeyModal,
disabled: !canCreateApiKey,
}),
[],
);
const isListAPIKeysAllowed = useAccessControl({
withPortal: true,
resource: RESOURCE_BASE.DEVELOPER,
operation: OPERATIONS.LIST,
});
const menuActions = getMenuActions();
return (
<>
<BackgroundAnimation page="acquirerProviders" />
<GiveMotionWrapper
delay={30}
containerProps={{ sx: { height: "100%", zIndex: 2 } }}
customStyle={{
height: "100%",
display: "flex",
justifyContent: "center",
}}
>
<Table
{...props}
top={height}
allRows={rows}
columns={columns}
totalRows={totalRows}
type="developer"
Head={
<MerchantBanner
handleCreate={openCreateApiKeyModal}
handleSearchChange={
isListAPIKeysAllowed ? handleSearchChange : undefined
}
search={search}
/>
}
CompactHead={
<MerchantBanner
compact
totalRows={totalRows}
handleCreate={openCreateApiKeyModal}
handleSearchChange={
isListAPIKeysAllowed ? handleSearchChange : undefined
}
search={search}
/>
}
compactAnimationPage="acquirerProviders"
isLoading={isLoading}
emptyStateAction={emptyStateAction}
emptyStateActionTooltipProps={{
disableHoverListener: canCreateApiKey,
title: CREATE_DENY_MESSAGE,
}}
isListPermissionAllowed={isListAPIKeysAllowed}
sectionName="Developer API"
queryKey={QKEY_MERCHANTS_API_KEYS}
onScroll={onScroll}
searchQuery={searchQuery}
handleSearchChange={handleSearchChange}
page={page}
setPageDispatcher={setPageDispatcher}
setPage={setPage}
setSelectedRowIdx={setSelectedRowIdx}
selectedRowIdx={selectedRowIdx}
loadMore={loadMore}
numberOfPages={numberOfPages}
openModal={MERCHANT_DEVELOPER_API_PANEL}
hideCaret
customLoadingRowProps={{
height: isMobileView ? "120px" : undefined,
sx: { paddingInline: isMobileView ? "0" : undefined },
}}
/>
</GiveMotionWrapper>
<ContextualMenu
handleClose={onCloseMenu}
anchorEl={anchorEl}
options={menuActions}
color={isMobileView ? "primary" : "tertiary"}
texture={isMobileView ? "solid" : "blurred"}
/>
</>
);
};
export default MerchantsApiKeyTable;
|