mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
Fix ESLint fast-refresh warnings
Refactor to resolve react-refresh/only-export-components warnings: - Move buttonVariants export to separate file (Button.variants.ts) - Extract WebSocketContext to dedicated context file - Move useWebSocketContext hook to separate file - Update imports across affected files All component files now export only components, improving fast refresh reliability
This commit is contained in:
@@ -100,5 +100,3 @@ function LoadingSpinner() {
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
export { buttonVariants, type ButtonVariants };
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export { Button, type ButtonProps, buttonVariants, type ButtonVariants } from './Button';
|
||||
export { Button, type ButtonProps } from './Button';
|
||||
export { buttonVariants, type ButtonVariants } from './Button.variants';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useWebSocketContext, WSMessage } from '../providers/WebSocketProvider';
|
||||
import { useWebSocketContext } from '../providers/useWebSocketContext';
|
||||
import { WSMessage } from '../providers/WebSocketProvider';
|
||||
|
||||
// Re-export WSMessage type for convenience
|
||||
export type { WSMessage };
|
||||
|
||||
51
src/providers/WebSocketContext.ts
Normal file
51
src/providers/WebSocketContext.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { createContext } from 'react';
|
||||
|
||||
export interface WSMessage {
|
||||
type: string;
|
||||
// Ticket events
|
||||
ticket_id?: number;
|
||||
title?: string;
|
||||
// Common
|
||||
message?: string;
|
||||
user_id?: number;
|
||||
is_admin?: boolean;
|
||||
// Balance events
|
||||
amount_kopeks?: number;
|
||||
amount_rubles?: number;
|
||||
new_balance_kopeks?: number;
|
||||
new_balance_rubles?: number;
|
||||
description?: string;
|
||||
// Subscription events
|
||||
expires_at?: string;
|
||||
new_expires_at?: string;
|
||||
tariff_name?: string;
|
||||
days_left?: number;
|
||||
// Device purchase events
|
||||
devices_added?: number;
|
||||
new_device_limit?: number;
|
||||
// Traffic purchase events
|
||||
traffic_gb_added?: number;
|
||||
new_traffic_limit_gb?: number;
|
||||
// Autopay events
|
||||
required_kopeks?: number;
|
||||
required_rubles?: number;
|
||||
balance_kopeks?: number;
|
||||
balance_rubles?: number;
|
||||
reason?: string;
|
||||
// Account events (ban/warning)
|
||||
// Referral events
|
||||
bonus_kopeks?: number;
|
||||
bonus_rubles?: number;
|
||||
referral_name?: string;
|
||||
// Payment events
|
||||
payment_method?: string;
|
||||
}
|
||||
|
||||
export type MessageHandler = (message: WSMessage) => void;
|
||||
|
||||
export interface WebSocketContextValue {
|
||||
isConnected: boolean;
|
||||
subscribe: (handler: MessageHandler) => () => void;
|
||||
}
|
||||
|
||||
export const WebSocketContext = createContext<WebSocketContextValue | null>(null);
|
||||
@@ -1,58 +1,12 @@
|
||||
import { createContext, useContext, useEffect, useRef, useState, useCallback } from 'react';
|
||||
import { useEffect, useRef, useState, useCallback } from 'react';
|
||||
import { useAuthStore } from '../store/auth';
|
||||
import { WebSocketContext, type MessageHandler, type WSMessage } from './WebSocketContext';
|
||||
|
||||
// Re-export for backward compatibility
|
||||
export type { WSMessage } from './WebSocketContext';
|
||||
|
||||
const isDev = import.meta.env.DEV;
|
||||
|
||||
export interface WSMessage {
|
||||
type: string;
|
||||
// Ticket events
|
||||
ticket_id?: number;
|
||||
title?: string;
|
||||
// Common
|
||||
message?: string;
|
||||
user_id?: number;
|
||||
is_admin?: boolean;
|
||||
// Balance events
|
||||
amount_kopeks?: number;
|
||||
amount_rubles?: number;
|
||||
new_balance_kopeks?: number;
|
||||
new_balance_rubles?: number;
|
||||
description?: string;
|
||||
// Subscription events
|
||||
expires_at?: string;
|
||||
new_expires_at?: string;
|
||||
tariff_name?: string;
|
||||
days_left?: number;
|
||||
// Device purchase events
|
||||
devices_added?: number;
|
||||
new_device_limit?: number;
|
||||
// Traffic purchase events
|
||||
traffic_gb_added?: number;
|
||||
new_traffic_limit_gb?: number;
|
||||
// Autopay events
|
||||
required_kopeks?: number;
|
||||
required_rubles?: number;
|
||||
balance_kopeks?: number;
|
||||
balance_rubles?: number;
|
||||
reason?: string;
|
||||
// Account events (ban/warning)
|
||||
// Referral events
|
||||
bonus_kopeks?: number;
|
||||
bonus_rubles?: number;
|
||||
referral_name?: string;
|
||||
// Payment events
|
||||
payment_method?: string;
|
||||
}
|
||||
|
||||
type MessageHandler = (message: WSMessage) => void;
|
||||
|
||||
interface WebSocketContextValue {
|
||||
isConnected: boolean;
|
||||
subscribe: (handler: MessageHandler) => () => void;
|
||||
}
|
||||
|
||||
const WebSocketContext = createContext<WebSocketContextValue | null>(null);
|
||||
|
||||
export function WebSocketProvider({ children }: { children: React.ReactNode }) {
|
||||
const { accessToken, isAuthenticated } = useAuthStore();
|
||||
const wsRef = useRef<WebSocket | null>(null);
|
||||
@@ -207,11 +161,3 @@ export function WebSocketProvider({ children }: { children: React.ReactNode }) {
|
||||
</WebSocketContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useWebSocketContext() {
|
||||
const context = useContext(WebSocketContext);
|
||||
if (!context) {
|
||||
throw new Error('useWebSocketContext must be used within a WebSocketProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
10
src/providers/useWebSocketContext.ts
Normal file
10
src/providers/useWebSocketContext.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { useContext } from 'react';
|
||||
import { WebSocketContext } from './WebSocketContext';
|
||||
|
||||
export function useWebSocketContext() {
|
||||
const context = useContext(WebSocketContext);
|
||||
if (!context) {
|
||||
throw new Error('useWebSocketContext must be used within a WebSocketProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user