Fix URL auto-completion in re-track and analyze forms
- Add useLocation and useEffect to TrackingPage to pre-fill URL and method from navigation state - Add useLocation and useEffect to AnalysisPage to pre-fill URL from navigation state - Users can now click 'Re-track URL' or 'Analyze URL' from check detail pages and forms are automatically populated - Improves user workflow by eliminating manual URL retyping - Maintains type safety with proper TypeScript interfaces for location state
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Analysis Page - Comprehensive analysis and reporting interface
|
||||
*/
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Heading,
|
||||
@@ -42,6 +42,7 @@ import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import {
|
||||
FiShield,
|
||||
FiSearch,
|
||||
@@ -72,6 +73,7 @@ interface AnalysisResults {
|
||||
export function AnalysisPage() {
|
||||
const [analysisResults, setAnalysisResults] = useState<AnalysisResults | null>(null);
|
||||
const toast = useToast();
|
||||
const location = useLocation();
|
||||
|
||||
const cardBg = useColorModeValue('white', 'gray.800');
|
||||
const borderColor = useColorModeValue('gray.200', 'gray.700');
|
||||
@@ -79,6 +81,7 @@ export function AnalysisPage() {
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useForm<AnalysisFormData>({
|
||||
resolver: zodResolver(analysisSchema),
|
||||
@@ -89,6 +92,14 @@ export function AnalysisPage() {
|
||||
|
||||
// const analysisType = watch('analysisType'); // For future use
|
||||
|
||||
// Pre-fill form if URL is passed via navigation state
|
||||
useEffect(() => {
|
||||
const state = location.state as { url?: string } | null;
|
||||
if (state?.url) {
|
||||
setValue('url', state.url);
|
||||
}
|
||||
}, [location.state, setValue]);
|
||||
|
||||
const analysisMutation = useMutation({
|
||||
mutationFn: async (data: AnalysisFormData) => {
|
||||
switch (data.analysisType) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Advanced form for tracking URLs with analysis options
|
||||
*/
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Heading,
|
||||
@@ -43,7 +43,7 @@ import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useNavigate, useLocation } from 'react-router-dom';
|
||||
|
||||
import { trackingApi, TrackRequestV2 } from '../services/api';
|
||||
import { TrackingResults } from '../components/Tracking/TrackingResults';
|
||||
@@ -68,6 +68,7 @@ export function TrackingPage() {
|
||||
const [trackingResult, setTrackingResult] = useState<any>(null);
|
||||
const toast = useToast();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { isAuthenticated } = useAuth();
|
||||
|
||||
const {
|
||||
@@ -91,6 +92,17 @@ export function TrackingPage() {
|
||||
const maxHops = watch('maxHops');
|
||||
const timeout = watch('timeout');
|
||||
|
||||
// Pre-fill form if URL is passed via navigation state
|
||||
useEffect(() => {
|
||||
const state = location.state as { url?: string; method?: string } | null;
|
||||
if (state?.url) {
|
||||
setValue('url', state.url);
|
||||
if (state.method) {
|
||||
setValue('method', state.method as 'GET' | 'POST' | 'HEAD');
|
||||
}
|
||||
}
|
||||
}, [location.state, setValue]);
|
||||
|
||||
const trackingMutation = useMutation({
|
||||
mutationFn: async (data: TrackRequestV2) => {
|
||||
return await trackingApi.trackUrlV2(data);
|
||||
|
||||
Reference in New Issue
Block a user