Skip to content

Commit 17a6cfa

Browse files
committed
Fix ESLint errors in frontend
- Replace 'any' types with proper interfaces - Fix setState-in-effect with queueMicrotask - Remove unused imports and variables
1 parent 13aa7a1 commit 17a6cfa

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

src/web/src/app/(dashboard)/apis/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default function ApiDetailPage() {
6767
try {
6868
await deleteApi.mutateAsync(id);
6969
router.push('/apis');
70-
} catch (error) {
70+
} catch {
7171
setIsDeleting(false);
7272
}
7373
};

src/web/src/app/(dashboard)/apis/register/page.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ const registerSchema = z.object({
3636

3737
type RegisterFormData = z.infer<typeof registerSchema>;
3838

39+
interface RegisterApiPayload {
40+
name: string;
41+
specUrl: string;
42+
description?: string;
43+
authType: string;
44+
apiKey?: string;
45+
apiKeyHeader?: string;
46+
bearerToken?: string;
47+
basicUsername?: string;
48+
basicPassword?: string;
49+
}
50+
3951
export default function RegisterApiPage() {
4052
const router = useRouter();
4153
const registerApi = useRegisterApi();
@@ -59,7 +71,7 @@ export default function RegisterApiPage() {
5971
const onSubmit = async (data: RegisterFormData) => {
6072
setError(null);
6173
try {
62-
const payload: any = {
74+
const payload: RegisterApiPayload = {
6375
name: data.name,
6476
specUrl: data.specUrl,
6577
description: data.description,
@@ -78,8 +90,9 @@ export default function RegisterApiPage() {
7890

7991
await registerApi.mutateAsync(payload);
8092
router.push('/apis');
81-
} catch (err: any) {
82-
setError(err.response?.data?.error || 'Failed to register API');
93+
} catch (err) {
94+
const axiosError = err as { response?: { data?: { error?: string } } };
95+
setError(axiosError.response?.data?.error || 'Failed to register API');
8396
}
8497
};
8598

@@ -155,7 +168,7 @@ export default function RegisterApiPage() {
155168
<Label>Authentication Type</Label>
156169
<Select
157170
value={authType}
158-
onValueChange={(value) => setValue('authType', value as any)}
171+
onValueChange={(value) => setValue('authType', value as RegisterFormData['authType'])}
159172
>
160173
<SelectTrigger>
161174
<SelectValue placeholder="Select authentication type" />

src/web/src/app/auth/callback/page.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ function CallbackContent() {
3434

3535
useEffect(() => {
3636
// Check for error in query params (errors can still be in query params as they're not sensitive)
37-
const error = searchParams.get('error');
37+
const errorParam = searchParams.get('error');
3838

39-
if (error) {
40-
setStatus('error');
41-
setErrorMessage(decodeURIComponent(error));
39+
if (errorParam) {
40+
// Wrap in microtask to avoid synchronous setState in effect
41+
queueMicrotask(() => {
42+
setStatus('error');
43+
setErrorMessage(decodeURIComponent(errorParam));
44+
});
4245
return;
4346
}
4447

@@ -47,8 +50,10 @@ function CallbackContent() {
4750
const token = getTokenFromFragment();
4851

4952
if (!token) {
50-
setStatus('error');
51-
setErrorMessage('No authentication token received');
53+
queueMicrotask(() => {
54+
setStatus('error');
55+
setErrorMessage('No authentication token received');
56+
});
5257
return;
5358
}
5459

@@ -57,12 +62,13 @@ function CallbackContent() {
5762
window.history.replaceState(null, '', window.location.pathname + window.location.search);
5863
}
5964

60-
// Set the token in auth context
61-
setUserFromToken(token);
62-
setStatus('success');
63-
64-
// Redirect to dashboard immediately
65-
router.push('/dashboard');
65+
// Set the token in auth context and update status
66+
queueMicrotask(() => {
67+
setUserFromToken(token);
68+
setStatus('success');
69+
// Redirect to dashboard
70+
router.push('/dashboard');
71+
});
6672
}, [searchParams, setUserFromToken, router]);
6773

6874
return (

src/web/src/hooks/use-apis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
4-
import { apisApi, ApiRegistration, ApiDetail, ApiEndpoint } from '@/lib/api';
4+
import { apisApi } from '@/lib/api';
55

66
export function useApis() {
77
return useQuery({

src/web/src/lib/api.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,20 @@ api.interceptors.request.use((config: InternalAxiosRequestConfig) => {
4343
return config;
4444
});
4545

46+
// Extended request config to track retry state
47+
interface ExtendedAxiosRequestConfig extends InternalAxiosRequestConfig {
48+
_retry?: boolean;
49+
}
50+
4651
// Response interceptor - handle 401 and refresh token
4752
api.interceptors.response.use(
4853
(response) => response,
4954
async (error: AxiosError) => {
50-
const originalRequest = error.config;
55+
const originalRequest = error.config as ExtendedAxiosRequestConfig | undefined;
5156

5257
if (error.response?.status === 401 && originalRequest) {
5358
// Avoid infinite loops
54-
if ((originalRequest as any)._retry) {
59+
if (originalRequest._retry) {
5560
setAccessToken(null);
5661
// Only redirect if not already on auth pages or landing page
5762
if (typeof window !== 'undefined' &&
@@ -62,7 +67,7 @@ api.interceptors.response.use(
6267
return Promise.reject(error);
6368
}
6469

65-
(originalRequest as any)._retry = true;
70+
originalRequest._retry = true;
6671

6772
// Use singleton promise to prevent multiple refresh calls
6873
if (!refreshPromise) {

0 commit comments

Comments
 (0)