Skip to content

Commit

Permalink
fixes local storage utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jitunayak committed Jun 4, 2024
1 parent 5de1e95 commit 2e361a2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/hooks/useRoomsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const BASE_URL = import.meta.env.VITE_BASE_URL;
const client = axios.create({
baseURL: BASE_URL,
headers: {
Authorization: 'Bearer ' + getLocalStorage('accessToken'),
Authorization: 'Bearer ' + getLocalStorage('access_token'),
'Content-Type': 'application/json',
},
});

const useRoomsApi = () => {
const fetchRooms = async (
page: number = 1
page: number = 1,
): Promise<{
allPages: number;
data: IRoom[];
Expand Down Expand Up @@ -49,7 +49,7 @@ const useRoomsApi = () => {
};

const sendBookingEmail = async (
payload: Pick<IBookingConfirmationPayload, 'checkInDate' | 'checkOutDate'>
payload: Pick<IBookingConfirmationPayload, 'checkInDate' | 'checkOutDate'>,
) => {
return client.post(`/api/v1/emails?action=bookingConfirmation`, {
...payload,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ function Home() {
const navigate = useNavigate();

useEffect(() => {
const redirectUri = getLocalStorage('redirectTo');
const redirectUri = getLocalStorage('redirect_to');
if (redirectUri) {
navigate({ to: redirectUri });
localStorage.removeItem('redirectTo');
localStorage.removeItem('redirect_to');
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
6 changes: 3 additions & 3 deletions src/types/ILocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type ILocalStorage = {
[key in LocalStorageKeys]: key extends 'accessToken'
[key in LocalStorageKeys]: key extends 'access_token'
? string
: key extends 'redirectTo'
: key extends 'redirect_to'
? string
: key extends 'user'
? {
Expand All @@ -14,4 +14,4 @@ export type ILocalStorage = {
: string;
};

export type LocalStorageKeys = 'accessToken' | 'redirectTo' | 'user';
export type LocalStorageKeys = 'access_token' | 'redirect_to' | 'user';
2 changes: 1 addition & 1 deletion src/utils/LocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const setLocalStorage = (key: LocalStorageKeys, value: unknown) => {
};

export function getLocalStorage<K extends LocalStorageKeys>(
storageKey: K
storageKey: K,
): ILocalStorage[K] | null {
const value = localStorage.getItem(storageKey);
if (!value) {
Expand Down

0 comments on commit 2e361a2

Please sign in to comment.