Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [M3-7526] - Add setHeader to GET /profile endpoint #9987

Merged
merged 21 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/api-v4/src/profile/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Request, {
setData,
setMethod,
setParams,
setHeaders,
setURL,
setXFilter,
} from '../request';
Expand All @@ -24,15 +25,21 @@ import {
SendPhoneVerificationCodePayload,
VerifyVerificationCodePayload,
} from './types';
import type { RequestOptions } from '../types';

/**
* getProfile
*
* Return the current (logged in) user's profile.
*
*/
export const getProfile = () =>
Request<Profile>(setURL(`${API_ROOT}/profile`), setMethod('GET'));
export const getProfile = ({ headers }: RequestOptions = {}) => {
return Request<Profile>(
setURL(`${API_ROOT}/profile`),
setMethod('GET'),
setHeaders(headers)
);
};

/**
* updateProfile
Expand Down
tyler-akamai marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Add setHeaders to GET profile/ endpoint ([#9987](https://github.com/linode/manager/pull/9987))
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PaymentMethod } from '@linode/api-v4';
import { makePayment } from '@linode/api-v4/lib/account';
import { APIWarning } from '@linode/api-v4/lib/types';
import { Stack } from 'src/components/Stack';
import Grid from '@mui/material/Unstable_Grid2';
import { useSnackbar } from 'notistack';
import * as React from 'react';
Expand All @@ -16,6 +15,7 @@ import { ErrorState } from 'src/components/ErrorState/ErrorState';
import { InputAdornment } from 'src/components/InputAdornment';
import { LinearProgress } from 'src/components/LinearProgress';
import { Notice } from 'src/components/Notice/Notice';
import { Stack } from 'src/components/Stack';
import { SupportLink } from 'src/components/SupportLink';
import { TextField } from 'src/components/TextField';
import { TooltipIcon } from 'src/components/TooltipIcon';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Grid from '@mui/material/Unstable_Grid2';
import { useTheme, Theme } from '@mui/material/styles';
import { Theme, useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useSnackbar } from 'notistack';
import * as React from 'react';
Expand All @@ -11,6 +11,7 @@ import { Typography } from 'src/components/Typography';
import { useAccount, useMutateAccount } from 'src/queries/account';
import { useNotificationsQuery } from 'src/queries/accountNotifications';
import { useMutateProfile, useProfile } from 'src/queries/profile';

import { StyledGrid } from './EmailBounce.styles';

// =============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
} from '@linode/api-v4/lib/support';
import { APIError } from '@linode/api-v4/lib/types';
import { Theme } from '@mui/material/styles';
import { makeStyles } from 'tss-react/mui';
import { update } from 'ramda';
import * as React from 'react';
import { debounce } from 'throttle-debounce';
import { makeStyles } from 'tss-react/mui';

import { Accordion } from 'src/components/Accordion';
import { ActionsPanel } from 'src/components/ActionsPanel/ActionsPanel';
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/hooks/useInitialRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const useInitialRequests = () => {

// Username and whether a user is restricted
queryClient.prefetchQuery({
queryFn: getProfile,
queryFn: () => getProfile(),
queryKey: 'profile',
}),

Expand Down
11 changes: 9 additions & 2 deletions packages/manager/src/queries/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ import { Grants } from '../../../api-v4/lib';
import { queryKey as accountQueryKey } from './account';
import { queryPresets } from './base';

import type { RequestOptions } from '@linode/api-v4';

export const queryKey = 'profile';

export const useProfile = (givenProfile?: Profile) =>
useQuery<Profile, APIError[]>(queryKey, getProfile, {
export const useProfile = (
givenProfile?: Profile,
tyler-akamai marked this conversation as resolved.
Show resolved Hide resolved
{ headers }: RequestOptions = {}
tyler-akamai marked this conversation as resolved.
Show resolved Hide resolved
) => {
const key = [queryKey, headers];
return useQuery<Profile, APIError[]>(key, () => getProfile({ headers }), {
...queryPresets.oneTimeFetch,
initialData: givenProfile,
});
};

export const useMutateProfile = () => {
const queryClient = useQueryClient();
Expand Down