Skip to content

Commit

Permalink
code rabbit suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Dec 16, 2024
1 parent 353d0a0 commit 7161ede
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
6 changes: 5 additions & 1 deletion src/Utils/request/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ const ensurePathNotMissingReplacements = (path: string) => {
}
};

export function getJWTAccessToken() {
return localStorage.getItem(LocalStorageKeys.accessToken);
}

export function makeHeaders(noAuth: boolean, additionalHeaders?: HeadersInit) {
const headers = new Headers(additionalHeaders);

headers.set("Content-Type", "application/json");
headers.append("Accept", "application/json");

const jwtAccessToken = localStorage.getItem(LocalStorageKeys.accessToken);
const jwtAccessToken = getJWTAccessToken();
if (jwtAccessToken && !noAuth) {
headers.append("Authorization", `Bearer ${jwtAccessToken}`);
}
Expand Down
12 changes: 3 additions & 9 deletions src/components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ import { FieldLabel } from "@/components/Form/FormFields/FormField";
import useAuthUser from "@/hooks/useAuthUser";
import useSlug from "@/hooks/useSlug";

import {
FACILITY_FEATURE_TYPES,
LocalStorageKeys,
USER_TYPES,
} from "@/common/constants";
import { FACILITY_FEATURE_TYPES, USER_TYPES } from "@/common/constants";

import { PLUGIN_Component } from "@/PluginEngine";
import { NonReadOnlyUsers } from "@/Utils/AuthorizeFor";
Expand All @@ -42,6 +38,7 @@ import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
import uploadFile from "@/Utils/request/uploadFile";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import { getJWTAccessToken } from "@/Utils/request/utils";
import { sleep } from "@/Utils/utils";

import { patientRegisterAuth } from "../Patient/PatientRegister";
Expand Down Expand Up @@ -121,10 +118,7 @@ export const FacilityHome = ({ facilityId }: Props) => {
url,
formData,
"POST",
{
Authorization:
"Bearer " + localStorage.getItem(LocalStorageKeys.accessToken),
},
{ Authorization: `Bearer ${getJWTAccessToken()}` },
async (xhr: XMLHttpRequest) => {
if (xhr.status === 200) {
await sleep(1000);
Expand Down
8 changes: 2 additions & 6 deletions src/components/Users/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import Loading from "@/components/Common/Loading";

import useAuthUser from "@/hooks/useAuthUser";

import { LocalStorageKeys } from "@/common/constants";

import * as Notification from "@/Utils/Notifications";
import { showAvatarEdit } from "@/Utils/permissions";
import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
import uploadFile from "@/Utils/request/uploadFile";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import { getJWTAccessToken } from "@/Utils/request/utils";
import { formatDisplayName, sleep } from "@/Utils/utils";

export default function UserAvatar({ username }: { username: string }) {
Expand Down Expand Up @@ -47,10 +46,7 @@ export default function UserAvatar({ username }: { username: string }) {
url,
formData,
"POST",
{
Authorization:
"Bearer " + localStorage.getItem(LocalStorageKeys.accessToken),
},
{ Authorization: `Bearer ${getJWTAccessToken()}` },
async (xhr: XMLHttpRequest) => {
if (xhr.status === 200) {
await sleep(1000);
Expand Down
8 changes: 3 additions & 5 deletions src/components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {

import useAuthUser, { useAuthContext } from "@/hooks/useAuthUser";

import { GENDER_TYPES, LocalStorageKeys } from "@/common/constants";
import { GENDER_TYPES } from "@/common/constants";
import { validateEmailAddress } from "@/common/validation";

import * as Notification from "@/Utils/Notifications";
Expand All @@ -35,6 +35,7 @@ import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
import uploadFile from "@/Utils/request/uploadFile";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import { getJWTAccessToken } from "@/Utils/request/utils";
import {
dateQueryString,
formatDate,
Expand Down Expand Up @@ -507,10 +508,7 @@ export default function UserProfile() {
url,
formData,
"POST",
{
Authorization:
"Bearer " + localStorage.getItem(LocalStorageKeys.accessToken),
},
{ Authorization: `Bearer ${getJWTAccessToken()}` },
async (xhr: XMLHttpRequest) => {
if (xhr.status === 200) {
await sleep(1000);
Expand Down

0 comments on commit 7161ede

Please sign in to comment.