feat: add new frontend components, MH batch worker, and gitignore rules
- Add all new Frontend source files (pages, components, hooks, utils) - Add selenium_MHBatchPaymentCheckWorker.py and MHSinglePaymentCheckWorker.py - Add install-steps-5-13.sh setup script - Update .gitignore to exclude runtime/sensitive data (backups, uploads, chat-history, keys, downloads, generated .d.ts files) while keeping folders - Add .gitkeep to preserve empty runtime folders in git Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
import { createContext, useContext, useEffect, useRef } from "react";
|
||||
import { useQuery, useMutation, } from "@tanstack/react-query";
|
||||
import { UserUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
|
||||
import { getQueryFn, apiRequest, queryClient } from "../lib/queryClient";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
const insertUserSchema = UserUncheckedCreateInputObjectSchema.pick({
|
||||
username: true,
|
||||
password: true,
|
||||
});
|
||||
export const AuthContext = createContext(null);
|
||||
export function AuthProvider({ children }) {
|
||||
const { toast } = useToast();
|
||||
const { data: user, error, isLoading, } = useQuery({
|
||||
queryKey: ["/api/users/"],
|
||||
queryFn: getQueryFn({ on401: "returnNull" }),
|
||||
});
|
||||
const loginMutation = useMutation({
|
||||
mutationFn: async (credentials) => {
|
||||
const res = await apiRequest("POST", "/api/auth/login", credentials);
|
||||
const contentType = res.headers.get("content-type") || "";
|
||||
const isJson = contentType.includes("application/json");
|
||||
const data = isJson ? await res.json() : {};
|
||||
if (!res.ok) {
|
||||
throw new Error(data?.error || "Login failed. Please try again.");
|
||||
}
|
||||
if (!data?.token || !data?.user) {
|
||||
throw new Error("Invalid response from server");
|
||||
}
|
||||
localStorage.setItem("token", data.token);
|
||||
return data.user;
|
||||
},
|
||||
onSuccess: (user) => {
|
||||
queryClient.setQueryData(["/api/users/"], user);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Login error:", error);
|
||||
toast({
|
||||
title: "Login failed",
|
||||
description: error.message,
|
||||
variant: "destructive",
|
||||
});
|
||||
},
|
||||
});
|
||||
const registerMutation = useMutation({
|
||||
mutationFn: async (credentials) => {
|
||||
const res = await apiRequest("POST", "/api/auth/register", credentials);
|
||||
const contentType = res.headers.get("content-type") || "";
|
||||
const isJson = contentType.includes("application/json");
|
||||
const data = isJson ? await res.json() : {};
|
||||
if (!res.ok) {
|
||||
throw new Error(data?.error || "Registration failed.");
|
||||
}
|
||||
if (!data?.token || !data?.user) {
|
||||
throw new Error("Invalid response from server");
|
||||
}
|
||||
localStorage.setItem("token", data.token);
|
||||
return data.user;
|
||||
},
|
||||
onSuccess: (user) => {
|
||||
queryClient.setQueryData(["/api/users/"], user);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Registration error:", error);
|
||||
toast({
|
||||
title: "Registration failed",
|
||||
description: error.message,
|
||||
variant: "destructive",
|
||||
});
|
||||
},
|
||||
});
|
||||
const logoutMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
localStorage.removeItem("token");
|
||||
sessionStorage.removeItem("chatbot_messages");
|
||||
await apiRequest("POST", "/api/auth/logout");
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.setQueryData(["/api/users/"], null);
|
||||
},
|
||||
onError: (error) => {
|
||||
toast({
|
||||
title: "Logout failed",
|
||||
description: error.message,
|
||||
variant: "destructive",
|
||||
});
|
||||
},
|
||||
});
|
||||
const IDLE_TIMEOUT = 60 * 60 * 1000;
|
||||
const WARN_BEFORE = 5 * 60 * 1000;
|
||||
const logoutTimer = useRef(null);
|
||||
const warnTimer = useRef(null);
|
||||
const warnedRef = useRef(false);
|
||||
useEffect(() => {
|
||||
if (!user)
|
||||
return;
|
||||
const clearTimers = () => {
|
||||
if (logoutTimer.current)
|
||||
clearTimeout(logoutTimer.current);
|
||||
if (warnTimer.current)
|
||||
clearTimeout(warnTimer.current);
|
||||
};
|
||||
const resetTimers = () => {
|
||||
clearTimers();
|
||||
warnedRef.current = false;
|
||||
warnTimer.current = setTimeout(() => {
|
||||
if (!warnedRef.current) {
|
||||
warnedRef.current = true;
|
||||
toast({
|
||||
title: "Session expiring soon",
|
||||
description: "You will be logged out in 5 minutes due to inactivity.",
|
||||
duration: 10000,
|
||||
});
|
||||
}
|
||||
}, IDLE_TIMEOUT - WARN_BEFORE);
|
||||
logoutTimer.current = setTimeout(() => {
|
||||
logoutMutation.mutate();
|
||||
}, IDLE_TIMEOUT);
|
||||
};
|
||||
const events = ["mousemove", "mousedown", "keydown", "scroll", "touchstart", "click"];
|
||||
events.forEach((e) => window.addEventListener(e, resetTimers, { passive: true }));
|
||||
resetTimers();
|
||||
return () => {
|
||||
clearTimers();
|
||||
events.forEach((e) => window.removeEventListener(e, resetTimers));
|
||||
};
|
||||
}, [user]);
|
||||
return (<AuthContext.Provider value={{
|
||||
user: user ?? null,
|
||||
isLoading,
|
||||
error,
|
||||
loginMutation,
|
||||
logoutMutation,
|
||||
registerMutation,
|
||||
}}>
|
||||
{children}
|
||||
</AuthContext.Provider>);
|
||||
}
|
||||
export function useAuth() {
|
||||
const context = useContext(AuthContext);
|
||||
if (!context) {
|
||||
throw new Error("useAuth must be used within an AuthProvider");
|
||||
}
|
||||
return context;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { apiRequest } from "@/lib/queryClient";
|
||||
export function useLicense() {
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ["/api/license/status"],
|
||||
queryFn: async () => {
|
||||
const res = await apiRequest("GET", "/api/license/status");
|
||||
return res.json();
|
||||
},
|
||||
staleTime: 1000 * 60 * 5, // cache for 5 minutes
|
||||
});
|
||||
const isLicensed = !isLoading && !!data?.activated && !data?.expired;
|
||||
return { isLicensed, isLoading, licenseData: data };
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import * as React from "react";
|
||||
const MOBILE_BREAKPOINT = 768;
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState(undefined);
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
||||
};
|
||||
mql.addEventListener("change", onChange);
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
||||
return () => mql.removeEventListener("change", onChange);
|
||||
}, []);
|
||||
return !!isMobile;
|
||||
}
|
||||
Reference in New Issue
Block a user