import { useEffect } from 'react'; import { motion } from 'framer-motion'; import { CheckCircle2, AlertCircle, Ban } from 'lucide-react'; import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { StatusChip } from './StatusChip'; import { TimelineStep } from './TimelineStep'; import { contactAdminForForm16Mismatch } from '@/services/form16Api'; import { toast } from 'sonner'; export type SubmissionResultStatus = 'success' | 'mismatch' | 'duplicate' | 'error'; interface RequestSubmissionSuccessProps { /** 'success' = matched & credit note; 'mismatch' = value mismatch; 'duplicate' = already submitted; 'error' = request received / processing */ status: SubmissionResultStatus; requestId: string; creditNoteNumber?: string | null; /** Optional message (e.g. from API or error) */ message?: string | null; onComplete: () => void; onResubmit?: () => void; /** When status is 'error' (request received), optional handler to open the request detail */ onViewRequest?: () => void; } export function RequestSubmissionSuccess({ status, requestId, creditNoteNumber, message, onComplete, onResubmit, onViewRequest, }: RequestSubmissionSuccessProps) { const isSuccess = status === 'success'; const isMismatch = status === 'mismatch'; const isMissing26AsMismatch = isMismatch && (message || '').toLowerCase().includes('26as') && (message || '').toLowerCase().includes('no 26as'); const onContactAdmin = async () => { try { await contactAdminForForm16Mismatch(requestId); toast.success('Administrator notified'); } catch (e: any) { const msg = e?.response?.data?.message || e?.message || 'Failed to notify administrator'; toast.error(String(msg)); } }; const isDuplicate = status === 'duplicate'; const isError = status === 'error'; useEffect(() => { if (!isSuccess) return; const timer = setTimeout(onComplete, 5000); return () => clearTimeout(timer); }, [isSuccess, onComplete]); const steps = [ { label: 'Form 16A Uploaded', state: isDuplicate ? ('failed' as const) : ('completed' as const) }, { label: 'Validation', state: isDuplicate ? ('failed' as const) : (isError ? ('pending' as const) : ('completed' as const)) }, { label: '26AS Matching', state: isSuccess ? ('completed' as const) : (isMismatch || isDuplicate) ? ('failed' as const) : ('pending' as const) }, { label: 'Credit Note', state: isSuccess ? ('completed' as const) : ('pending' as const) }, ]; return (
{isSuccess ? ( ) : isDuplicate ? ( ) : isError ? ( ) : ( )}
{isSuccess ? ( <>

Request Submitted Successfully

Details have matched and credit note is generated.

Your Form 16A data matched with 26AS records. Credit note has been generated.

) : isDuplicate ? ( <>

Duplicate Submission

This Form 16A has already been submitted for the same quarter and financial year.

A credit note may already have been issued. Please check your Closed Requests or Credit Notes.

{message && (

Duplicate submission — not allowed

{message}

)} ) : isMismatch ? ( <>

Value Mismatch

Resubmit the form carefully.

Form 16A details did not match with 26AS data. Please verify the certificate and resubmit with correct details.

{message && (

Validation Error:

{message}

)} {isMissing26AsMismatch && (

Contact administrator: FORM 26AS does not match FORM 16A.

If you have submitted the updated Form 16A but the latest 26AS is not uploaded for this quarter yet, please notify RE so they can upload/update 26AS.

)} ) : ( <>

Request Submitted

Your request has been received and is being processed.

If there was an issue, you can try again or contact support.

{message && (

{message}

)} )}

Request ID

{requestId || '—'}

{isSuccess && creditNoteNumber && ( <>

Credit Note Number

{creditNoteNumber}

)}

Process flow

{steps.map((step, index) => ( ))}
{isSuccess ? ( <>

Redirecting to My Requests in a moment...

) : ( <> {isError && onViewRequest && ( )} {onResubmit && (isMismatch || isDuplicate || isError) && ( )} {isMissing26AsMismatch && ( )} )}
); }