From 3baff47c80b98dfc41a8339e105db96b97d80baa Mon Sep 17 00:00:00 2001 From: azeeee05 Date: Mon, 3 Aug 2026 14:25:40 +0530 Subject: [PATCH] done recovery incidents --- .../recoveryIncidents/RecoveryIncidentsApi.ts | 24 ++++++ .../components/AddRecoveryIncidents.tsx | 74 ++++++++++++++++++- .../components/RecoveryIncidentsList.tsx | 21 ++++-- 3 files changed, 111 insertions(+), 8 deletions(-) diff --git a/src/app/recoveryIncidents/RecoveryIncidentsApi.ts b/src/app/recoveryIncidents/RecoveryIncidentsApi.ts index e69de29..70de93a 100644 --- a/src/app/recoveryIncidents/RecoveryIncidentsApi.ts +++ b/src/app/recoveryIncidents/RecoveryIncidentsApi.ts @@ -0,0 +1,24 @@ +import { ApiClient } from '../api/ApiClient'; +import type { RecoveryIncident } from './RecoveryIncidentsTypes'; + +export const RecoveryIncidentsApi = { + getAll: async (): Promise => { + return ApiClient.get('/recovery-incidents'); + }, + + getById: async (id: string): Promise => { + return ApiClient.get(`/recovery-incidents/${id}`); + }, + + create: async (data: Omit): Promise => { + return ApiClient.post('/recovery-incidents', data); + }, + + update: async (id: string, data: Partial): Promise => { + return ApiClient.patch(`/recovery-incidents/${id}`, data); + }, + + delete: async (id: string): Promise => { + return ApiClient.delete(`/recovery-incidents/${id}`); + }, +}; diff --git a/src/app/recoveryIncidents/components/AddRecoveryIncidents.tsx b/src/app/recoveryIncidents/components/AddRecoveryIncidents.tsx index 3b8344b..874346d 100644 --- a/src/app/recoveryIncidents/components/AddRecoveryIncidents.tsx +++ b/src/app/recoveryIncidents/components/AddRecoveryIncidents.tsx @@ -1,9 +1,11 @@ +import { useState } from 'react'; import { FileText, User, Airplane, WarningCircle, CaretRight } from '@phosphor-icons/react'; import { CustomModal, CustomInput, CustomDropdown, } from "../../../components/custom"; +import { RecoveryIncidentsApi } from '../RecoveryIncidentsApi'; interface AddRecoveryIncidentsProps { isOpen: boolean; @@ -14,6 +16,52 @@ const SECTION_TITLE_CLASS = "flex items-center gap-2 mb-4 text-[#4A5568] font-bo const SECTION_CONTAINER_CLASS = "bg-[#F9FAFB] rounded-[14px] p-5 border border-gray-100"; export default function AddRecoveryIncidents({ isOpen, onClose }: AddRecoveryIncidentsProps) { + const [formData, setFormData] = useState({ + passengerName: "", + pnr: "", + loyaltyTier: "", + flightNumber: "", + date: "", + origin: "", + destination: "", + category: "", + scenario: "", + jurisdiction: "", + delayDuration: "", + }); + + const [loading, setLoading] = useState(false); + + const handleInputChange = (field: string, value: string) => { + setFormData((prev) => ({ ...prev, [field]: value })); + }; + + const handleSubmit = async () => { + setLoading(true); + try { + const payload = { + recoveryId: "REC-" + Math.floor(Math.random() * 10000), + passengerName: formData.passengerName || "Unknown", + pnr: formData.pnr || "N/A", + flightNumber: formData.flightNumber || "TBD", + flightRoute: `${formData.origin || 'UNK'} → ${formData.destination || 'UNK'}`, + date: formData.date ? new Date(formData.date).toISOString() : new Date().toISOString(), + category: formData.category || "General", + statuses: [{ text: "New", variant: "info" as const }], + value: "$0", + }; + + console.log("Submitting payload:", payload); + await RecoveryIncidentsApi.create(payload); + onClose(); // Will trigger refresh in parent list + } catch (error: any) { + console.error("Error creating incident:", error.response?.data || error.message || error); + alert(`Failed to add incident: ${error.response?.data?.message || 'Unknown error'}`); + } finally { + setLoading(false); + } + }; + return ( } size="lg" primaryAction={{ - label: "Assess & Log Incident", - onClick: onClose, + label: loading ? "Logging..." : "Assess & Log Incident", + onClick: handleSubmit, icon: }} secondaryAction={{ @@ -43,14 +91,20 @@ export default function AddRecoveryIncidents({ isOpen, onClose }: AddRecoveryInc handleInputChange("passengerName", e.target.value)} /> handleInputChange("pnr", e.target.value)} /> handleInputChange("loyaltyTier", val as string)} options={[ { label: "Gold", value: "gold" }, { label: "Silver", value: "silver" }, @@ -70,6 +124,8 @@ export default function AddRecoveryIncidents({ isOpen, onClose }: AddRecoveryInc handleInputChange("flightNumber", val as string)} options={[ { label: "B7687YT", value: "B7687YT" }, { label: "Q23SXD", value: "Q23SXD" }, @@ -80,10 +136,14 @@ export default function AddRecoveryIncidents({ isOpen, onClose }: AddRecoveryInc type="date" label="Date" placeholder="Selected Option" + value={formData.date} + onChange={(e) => handleInputChange("date", e.target.value)} /> handleInputChange("origin", val as string)} options={[ { label: "FRA", value: "FRA" }, { label: "LHR", value: "LHR" }, @@ -93,6 +153,8 @@ export default function AddRecoveryIncidents({ isOpen, onClose }: AddRecoveryInc handleInputChange("destination", val as string)} options={[ { label: "JFK", value: "JFK" }, { label: "CDG", value: "CDG" }, @@ -112,6 +174,8 @@ export default function AddRecoveryIncidents({ isOpen, onClose }: AddRecoveryInc handleInputChange("category", val as string)} options={[ { label: "Flight Ops", value: "flight_ops" }, { label: "Travel Exp", value: "travel_exp" }, @@ -121,6 +185,8 @@ export default function AddRecoveryIncidents({ isOpen, onClose }: AddRecoveryInc handleInputChange("scenario", val as string)} options={[ { label: "Delay", value: "delay" }, { label: "Cancellation", value: "cancellation" }, @@ -130,6 +196,8 @@ export default function AddRecoveryIncidents({ isOpen, onClose }: AddRecoveryInc handleInputChange("jurisdiction", val as string)} options={[ { label: "EU261", value: "eu261" }, { label: "US DOT", value: "us_dot" }, @@ -139,6 +207,8 @@ export default function AddRecoveryIncidents({ isOpen, onClose }: AddRecoveryInc type="number" label="Delay Duration (Mins)" placeholder="0" + value={formData.delayDuration} + onChange={(e) => handleInputChange("delayDuration", e.target.value)} /> diff --git a/src/app/recoveryIncidents/components/RecoveryIncidentsList.tsx b/src/app/recoveryIncidents/components/RecoveryIncidentsList.tsx index 7aebd03..01f2716 100644 --- a/src/app/recoveryIncidents/components/RecoveryIncidentsList.tsx +++ b/src/app/recoveryIncidents/components/RecoveryIncidentsList.tsx @@ -20,6 +20,7 @@ import { import type { Column } from "../../../components/custom/CustomTable"; import type { RecoveryIncident } from "../RecoveryIncidentsTypes"; import AddRecoveryIncidents from "./AddRecoveryIncidents"; +import { RecoveryIncidentsApi } from "../RecoveryIncidentsApi"; // ─── Constants ─────────────────────────────────────────────────────────────── @@ -303,12 +304,13 @@ export default function RecoveryIncidentsList() { // ─── Fetch data ───────────────────────────────────────────── const fetchIncidents = useCallback( - (page: number) => { + async (page: number) => { setLoading(true); - // Simulate API call with timeout - setTimeout(() => { - const filteredData = MOCK_INCIDENTS.filter((p) => { + try { + const data = await RecoveryIncidentsApi.getAll(); + + const filteredData = data.filter((p) => { const matchesSearch = p.recoveryId.toLowerCase().includes(search.toLowerCase()) || p.flightNumber.toLowerCase().includes(search.toLowerCase()); const matchesGroup = isGrouped ? true : !p.isGroupHeader; @@ -323,8 +325,12 @@ export default function RecoveryIncidentsList() { setIncidents(paginatedData); setTotalItems(total); setTotalPages(pages || 1); + } catch (error) { + console.error("Failed to fetch recovery incidents", error); + setIncidents([]); + } finally { setLoading(false); - }, 500); + } }, [search, isGrouped], ); @@ -619,7 +625,10 @@ export default function RecoveryIncidentsList() { {/* Modal */} setIsModalOpen(false)} + onClose={() => { + setIsModalOpen(false); + fetchIncidents(currentPage); // Refresh list + }} /> );