diff --git a/packages/api-v4/.changeset/pr-9987-added-1702566330400.md b/packages/api-v4/.changeset/pr-9987-added-1702566330400.md new file mode 100644 index 00000000000..10a77e15e16 --- /dev/null +++ b/packages/api-v4/.changeset/pr-9987-added-1702566330400.md @@ -0,0 +1,5 @@ +--- +"@linode/api-v4": Added +--- + +Add setHeaders to GET profile/ endpoint ([#9987](https://github.com/linode/manager/pull/9987)) diff --git a/packages/api-v4/src/profile/profile.ts b/packages/api-v4/src/profile/profile.ts index 2a179722d5c..1779d465d66 100644 --- a/packages/api-v4/src/profile/profile.ts +++ b/packages/api-v4/src/profile/profile.ts @@ -10,6 +10,7 @@ import Request, { setData, setMethod, setParams, + setHeaders, setURL, setXFilter, } from '../request'; @@ -24,6 +25,7 @@ import { SendPhoneVerificationCodePayload, VerifyVerificationCodePayload, } from './types'; +import type { RequestOptions } from '../types'; /** * getProfile @@ -31,8 +33,13 @@ import { * Return the current (logged in) user's profile. * */ -export const getProfile = () => - Request(setURL(`${API_ROOT}/profile`), setMethod('GET')); +export const getProfile = ({ headers }: RequestOptions = {}) => { + return Request( + setURL(`${API_ROOT}/profile`), + setMethod('GET'), + setHeaders(headers) + ); +}; /** * updateProfile diff --git a/packages/manager/.changeset/pr-9987-upcoming-features-1702333742297.md b/packages/manager/.changeset/pr-9987-upcoming-features-1702333742297.md new file mode 100644 index 00000000000..027b2044b47 --- /dev/null +++ b/packages/manager/.changeset/pr-9987-upcoming-features-1702333742297.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Added +--- + +Add setHeaders to GET profile/ endpoint ([#9987](https://github.com/linode/manager/pull/9987)) diff --git a/packages/manager/src/features/Billing/BillingPanels/BillingSummary/PaymentDrawer/PaymentDrawer.tsx b/packages/manager/src/features/Billing/BillingPanels/BillingSummary/PaymentDrawer/PaymentDrawer.tsx index 52d62bef282..85d566d7177 100644 --- a/packages/manager/src/features/Billing/BillingPanels/BillingSummary/PaymentDrawer/PaymentDrawer.tsx +++ b/packages/manager/src/features/Billing/BillingPanels/BillingSummary/PaymentDrawer/PaymentDrawer.tsx @@ -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'; @@ -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'; diff --git a/packages/manager/src/features/GlobalNotifications/EmailBounce.tsx b/packages/manager/src/features/GlobalNotifications/EmailBounce.tsx index df71a4c7802..06ad2f44f8c 100644 --- a/packages/manager/src/features/GlobalNotifications/EmailBounce.tsx +++ b/packages/manager/src/features/GlobalNotifications/EmailBounce.tsx @@ -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'; @@ -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'; // ============================================================================= diff --git a/packages/manager/src/features/Support/SupportTickets/SupportTicketDialog.tsx b/packages/manager/src/features/Support/SupportTickets/SupportTicketDialog.tsx index f7196cf2fbd..22e46b964e4 100644 --- a/packages/manager/src/features/Support/SupportTickets/SupportTicketDialog.tsx +++ b/packages/manager/src/features/Support/SupportTickets/SupportTicketDialog.tsx @@ -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'; diff --git a/packages/manager/src/hooks/useInitialRequests.ts b/packages/manager/src/hooks/useInitialRequests.ts index c2bc651c79e..5157f22fd85 100644 --- a/packages/manager/src/hooks/useInitialRequests.ts +++ b/packages/manager/src/hooks/useInitialRequests.ts @@ -70,7 +70,7 @@ export const useInitialRequests = () => { // Username and whether a user is restricted queryClient.prefetchQuery({ - queryFn: getProfile, + queryFn: () => getProfile(), queryKey: 'profile', }), diff --git a/packages/manager/src/queries/profile.ts b/packages/manager/src/queries/profile.ts index 18e89ff4139..309c00f9386 100644 --- a/packages/manager/src/queries/profile.ts +++ b/packages/manager/src/queries/profile.ts @@ -37,13 +37,16 @@ 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(queryKey, getProfile, { +export const useProfile = ({ headers }: RequestOptions = {}) => { + const key = [queryKey, headers]; + return useQuery(key, () => getProfile({ headers }), { ...queryPresets.oneTimeFetch, - initialData: givenProfile, }); +}; export const useMutateProfile = () => { const queryClient = useQueryClient(); @@ -57,7 +60,7 @@ export const updateProfileData = ( newData: Partial, queryClient: QueryClient ): void => { - queryClient.setQueryData(queryKey, (oldData: Profile) => ({ + queryClient.setQueryData([queryKey, undefined], (oldData: Profile) => ({ ...oldData, ...newData, })); @@ -65,16 +68,20 @@ export const updateProfileData = ( export const useGrants = () => { const { data: profile } = useProfile(); - return useQuery([queryKey, 'grants'], listGrants, { - ...queryPresets.oneTimeFetch, - enabled: Boolean(profile?.restricted), - }); + return useQuery( + [queryKey, undefined, 'grants'], + listGrants, + { + ...queryPresets.oneTimeFetch, + enabled: Boolean(profile?.restricted), + } + ); }; export const getProfileData = (queryClient: QueryClient) => - queryClient.getQueryData(queryKey); + queryClient.getQueryData([queryKey, undefined]); export const getGrantData = (queryClient: QueryClient) => - queryClient.getQueryData([queryKey, 'grants']); + queryClient.getQueryData([queryKey, undefined, 'grants']); export const useSMSOptOutMutation = () => { const queryClient = useQueryClient(); @@ -101,7 +108,7 @@ export const useSSHKeysQuery = ( enabled = true ) => useQuery( - [queryKey, 'ssh-keys', 'paginated', params, filter], + [queryKey, {}, 'ssh-keys', 'paginated', params, filter], () => getSSHKeys(params, filter), { enabled, @@ -115,7 +122,7 @@ export const useCreateSSHKeyMutation = () => { createSSHKey, { onSuccess() { - queryClient.invalidateQueries([queryKey, 'ssh-keys']); + queryClient.invalidateQueries([queryKey, undefined, 'ssh-keys']); // also invalidate the /account/users data because that endpoint returns some SSH key data queryClient.invalidateQueries([accountQueryKey, 'users']); }, @@ -129,7 +136,7 @@ export const useUpdateSSHKeyMutation = (id: number) => { (data) => updateSSHKey(id, data), { onSuccess() { - queryClient.invalidateQueries([queryKey, 'ssh-keys']); + queryClient.invalidateQueries([queryKey, undefined, 'ssh-keys']); // also invalidate the /account/users data because that endpoint returns some SSH key data queryClient.invalidateQueries([accountQueryKey, 'users']); }, @@ -141,7 +148,7 @@ export const useDeleteSSHKeyMutation = (id: number) => { const queryClient = useQueryClient(); return useMutation<{}, APIError[]>(() => deleteSSHKey(id), { onSuccess() { - queryClient.invalidateQueries([queryKey, 'ssh-keys']); + queryClient.invalidateQueries([queryKey, undefined, 'ssh-keys']); // also invalidate the /account/users data because that endpoint returns some SSH key data queryClient.invalidateQueries([accountQueryKey, 'users']); }, @@ -152,14 +159,14 @@ export const sshKeyEventHandler = (event: EventWithStore) => { // This event handler is a bit agressive and will over-fetch, but UX will // be great because this will ensure Cloud has up to date data all the time. - event.queryClient.invalidateQueries([queryKey, 'ssh-keys']); + event.queryClient.invalidateQueries([queryKey, undefined, 'ssh-keys']); // also invalidate the /account/users data because that endpoint returns some SSH key data event.queryClient.invalidateQueries([accountQueryKey, 'users']); }; export const useTrustedDevicesQuery = (params?: Params, filter?: Filter) => useQuery, APIError[]>( - [queryKey, 'trusted-devices', 'paginated', params, filter], + [queryKey, {}, 'trusted-devices', 'paginated', params, filter], () => getTrustedDevices(params, filter), { keepPreviousData: true, @@ -170,7 +177,7 @@ export const useRevokeTrustedDeviceMutation = (id: number) => { const queryClient = useQueryClient(); return useMutation<{}, APIError[]>(() => deleteTrustedDevice(id), { onSuccess() { - queryClient.invalidateQueries([queryKey, 'trusted-devices']); + queryClient.invalidateQueries([queryKey, undefined, 'trusted-devices']); }, }); }; @@ -179,7 +186,7 @@ export const useDisableTwoFactorMutation = () => { const queryClient = useQueryClient(); return useMutation<{}, APIError[]>(disableTwoFactor, { onSuccess() { - queryClient.invalidateQueries([queryKey]); + queryClient.invalidateQueries([queryKey, undefined]); }, }); };