Skip to content

Commit

Permalink
feat: get payments methods to check if there's any payment info saved
Browse files Browse the repository at this point in the history
  • Loading branch information
r41ph committed Oct 3, 2024
1 parent ceaaef4 commit 2feb15a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
ListItemText,
ListSubheader,
} from '@mui/material';
import { useQuery } from '@tanstack/react-query';

import { getPaymentMethodsQuery } from 'lib/queries/react-query/registry-server/getPaymentMethodsQuery/getPaymentMethodsQuery';

import { AdminNavigationSection } from './AdminNavigation.types';
import { isSelected } from './AdminNavigation.utils';
Expand All @@ -26,8 +29,13 @@ export const AdminNavigation = ({
}: AdminNavigationProps) => {
const { _ } = useLingui();

// TODO: implement savedPaymentInfo to check if there's any payment info saved
const savedPaymentInfo = true;
const { data: paymentMethodData } = useQuery(
getPaymentMethodsQuery({
enabled: true,
}),
);

const savedPaymentInfo = (paymentMethodData?.paymentMethods?.length ?? 0) > 0;

if (!savedPaymentInfo) {
// If there is no saved payment info remove the item from the nav
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { useLocation } from 'react-router-dom';
import { useLingui } from '@lingui/react';
import Box from '@mui/material/Box';
import { useTheme } from '@mui/styles';
import { useQuery } from '@tanstack/react-query';
import { getClientConfig } from 'clients/Clients.config';

import Header from 'web-components/src/components/header';
import { UserMenuItems } from 'web-components/src/components/header/components/UserMenuItems';
import { Theme } from 'web-components/src/theme/muiTheme';

import { useAuth } from 'lib/auth/auth';
import { getPaymentMethodsQuery } from 'lib/queries/react-query/registry-server/getPaymentMethodsQuery/getPaymentMethodsQuery';
import { useWallet } from 'lib/wallet/wallet';

import { getWalletAddress } from 'pages/Dashboard/Dashboard.utils';
Expand Down Expand Up @@ -54,8 +56,13 @@ const RegistryLayoutHeader: React.FC = () => {
const menuItems = useMemo(() => getMenuItems(pathname, _), [pathname, _]);
const onProfileClick = useOnProfileClick();

// TODO: implement savedPaymentInfo
const savedPaymentInfo = true;
const { data: paymentMethodData } = useQuery(
getPaymentMethodsQuery({
enabled: !!isConnected,
}),
);

const savedPaymentInfo = (paymentMethodData?.paymentMethods?.length ?? 0) > 0;

const userMenuItems = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const GET_PAYMENT_METHODS_QUERY_KEY = 'getPost';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { apiUri } from 'lib/apiUri';

import { GET_PAYMENT_METHODS_QUERY_KEY } from './getPaymentMethodsQuery.constants';
import {
ReactQueryGetPostQueryParams,
ReactQueryGetPostQueryResponse,
} from './getPaymentMethodsQuery.types';

export const getPaymentMethodsQuery = ({
limit,
...params
}: ReactQueryGetPostQueryParams): ReactQueryGetPostQueryResponse => ({
queryKey: [GET_PAYMENT_METHODS_QUERY_KEY, limit],
queryFn: async () => {
try {
const resp = await fetch(
`${apiUri}/marketplace/v1/stripe/payment-methods${
limit ? `?limit=${limit}` : ''
}`,
{
method: 'GET',
credentials: 'include',
},
);
return await resp.json();
} catch (e) {
return null;
}
},
...params,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PaymentMethod } from '@stripe/stripe-js';
import { QueryObserverOptions } from '@tanstack/react-query';

import { ReactQueryBuilderResponse } from '../../types/react-query.types';

export type ReactQueryGetPostQueryResponse = QueryObserverOptions<{
paymentMethods?: PaymentMethod[] | null;
}>;

export type ReactQueryGetPostQueryParams = {
limit?: number;
} & ReactQueryBuilderResponse<ReactQueryGetPostQueryResponse>;

0 comments on commit 2feb15a

Please sign in to comment.