Skip to content

Commit 24101bc

Browse files
committed
refactor(ui): replace import.meta.env with process.env
1 parent 6f5d0f9 commit 24101bc

File tree

5 files changed

+17
-27
lines changed

5 files changed

+17
-27
lines changed

src/types/models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { AttestationData } from '../ui/views/PushDetails/attestation.types';
2+
13
export interface UserData {
24
id: string;
35
name: string;

src/ui/services/user.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { UserData } from '../../types/models';
44

55
type SetStateCallback<T> = (value: T | ((prevValue: T) => T)) => void;
66

7-
const baseUrl = import.meta.env.VITE_API_URI
8-
? `${import.meta.env.VITE_API_URI}`
9-
: `${location.origin}`;
7+
const baseUrl: string = process.env.VITE_API_URI || location.origin;
108

119
const config = {
1210
withCredentials: true,
@@ -29,26 +27,16 @@ const getUser = async (
2927
const response: AxiosResponse<UserData> = await axios(url, config);
3028
const data = response.data;
3129

32-
if (setData) {
33-
setData(data);
34-
}
35-
if (setIsLoading) {
36-
setIsLoading(false);
37-
}
30+
setData?.(data);
31+
setIsLoading?.(false);
3832
} catch (error) {
3933
const axiosError = error as AxiosError;
40-
if (axiosError.response && axiosError.response.status === 401) {
41-
if (setAuth) {
42-
setAuth(false);
43-
}
34+
if (axiosError.response?.status === 401) {
35+
setAuth?.(false);
4436
} else {
45-
if (setIsError) {
46-
setIsError(true);
47-
}
48-
}
49-
if (setIsLoading) {
50-
setIsLoading(false);
37+
setIsError?.(true);
5138
}
39+
setIsLoading?.(false);
5240
}
5341
};
5442

@@ -69,8 +57,7 @@ const getUsers = async (
6957
const response: AxiosResponse<UserData[]> = await axios(url.toString(), {
7058
withCredentials: true,
7159
});
72-
const data = response.data;
73-
setData(data);
60+
setData(response.data);
7461
} catch (error) {
7562
if (axios.isAxiosError(error)) {
7663
if (error.response?.status === 401) {
@@ -79,7 +66,7 @@ const getUsers = async (
7966
'Failed to authorize user. If JWT auth is enabled, please check your configuration or disable it.',
8067
);
8168
} else {
82-
const msg = error.response?.data?.message ?? error.message;
69+
const msg = (error.response?.data as any)?.message ?? error.message;
8370
setErrorMessage(`Error fetching users: ${msg}`);
8471
}
8572
} else {
@@ -126,7 +113,7 @@ const getUserLoggedIn = async (
126113
} catch (error) {
127114
setIsLoading(false);
128115
const axiosError = error as AxiosError;
129-
if (axiosError.response && axiosError.response.status === 401) {
116+
if (axiosError.response?.status === 401) {
130117
setAuth(false);
131118
} else {
132119
setIsError(true);

src/ui/views/PushDetails/attestation.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface Reviewer {
88
gitAccount: string;
99
}
1010

11-
interface AttestationData {
11+
export interface AttestationData {
1212
reviewer: Reviewer;
1313
timestamp: string | Date;
1414
questions: Question[];

src/ui/views/RepoDetails/Components/AddUser.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const AddUserDialog: React.FC<AddUserDialogProps> = ({
7676
};
7777

7878
useEffect(() => {
79-
getUsers(setIsLoading, setData, setAuth, setIsError, {});
79+
getUsers(setIsLoading, setData, setAuth, setIsError, setError, {});
8080
}, []);
8181

8282
if (isError) return <div>Something went wrong ...</div>;

tsconfig.publish.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"experimental/**",
99
"plugins/**",
1010
"./dist/**",
11-
"./src/ui",
12-
"./src/**/*.jsx",
11+
"src/ui/**",
12+
"**/*.tsx",
13+
"**/*.jsx",
1314
"./src/context.js"
1415
]
1516
}

0 commit comments

Comments
 (0)