Imported libraries, removed next-basics.

This commit is contained in:
Mike Cao 2025-02-05 13:30:28 -08:00
parent 31266cb1ac
commit 113022ed17
44 changed files with 361 additions and 180 deletions

View file

@ -11,6 +11,7 @@ export function useTeams(userId: string) {
queryFn: (params: any) => {
return get(`/users/${userId}/teams`, params);
},
enabled: !!userId,
});
}

View file

@ -1,7 +1,8 @@
import { useCallback } from 'react';
import * as reactQuery from '@tanstack/react-query';
import { useApi as nextUseApi } from 'next-basics';
import { getClientAuthToken } from 'lib/client';
import { SHARE_TOKEN_HEADER } from 'lib/constants';
import { httpGet, httpPost, httpPut, httpDelete } from 'lib/fetch';
import useStore from 'store/app';
const selector = (state: { shareToken: { token?: string } }) => state.shareToken;
@ -9,12 +10,50 @@ const selector = (state: { shareToken: { token?: string } }) => state.shareToken
export function useApi() {
const shareToken = useStore(selector);
const { get, post, put, del } = nextUseApi(
{ authorization: `Bearer ${getClientAuthToken()}`, [SHARE_TOKEN_HEADER]: shareToken?.token },
process.env.basePath,
);
const defaultHeaders = {
authorization: `Bearer ${getClientAuthToken()}`,
[SHARE_TOKEN_HEADER]: shareToken?.token,
};
const basePath = process.env.basePath;
return { get, post, put, del, ...reactQuery };
function getUrl(url: string, basePath = ''): string {
return url.startsWith('http') ? url : `${basePath}/api${url}`;
}
const getHeaders = (headers: any = {}) => {
return { ...defaultHeaders, ...headers };
};
return {
get: useCallback(
async (url: string, params: object = {}, headers: object = {}) => {
return httpGet(getUrl(url, basePath), params, getHeaders(headers));
},
[httpGet],
),
post: useCallback(
async (url: string, params: object = {}, headers: object = {}) => {
return httpPost(getUrl(url, basePath), params, getHeaders(headers));
},
[httpPost],
),
put: useCallback(
async (url: string, params: object = {}, headers: object = {}) => {
return httpPut(getUrl(url, basePath), params, getHeaders(headers));
},
[httpPut],
),
del: useCallback(
async (url: string, params: object = {}, headers: object = {}) => {
return httpDelete(getUrl(url, basePath), params, getHeaders(headers));
},
[httpDelete],
),
...reactQuery,
};
}
export default useApi;

View file

@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { httpGet } from 'next-basics';
import { httpGet } from 'lib/fetch';
import enUS from '../../../public/intl/country/en-US.json';
const countryNames = {

View file

@ -1,5 +1,5 @@
import { getMinimumUnit, parseDateRange } from 'lib/date';
import { setItem } from 'next-basics';
import { setItem } from 'lib/storage';
import { DATE_RANGE_CONFIG, DEFAULT_DATE_COMPARE, DEFAULT_DATE_RANGE } from 'lib/constants';
import websiteStore, { setWebsiteDateRange, setWebsiteDateCompare } from 'store/websites';
import appStore, { setDateRange } from 'store/app';

View file

@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { httpGet } from 'next-basics';
import { httpGet } from 'lib/fetch';
import enUS from '../../../public/intl/language/en-US.json';
const languageNames = {

View file

@ -1,5 +1,6 @@
import { useEffect } from 'react';
import { httpGet, setItem } from 'next-basics';
import { httpGet } from 'lib/fetch';
import { setItem } from 'lib/storage';
import { LOCALE_CONFIG } from 'lib/constants';
import { getDateLocale, getTextDirection } from 'lib/lang';
import useStore, { setLocale } from 'store/app';

View file

@ -1,6 +1,6 @@
import { useMemo } from 'react';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import { buildUrl, safeDecodeURIComponent } from 'next-basics';
import { buildUrl } from 'lib/url';
export function useNavigation(): {
pathname: string;
@ -16,7 +16,7 @@ export function useNavigation(): {
const obj = {};
for (const [key, value] of params.entries()) {
obj[key] = safeDecodeURIComponent(value);
obj[key] = value;
}
return obj;

View file

@ -1,6 +1,6 @@
import { useEffect, useMemo } from 'react';
import useStore, { setTheme } from 'store/app';
import { getItem, setItem } from 'next-basics';
import { getItem, setItem } from 'lib/storage';
import { DEFAULT_THEME, THEME_COLORS, THEME_CONFIG } from 'lib/constants';
import { colord } from 'colord';

View file

@ -1,4 +1,4 @@
import { setItem } from 'next-basics';
import { setItem } from 'lib/storage';
import { TIMEZONE_CONFIG } from 'lib/constants';
import { formatInTimeZone, zonedTimeToUtc, utcToZonedTime } from 'date-fns-tz';
import useStore, { setTimezone } from 'store/app';